Vasilis Daloukas
9 years ago
6 changed files with 1442 additions and 1381 deletions
File diff suppressed because it is too large
@ -1,439 +1,442 @@ |
|||||
<?php // $Id: play.php,v 1.26 2012/07/26 05:39:00 bdaloukas Exp $
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
// This files plays the game "Snakes and Ladders" |
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
function game_snakes_continue( $id, $game, $attempt, $snakes, $context) |
// it under the terms of the GNU General Public License as published by |
||||
{ |
// the Free Software Foundation, either version 3 of the License, or |
||||
if( $attempt != false and $snakes != false){ |
// (at your option) any later version. |
||||
return game_snakes_play( $id, $game, $attempt, $snakes, $context); |
// |
||||
} |
// Moodle is distributed in the hope that it will be useful, |
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
if( $attempt === false){ |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
$attempt = game_addattempt( $game); |
// GNU General Public License for more details. |
||||
} |
// |
||||
|
// You should have received a copy of the GNU General Public License |
||||
$newrec = new stdClass(); |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
$newrec->id = $attempt->id; |
|
||||
$newrec->snakesdatabaseid = $game->param3; |
// This files plays the game "Snakes and Ladders". |
||||
if( $newrec->snakesdatabaseid == 0) |
|
||||
$newrec->snakesdatabaseid = 1; |
function game_snakes_continue( $id, $game, $attempt, $snakes, $context) { |
||||
$newrec->position = 1; |
if ($attempt != false and $snakes != false) { |
||||
$newrec->queryid = 0; |
return game_snakes_play( $id, $game, $attempt, $snakes, $context); |
||||
$newrec->dice = rand( 1, 6); |
} |
||||
if( !game_insert_record( 'game_snakes', $newrec)){ |
|
||||
print_error( 'game_snakes_continue: error inserting in game_snakes'); |
if ($attempt === false) { |
||||
} |
$attempt = game_addattempt( $game); |
||||
|
} |
||||
game_updateattempts( $game, $attempt, 0, 0); |
|
||||
|
$newrec = new stdClass(); |
||||
return game_snakes_play( $id, $game, $attempt, $newrec, $context); |
$newrec->id = $attempt->id; |
||||
} |
$newrec->snakesdatabaseid = $game->param3; |
||||
|
if ($newrec->snakesdatabaseid == 0) { |
||||
function game_snakes_play( $id, $game, $attempt, $snakes, $context) |
$newrec->snakesdatabaseid = 1; |
||||
{ |
} |
||||
global $CFG, $DB, $OUTPUT; |
$newrec->position = 1; |
||||
|
$newrec->queryid = 0; |
||||
$board = game_snakes_get_board( $game); |
$newrec->dice = rand( 1, 6); |
||||
$showboard = false; |
if (!game_insert_record( 'game_snakes', $newrec)) { |
||||
|
print_error( 'game_snakes_continue: error inserting in game_snakes'); |
||||
if( $snakes->position > $board->cols * $board->rows && $snakes->queryid <> 0){ |
} |
||||
$finish = true; |
|
||||
|
game_updateattempts( $game, $attempt, 0, 0); |
||||
if (! $cm = $DB->get_record('course_modules', array( 'id' => $id))) { |
|
||||
print_error("Course Module ID was incorrect id=$id"); |
return game_snakes_play( $id, $game, $attempt, $newrec, $context); |
||||
} |
} |
||||
|
|
||||
echo '<B>'.get_string( 'win', 'game').'</B><BR>'; |
function game_snakes_play( $id, $game, $attempt, $snakes, $context) { |
||||
echo '<br>'; |
global $CFG, $DB, $OUTPUT; |
||||
echo "<a href=\"$CFG->wwwroot/mod/game/attempt.php?id=$id\">".get_string( 'nextgame', 'game').'</a> '; |
|
||||
echo "<a href=\"$CFG->wwwroot/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> '; |
$board = game_snakes_get_board( $game); |
||||
|
$showboard = false; |
||||
$gradeattempt = 1; |
|
||||
$finish = 1; |
if ($snakes->position > $board->cols * $board->rows && $snakes->queryid <> 0) { |
||||
game_updateattempts( $game, $attempt, $gradeattempt, $finish); |
$finish = true; |
||||
}else |
|
||||
{ |
if (! $cm = $DB->get_record('course_modules', array( 'id' => $id))) { |
||||
$finish = false; |
print_error("Course Module ID was incorrect id=$id"); |
||||
if( $snakes->queryid == 0){ |
} |
||||
game_snakes_computenextquestion( $game, $snakes, $query); |
|
||||
}else |
echo '<B>'.get_string( 'win', 'game').'</B><BR>'; |
||||
{ |
echo '<br>'; |
||||
$query = $DB->get_record( 'game_queries', array( 'id' => $snakes->queryid)); |
echo "<a href=\"$CFG->wwwroot/mod/game/attempt.php?id=$id\">". |
||||
} |
get_string( 'nextgame', 'game').'</a> '; |
||||
if( $game->toptext != ''){ |
echo "<a href=\"$CFG->wwwroot/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> '; |
||||
echo $game->toptext.'<br>'; |
|
||||
} |
$gradeattempt = 1; |
||||
$showboard = true; |
$finish = 1; |
||||
} |
game_updateattempts( $game, $attempt, $gradeattempt, $finish); |
||||
|
} else { |
||||
if( $showboard and $game->param8 == 0) |
$finish = false; |
||||
game_snakes_showquestion( $id, $game, $snakes, $query, $context); |
if ($snakes->queryid == 0) { |
||||
|
game_snakes_computenextquestion( $game, $snakes, $query); |
||||
?> |
} else { |
||||
<script language="javascript" event="onload" for="window"> |
$query = $DB->get_record( 'game_queries', array( 'id' => $snakes->queryid)); |
||||
<!-- |
} |
||||
var retVal = new Array(); |
if ($game->toptext != '') { |
||||
var elements = document.getElementsByTagName("*"); |
echo $game->toptext.'<br>'; |
||||
for(var i = 0;i < elements.length;i++){ |
} |
||||
if( elements[ i].type == 'text'){ |
$showboard = true; |
||||
elements[ i].focus(); |
} |
||||
break; |
|
||||
} |
if ($showboard and $game->param8 == 0) { |
||||
} |
game_snakes_showquestion( $id, $game, $snakes, $query, $context); |
||||
--> |
} |
||||
</script> |
?> |
||||
|
<script language="javascript" event="onload" for="window"> |
||||
<table> |
<!-- |
||||
<tr> |
var retVal = new Array(); |
||||
<td> |
var elements = document.getElementsByTagName("*"); |
||||
|
for(var i = 0;i < elements.length;i++){ |
||||
<div id="board" STYLE="position:relative; left:0px;top:0px; width:<?php p($board->width); ?>px; height:<?php p($board->height); ?>px;"> |
if( elements[ i].type == 'text'){ |
||||
<img src="<?php echo $board->imagesrc; ?>"></img> |
elements[ i].focus(); |
||||
</div> |
break; |
||||
|
} |
||||
<?php |
} |
||||
|
--> |
||||
|
</script> |
||||
if( $finish == false){ |
|
||||
game_snakes_showdice( $snakes, $board); |
<table> |
||||
} |
<tr> |
||||
?> |
<td> |
||||
</td> |
|
||||
</tr> |
<div id="board" STYLE="position:relative; left:0px;top:0px; |
||||
</table> |
width:<?php p($board->width); ?>px; height:<?php p($board->height); ?>px;"> |
||||
<?php |
<img src="<?php echo $board->imagesrc; ?>"></img> |
||||
|
</div> |
||||
if( $game->bottomtext != ''){ |
|
||||
echo '<br>'.$game->bottomtext; |
<?php |
||||
} |
if ($finish == false) { |
||||
|
game_snakes_showdice( $snakes, $board); |
||||
if( $showboard and $game->param8 != 0) |
} |
||||
game_snakes_showquestion( $id, $game, $snakes, $query, $context); |
?> |
||||
} |
</td> |
||||
|
</tr> |
||||
function game_snakes_showdice( $snakes, $board) |
</table> |
||||
{ |
<?php |
||||
$pos = game_snakes_computeplayerposition( $snakes, $board); |
|
||||
?> |
if ($game->bottomtext != '') { |
||||
<div ID="player1" STYLE="position:relative; left:<?php p( $pos->x);?>px; top:<?php p( $pos->y);?>px;" > |
echo '<br>'.$game->bottomtext; |
||||
<img src="snakes/1/player1.png" alt="<?php print_string('snakes_player', 'game', ($snakes->position +1)); /*Accessibility. */ ?>" width="<?php echo $pos->width; ?>" height="<?php echo $pos->height; ?>"/> |
} |
||||
</div> |
|
||||
|
if ($showboard and $game->param8 != 0) { |
||||
<div ID="dice" STYLE="position:relative; left:<?php p( $board->width + round($board->width/3));?>px;top:<?php p( -2*round($board->height/3));?>px; "> |
game_snakes_showquestion( $id, $game, $snakes, $query, $context); |
||||
<img src="snakes/1/dice<?php p($snakes->dice);?>.png" alt="<?php print_string('snakes_dice', 'game', $snakes->dice) ?>" /> |
} |
||||
</div> |
} |
||||
<?php |
|
||||
} |
function game_snakes_showdice( $snakes, $board) { |
||||
|
$pos = game_snakes_computeplayerposition( $snakes, $board); |
||||
function game_snakes_computeplayerposition( $snakes, $board) |
?> |
||||
{ |
<div ID="player1" STYLE="position:relative; left:<?php p( $pos->x);?>px; top:<?php p( $pos->y);?>px;" > |
||||
$x = ($snakes->position - 1) % $board->cols; |
<img src="snakes/1/player1.png" |
||||
$y = floor( ($snakes->position-1) / $board->cols); |
alt="<?php print_string('snakes_player', 'game', ($snakes->position + 1)); /*Accessibility. */ ?>" |
||||
|
width="<?php echo $pos->width; ?>" |
||||
$cellwidth = ($board->width - $board->headerx - $board->footerx) / $board->cols; |
height="<?php echo $pos->height; ?>"/> |
||||
$cellheight = ($board->height - $board->headery - $board->footery) / $board->rows; |
</div> |
||||
|
|
||||
$pos = new stdClass(); |
<div ID="dice" STYLE="position:relative; |
||||
$pos->width = 22; |
left:<?php p( $board->width + round($board->width / 3)); ?>px; |
||||
$pos->height = 22; |
top:<?php p( -2 * round($board->height / 3));?>px; "> |
||||
|
<img src="snakes/1/dice<?php p($snakes->dice);?>.png" alt="<?php print_string('snakes_dice', 'game', $snakes->dice) ?>" /> |
||||
$pos->ofsx = 0; |
</div> |
||||
$pos->ofsy = $pos->height; |
<?php |
||||
|
} |
||||
switch( $board->direction){ |
|
||||
case 1: |
function game_snakes_computeplayerposition( $snakes, $board) { |
||||
if( ($y % 2) == 1){ |
$x = ($snakes->position - 1) % $board->cols; |
||||
$x = $board->cols - $x - 1; |
$y = floor( ($snakes->position - 1) / $board->cols); |
||||
} |
|
||||
$pos->x = $board->headerx + $x * $cellwidth + ($cellwidth - $pos->width)/2+ $pos->ofsx; |
$cellwidth = ($board->width - $board->headerx - $board->footerx) / $board->cols; |
||||
$pos->y = $board->footery + $y * $cellheight + ($cellheight - $pos->height)/2 + $pos->ofsy; |
$cellheight = ($board->height - $board->headery - $board->footery) / $board->rows; |
||||
$pos->x = round( $pos->x); |
|
||||
$pos->y = round( -$pos->y); |
$pos = new stdClass(); |
||||
break; |
$pos->width = 22; |
||||
} |
$pos->height = 22; |
||||
|
|
||||
return $pos; |
$pos->ofsx = 0; |
||||
} |
$pos->ofsy = $pos->height; |
||||
|
|
||||
function game_snakes_computenextquestion( $game, &$snakes, &$query) |
switch( $board->direction) { |
||||
{ |
case 1: |
||||
global $DB, $USER; |
if (($y % 2) == 1) { |
||||
|
$x = $board->cols - $x - 1; |
||||
//Retrieves CONST_GAME_TRIES_REPETITION words and select the one which is used fewer times |
} |
||||
if( ($recs = game_questions_selectrandom( $game, 1, CONST_GAME_TRIES_REPETITION)) == false){ |
$pos->x = $board->headerx + $x * $cellwidth + ($cellwidth - $pos->width) / 2 + $pos->ofsx; |
||||
return false; |
$pos->y = $board->footery + $y * $cellheight + ($cellheight - $pos->height) / 2 + $pos->ofsy; |
||||
} |
$pos->x = round( $pos->x); |
||||
|
$pos->y = round( -$pos->y); |
||||
$glossaryid = 0; |
break; |
||||
$questionid = 0; |
} |
||||
$min_num = 0; |
|
||||
$query = new stdClass(); |
return $pos; |
||||
foreach( $recs as $rec){ |
} |
||||
$a = array( 'gameid' => $game->id, 'userid' => $USER->id, 'questionid' => $rec->questionid, 'glossaryentryid' => $rec->glossaryentryid); |
|
||||
if(($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions AS r')) != false){ |
function game_snakes_computenextquestion( $game, &$snakes, &$query) { |
||||
if( ($rec2->r < $min_num) or ($min_num == 0)){ |
global $DB, $USER; |
||||
$min_num = $rec2->r; |
|
||||
$query->glossaryentryid = $rec->glossaryentryid; |
// Retrieves CONST_GAME_TRIES_REPETITION words and select the one which is used fewer times. |
||||
$query->questionid = $rec->questionid; |
if (($recs = game_questions_selectrandom( $game, 1, CONST_GAME_TRIES_REPETITION)) == false) { |
||||
} |
return false; |
||||
} |
} |
||||
else{ |
|
||||
$query->glossaryentryid = $rec->glossaryentryid; |
$glossaryid = 0; |
||||
$query->questionid = $rec->questionid; |
$questionid = 0; |
||||
break; |
$minnum = 0; |
||||
} |
$query = new stdClass(); |
||||
} |
foreach ($recs as $rec) { |
||||
|
$a = array( 'gameid' => $game->id, 'userid' => $USER->id, |
||||
if( ($query->glossaryentryid == 0) AND ($query->questionid == 0)) |
'questionid' => $rec->questionid, 'glossaryentryid' => $rec->glossaryentryid); |
||||
return false; |
if (($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions AS r')) != false) { |
||||
|
if (($rec2->r < $minnum) or ($minnum == 0)) { |
||||
$query->attemptid = $snakes->id; |
$minnum = $rec2->r; |
||||
$query->gameid = $game->id; |
$query->glossaryentryid = $rec->glossaryentryid; |
||||
$query->userid = $USER->id; |
$query->questionid = $rec->questionid; |
||||
$query->sourcemodule = $game->sourcemodule; |
} |
||||
$query->score = 0; |
} else { |
||||
$query->timelastattempt = time(); |
$query->glossaryentryid = $rec->glossaryentryid; |
||||
if( !($query->id = $DB->insert_record( 'game_queries', $query))){ |
$query->questionid = $rec->questionid; |
||||
print_error( "Can't insert to table game_queries"); |
break; |
||||
} |
} |
||||
|
} |
||||
$snakes->queryid = $query->id; |
|
||||
|
if (($query->glossaryentryid == 0) and ($query->questionid == 0)) { |
||||
$updrec = new stdClass(); |
return false; |
||||
$updrec->id = $snakes->id; |
} |
||||
$updrec->queryid = $query->id; |
$query->attemptid = $snakes->id; |
||||
$updrec->dice = $snakes->dice = rand( 1, 6); |
$query->gameid = $game->id; |
||||
|
$query->userid = $USER->id; |
||||
if( !$DB->update_record( 'game_snakes', $updrec)){ |
$query->sourcemodule = $game->sourcemodule; |
||||
print_error( 'game_questions_selectrandom: error updating in game_snakes'); |
$query->score = 0; |
||||
} |
$query->timelastattempt = time(); |
||||
|
if (!($query->id = $DB->insert_record( 'game_queries', $query))) { |
||||
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
print_error( "Can't insert to table game_queries"); |
||||
|
} |
||||
return true; |
|
||||
} |
$snakes->queryid = $query->id; |
||||
|
|
||||
function game_snakes_showquestion( $id, $game, $snakes, $query, $context) |
$updrec = new stdClass(); |
||||
{ |
$updrec->id = $snakes->id; |
||||
if( $query->sourcemodule == 'glossary'){ |
$updrec->queryid = $query->id; |
||||
game_snakes_showquestion_glossary( $id, $snakes, $query, $game); |
$updrec->dice = $snakes->dice = rand( 1, 6); |
||||
}else |
|
||||
{ |
if (!$DB->update_record( 'game_snakes', $updrec)) { |
||||
game_snakes_showquestion_question( $game, $id, $snakes, $query, $context); |
print_error( 'game_questions_selectrandom: error updating in game_snakes'); |
||||
} |
} |
||||
} |
|
||||
|
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
||||
function game_snakes_showquestion_question( $game, $id, $snakes, $query, $context) |
|
||||
{ |
return true; |
||||
global $CFG; |
} |
||||
|
|
||||
$questionlist = $query->questionid; |
function game_snakes_showquestion( $id, $game, $snakes, $query, $context) { |
||||
$questions = game_sudoku_getquestions( $questionlist); |
if ($query->sourcemodule == 'glossary') { |
||||
|
game_snakes_showquestion_glossary( $id, $snakes, $query, $game); |
||||
/// Start the form |
} else { |
||||
echo "<form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; |
game_snakes_showquestion_question( $game, $id, $snakes, $query, $context); |
||||
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; |
} |
||||
|
} |
||||
// Add a hidden field with the quiz id |
|
||||
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; |
function game_snakes_showquestion_question( $game, $id, $snakes, $query, $context) { |
||||
echo '<input type="hidden" name="action" value="snakescheck" />'; |
global $CFG; |
||||
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; |
|
||||
|
$questionlist = $query->questionid; |
||||
/// Print all the questions |
$questions = game_sudoku_getquestions( $questionlist); |
||||
foreach( $questions as $question) |
|
||||
game_print_question( $game, $question, $context); |
// Start the form. |
||||
// Add a hidden field with questionids |
echo "<form id=\"responseform\" method=\"post\" ". |
||||
echo '<input type="hidden" name="questionids" value="'.$questionlist."\" />\n"; |
"action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; |
||||
|
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; |
||||
echo "</form>\n"; |
|
||||
} |
// Add a hidden field with the quiz id. |
||||
|
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; |
||||
function game_snakes_showquestion_glossary( $id, $snakes, $query, $game) |
echo '<input type="hidden" name="action" value="snakescheck" />'; |
||||
{ |
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; |
||||
global $CFG, $DB; |
|
||||
|
// Print all the questions. |
||||
$entry = $DB->get_record( 'glossary_entries', array('id' => $query->glossaryentryid)); |
foreach ($questions as $question) { |
||||
|
game_print_question( $game, $question, $context); |
||||
/// Start the form |
} |
||||
echo "<form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; |
// Add a hidden field with questionids. |
||||
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; |
echo '<input type="hidden" name="questionids" value="'.$questionlist."\" />\n"; |
||||
|
|
||||
// Add a hidden field with the queryid |
echo "</form>\n"; |
||||
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; |
} |
||||
echo '<input type="hidden" name="action" value="snakescheckg" />'; |
|
||||
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; |
function game_snakes_showquestion_glossary( $id, $snakes, $query, $game) { |
||||
|
global $CFG, $DB; |
||||
/// Print all the questions |
|
||||
|
$entry = $DB->get_record( 'glossary_entries', array('id' => $query->glossaryentryid)); |
||||
// Add a hidden field with glossaryentryid |
|
||||
echo '<input type="hidden" name="glossaryentryid" value="'.$query->glossaryentryid."\" />\n"; |
// Start the form. |
||||
|
echo "<form id=\"responseform\" method=\"post\" ". |
||||
$cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); |
"action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; |
||||
$contextglossary = game_get_context_module_instance( $cmglossary->id); |
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('sudoku_submit', 'game')."\"></center>\n"; |
||||
$s = game_filterglossary(str_replace( '\"', '"', $entry->definition), $query->glossaryentryid, $contextglossary->id, $game->course); |
|
||||
echo $s.'<br>'; |
// Add a hidden field with the queryid. |
||||
|
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; |
||||
echo get_string( 'answer').': '; |
echo '<input type="hidden" name="action" value="snakescheckg" />'; |
||||
echo "<input type=\"text\" name=\"answer\" size=30 /><br>"; |
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; |
||||
|
|
||||
echo "</form>\n"; |
// Print all the questions. |
||||
} |
|
||||
|
// Add a hidden field with glossaryentryid. |
||||
|
echo '<input type="hidden" name="glossaryentryid" value="'.$query->glossaryentryid."\" />\n"; |
||||
function game_snakes_check_questions( $id, $game, $attempt, $snakes, $context) |
|
||||
{ |
$cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); |
||||
global $QTYPES, $CFG, $DB; |
$contextglossary = game_get_context_module_instance( $cmglossary->id); |
||||
|
$s = game_filterglossary(str_replace( '\"', '"', $entry->definition), $query->glossaryentryid, |
||||
$responses = data_submitted(); |
$contextglossary->id, $game->course); |
||||
|
echo $s.'<br>'; |
||||
if( $responses->queryid != $snakes->queryid){ |
|
||||
game_snakes_play( $id, $game, $attempt, $snakes, $context); |
echo get_string( 'answer').': '; |
||||
return; |
echo "<input type=\"text\" name=\"answer\" size=30 /><br>"; |
||||
} |
|
||||
|
echo "</form>\n"; |
||||
$questionlist = $DB->get_field( 'game_queries', 'questionid', array( 'id' => $responses->queryid)); |
} |
||||
|
|
||||
$questions = game_sudoku_getquestions( $questionlist); |
function game_snakes_check_questions( $id, $game, $attempt, $snakes, $context) { |
||||
$correct = false; |
global $QTYPES, $CFG, $DB; |
||||
$query = ''; |
|
||||
foreach($questions as $question) { |
$responses = data_submitted(); |
||||
$query = new stdClass(); |
|
||||
$query->id = $snakes->queryid; |
if ($responses->queryid != $snakes->queryid) { |
||||
|
game_snakes_play( $id, $game, $attempt, $snakes, $context); |
||||
$grade = game_grade_responses( $question, $responses, 100, $answertext); |
return; |
||||
if( $grade < 99){ |
} |
||||
//wrong answer |
|
||||
game_update_queries( $game, $attempt, $query, 0, $answertext); |
$questionlist = $DB->get_field( 'game_queries', 'questionid', array( 'id' => $responses->queryid)); |
||||
continue; |
|
||||
} |
$questions = game_sudoku_getquestions( $questionlist); |
||||
|
$correct = false; |
||||
//correct answer |
$query = ''; |
||||
$correct = true; |
foreach ($questions as $question) { |
||||
|
$query = new stdClass(); |
||||
game_update_queries( $game, $attempt, $query, 1, ''); |
$query->id = $snakes->queryid; |
||||
} |
|
||||
|
$grade = game_grade_responses( $question, $responses, 100, $answertext); |
||||
//set the grade of the whole game |
if ($grade < 99) { |
||||
game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context); |
// Wrong answer. |
||||
} |
game_update_queries( $game, $attempt, $query, 0, $answertext); |
||||
|
continue; |
||||
|
} |
||||
function game_snakes_check_glossary( $id, $game, $attempt, $snakes, $context) |
|
||||
{ |
// Correct answer. |
||||
global $QTYPES, $CFG, $DB; |
$correct = true; |
||||
|
|
||||
$responses = data_submitted(); |
game_update_queries( $game, $attempt, $query, 1, ''); |
||||
|
} |
||||
if( $responses->queryid != $snakes->queryid){ |
|
||||
game_snakes_play( $id, $game, $attempt, $snakes, $context); |
// Set the grade of the whole game. |
||||
return; |
game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context); |
||||
} |
} |
||||
|
|
||||
$query = $DB->get_record( 'game_queries', array( 'id' => $responses->queryid)); |
function game_snakes_check_glossary( $id, $game, $attempt, $snakes, $context) { |
||||
|
global $QTYPES, $CFG, $DB; |
||||
$glossaryentry = $DB->get_record( 'glossary_entries', array( 'id' => $query->glossaryentryid)); |
|
||||
|
$responses = data_submitted(); |
||||
$name = 'resp'.$query->glossaryentryid; |
|
||||
$useranswer = $responses->answer; |
if ($responses->queryid != $snakes->queryid) { |
||||
|
game_snakes_play( $id, $game, $attempt, $snakes, $context); |
||||
if( game_upper( $useranswer) != game_upper( $glossaryentry->concept)){ |
return; |
||||
//wrong answer |
} |
||||
$correct = false; |
|
||||
game_update_queries( $game, $attempt, $query, 0, $useranswer);//last param is grade |
$query = $DB->get_record( 'game_queries', array( 'id' => $responses->queryid)); |
||||
}else |
|
||||
{ |
$glossaryentry = $DB->get_record( 'glossary_entries', array( 'id' => $query->glossaryentryid)); |
||||
//correct answer |
|
||||
$correct = true; |
$name = 'resp'.$query->glossaryentryid; |
||||
|
$useranswer = $responses->answer; |
||||
game_update_queries( $game, $attempt, $query, 1, $useranswer);//last param is grade |
|
||||
} |
if (game_upper( $useranswer) != game_upper( $glossaryentry->concept)) { |
||||
|
// Wrong answer. |
||||
//set the grade of the whole game |
$correct = false; |
||||
game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context); |
game_update_queries( $game, $attempt, $query, 0, $useranswer); // Last param is grade. |
||||
} |
} else { |
||||
|
// Correct answer. |
||||
|
$correct = true; |
||||
function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context) |
|
||||
{ |
game_update_queries( $game, $attempt, $query, 1, $useranswer); // Last param is grade. |
||||
global $DB; |
} |
||||
|
|
||||
$data = $DB->get_field( 'game_snakes_database', 'data', array( 'id' => $snakes->snakesdatabaseid)); |
// Set the grade of the whole game. |
||||
|
game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context); |
||||
if( $correct){ |
} |
||||
if( ($next=game_snakes_foundlander( $snakes->position + $snakes->dice, $data))){ |
|
||||
$snakes->position = $next; |
function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context) { |
||||
}else |
global $DB; |
||||
{ |
|
||||
$snakes->position = $snakes->position + $snakes->dice; |
$data = $DB->get_field( 'game_snakes_database', 'data', array( 'id' => $snakes->snakesdatabaseid)); |
||||
} |
|
||||
}else |
if ($correct) { |
||||
{ |
if (($next = game_snakes_foundlander( $snakes->position + $snakes->dice, $data))) { |
||||
if( ($next=game_snakes_foundsnake( $snakes->position, $data))){ |
$snakes->position = $next; |
||||
$snakes->position = $next; |
} else { |
||||
} |
$snakes->position = $snakes->position + $snakes->dice; |
||||
} |
} |
||||
|
} else { |
||||
$updrec = new stdClass(); |
if (($next = game_snakes_foundsnake( $snakes->position, $data))) { |
||||
$updrec->id = $snakes->id; |
$snakes->position = $next; |
||||
$updrec->position = $snakes->position; |
} |
||||
$updrec->queryid = 0; |
} |
||||
|
|
||||
if( !$DB->update_record( 'game_snakes', $updrec)){ |
$updrec = new stdClass(); |
||||
print_error( "game_snakes_position: Can't update game_snakes"); |
$updrec->id = $snakes->id; |
||||
} |
$updrec->position = $snakes->position; |
||||
|
$updrec->queryid = 0; |
||||
$board = $DB->get_record_select( 'game_snakes_database', "id=$snakes->snakesdatabaseid"); |
|
||||
$gradeattempt = $snakes->position / ($board->cols * $board->rows); |
if (!$DB->update_record( 'game_snakes', $updrec)) { |
||||
$finished = ( $snakes->position > $board->cols * $board->rows ? 1 : 0); |
print_error( "game_snakes_position: Can't update game_snakes"); |
||||
|
} |
||||
game_updateattempts( $game, $attempt, $gradeattempt, $finished); |
|
||||
|
$board = $DB->get_record_select( 'game_snakes_database', "id=$snakes->snakesdatabaseid"); |
||||
game_snakes_computenextquestion( $game, $snakes, $query); |
$gradeattempt = $snakes->position / ($board->cols * $board->rows); |
||||
|
$finished = ( $snakes->position > $board->cols * $board->rows ? 1 : 0); |
||||
game_snakes_play( $id, $game, $attempt, $snakes, $context); |
|
||||
} |
game_updateattempts( $game, $attempt, $gradeattempt, $finished); |
||||
|
|
||||
//in lander go forward |
game_snakes_computenextquestion( $game, $snakes, $query); |
||||
function game_snakes_foundlander( $position, $data) |
|
||||
{ |
game_snakes_play( $id, $game, $attempt, $snakes, $context); |
||||
preg_match( "/L$position-([0-9]*)/", $data, $matches); |
} |
||||
|
|
||||
if( count( $matches)){ |
// In lander go forward. |
||||
return $matches[ 1]; |
function game_snakes_foundlander( $position, $data) { |
||||
} |
preg_match( "/L$position-([0-9]*)/", $data, $matches); |
||||
|
|
||||
return 0; |
if (count( $matches)) { |
||||
} |
return $matches[ 1]; |
||||
|
} |
||||
//in snake go backward |
|
||||
function game_snakes_foundsnake( $position, $data) |
return 0; |
||||
{ |
} |
||||
preg_match( "/S([0-9]*)-$position,/", $data.',', $matches); |
|
||||
|
// In snake go backward. |
||||
if( count( $matches)){ |
function game_snakes_foundsnake( $position, $data) { |
||||
return $matches[ 1]; |
preg_match( "/S([0-9]*)-$position,/", $data.',', $matches); |
||||
} |
|
||||
|
if (count( $matches)) { |
||||
return 0; |
return $matches[ 1]; |
||||
} |
} |
||||
|
|
||||
function game_snakes_remove_attemptdata ($questionusageid, $questionid) { |
return 0; |
||||
global $DB; |
} |
||||
|
|
||||
$sql = "SELECT qas.id |
function game_snakes_remove_attemptdata ($questionusageid, $questionid) { |
||||
FROM mdl_question_attempts qa |
global $DB; |
||||
LEFT JOIN mdl_question_attempt_steps qas |
|
||||
ON qa.id=qas.questionattemptid |
$sql = "SELECT qas.id |
||||
WHERE questionusageid = $questionusageid |
FROM mdl_question_attempts qa |
||||
AND questionid = $questionid |
LEFT JOIN mdl_question_attempt_steps qas |
||||
AND state != 'todo'"; |
ON qa.id=qas.questionattemptid |
||||
|
WHERE questionusageid = $questionusageid |
||||
if ($stepdata = $DB->get_records_sql($sql)) { |
AND questionid = $questionid |
||||
foreach($stepdata as $step) { |
AND state != 'todo'"; |
||||
if ($step->id > 0) { |
|
||||
$DB->delete_records('question_attempt_step_data', array('attemptstepid' => $step->id)); |
if ($stepdata = $DB->get_records_sql($sql)) { |
||||
$DB->get_records_sql("update {question_attempt_steps} set state='todo' where id = {$step->id}"); |
foreach ($stepdata as $step) { |
||||
} |
if ($step->id > 0) { |
||||
} |
$DB->delete_records('question_attempt_step_data', array('attemptstepid' => $step->id)); |
||||
} |
$DB->get_records_sql("update {question_attempt_steps} set state='todo' where id = {$step->id}"); |
||||
} |
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
Loading…
Reference in new issue