Browse Source

New: Multianswer question on Snakes and Ladders Game

MOODLE_20_STABLE
Vasilis Daloukas 10 years ago
parent
commit
f8f3f7a19b
  1. 84
      locallib.php
  2. 2
      snakes/play.php
  3. 4
      version.php

84
locallib.php

@ -1539,6 +1539,8 @@ function game_grade_responses( $question, $responses, $maxgrade, &$answertext)
{
if( $question->qtype == 'multichoice')
{
if( $question->category == 8)
return game_grade_responses_multianswer( $question, $responses, $maxgrade, $answertext);
$name = "resp{$question->id}_";
$value = $responses->$name;
$answer = $question->options->answers[ $value];
@ -1560,11 +1562,36 @@ function game_grade_responses( $question, $responses, $maxgrade, &$answertext)
}
}
function game_grade_responses_multianswer( $question, $responses, $maxgrade, &$answertext)
{
$name = "resp{$question->id}_";
$len = strlen( $name);
$fraction = 0;
foreach( $responses as $key => $value)
{
$sub = substr( $key, 0, strlen( $name));
if( $sub != $name)
continue;
$name2 = $name.$value;
$value2 = $responses->$name2;
$answer = $question->options->answers[ $value2];
$fraction += $answer->fraction;
}
return $fraction * $maxgrade;
}
function game_print_question( $game, $question, $context)
{
if( $question->qtype == 'multichoice')
game_print_question_multichoice( $game, $question, $context);
else if( $question->qtype == 'shortanswer')
{
if( $question->category == 8)
game_print_question_multianswer( $game, $question, $context);
else
game_print_question_multichoice( $game, $question, $context);
}else if( $question->qtype == 'shortanswer')
game_print_question_shortanswer( $game, $question, $context);
}
@ -1620,6 +1647,59 @@ function game_print_question_multichoice( $game, $question, $context)
<?php
}
function game_print_question_multianswer( $game, $question, $context)
{
global $CFG;
$i=0;
$questiontext = $question->questiontext;
$answerprompt = get_string( 'singleanswer', 'quiz');
$feedback = '';
$anss = array();
foreach( $question->options->answers as $a)
{
$answer = new stdClass();
if( substr( $a->answer, 0, 3) == '<p>' or substr( $a->answer, 0, 3) == '<P>')
{
$a->answer = substr( $a->answer, 3);
$s = rtrim( $a->answer);
if( substr( $s, 0, -3) == '<p>' or substr( $s, 0, -3) == '<P>')
$a->answer = substr( $a->answer, 0, -3);
}
$a->answer = game_filterquestion_answer(str_replace( '\"', '"', $a->answer), $a->id, $context->id, $game->course);
$answer->control = "<input id=\"resp{$question->id}_{$a->id}\" name=\"resp{$question->id}_{$a->id}\" type=\"checkbox\" value=\"{$a->id}\" /> ".$a->answer;
$answer->class = 'radio';
$answer->id = $a->id;
$answer->text = $a->answer;
$answer->feedbackimg = '';
$answer->feedback = '';
$anss[] = $answer;
}
?>
<div class="qtext">
<?php echo game_filterquestion(str_replace( '\"', '"', $questiontext), $question->id, $context->id, $game->course); ?>
</div>
<div class="ablock clearfix">
<div class="prompt">
<?php echo $answerprompt; ?>
</div>
<table class="answer">
<?php $row = 1; foreach ($anss as $answer) { ?>
<tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">
<td>
<?php echo $answer->control; ?>
</td>
</tr>
<?php } ?>
</table>
</div>
<?php
}
function game_print_question_shortanswer( $game, $question, $context)
{
$questiontext = $question->questiontext;

2
snakes/play.php

@ -301,7 +301,7 @@ function game_snakes_check_questions( $id, $game, $attempt, $snakes, $context)
$query->id = $snakes->queryid;
$grade = game_grade_responses( $question, $responses, 100, $answertext);
if( $grade < 50){
if( $grade < 99){
//wrong answer
game_update_queries( $game, $attempt, $query, 0, $answertext);
continue;

4
version.php

@ -22,10 +22,10 @@ if( !isset( $plugin))
$useplugin = 2;
$plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics)
$plugin->version = 2015071206; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 20150714; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2010112400; // Requires Moodle 2.0
$plugin->cron = 0; // Period for cron to check this module (secs)
$plugin->release = '3.30.12.6';
$plugin->release = '3.30.14';
if( $useplugin != 2)
$module = $plugin;

Loading…
Cancel
Save