id = $attempt->id; $newrec->snakesdatabaseid = $game->param3; $newrec->position = 1; $newrec->queryid = 0; if( !game_insert_record( 'game_snakes', $newrec)){ error( 'game_snakes_continue: error inserting in game_snakes'); } game_updateattempts( $game, $attempt, 0, 0); return game_snakes_play( $id, $game, $attempt, $newrec); } function game_snakes_play( $id, $game, $attempt, $snakes) { global $CFG; $board = game_snakes_getboard( $game, $snakes); if( $snakes->position > $board->cols * $board->rows && $snakes->queryid <> 0){ $finish = true; if (! $cm = get_record("course_modules", "id", $id)) { error("Course Module ID was incorrect id=$id"); } echo ''.get_string( 'win', 'game').'
'; echo '
'; echo "wwwroot/mod/game/attempt.php?id=$id\">".get_string( 'nextgame', 'game').'         '; echo "wwwroot/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').' '; $gradeattempt = 1; $finish = 1; game_updateattempts( $game, $attempt, $gradeattempt, $finish); }else { $finish = false; if( $snakes->queryid == 0){ game_snakes_computenextquestion( $game, $snakes, $query); }else { $query = get_record( 'game_queries', 'id', $snakes->queryid); } if( $game->toptext != ''){ echo $game->toptext.'
'; } game_snakes_showquestion( $id, $game, $snakes, $query); } ?>

<?php print_string('snakes_board', 'game', $board->name); /*Accessibility ('name' may be a bit long.) */ ?>
bottomtext != ''){ echo '
'.$game->bottomtext; } } function game_snakes_getboard( $game, $snakes) { global $CFG; if( $game->param3 != 0 or $snakes->snakesdatabaseid == 0) { $board = get_record_select( 'game_snakes_database', 'id='.$snakes->snakesdatabaseid); if( $board == false) { require_once(dirname(__FILE__) . '/../db/importsnakes.php'); $board = get_record_select( 'game_snakes_database', 'id='.$snakes->snakesdatabaseid); } if( $board == false) print_error( 'No board '.$snakes->snakesdatabaseid); $board->imagesrc = $CFG->wwwroot.'/mod/game/snakes/boards/'.$board->fileboard; }else { $board = game_snakes_create_user_defined_board( $game); } return $board; } function game_snakes_showdice( $snakes, $board) { $pos = game_snakes_computeplayerposition( $snakes, $board); ?>

<?php print_string('snakes_player', 'game', ($snakes->position +1)); /*Accessibility. */ ?>

<?php print_string('snakes_dice', 'game', $snakes->dice) ?>
position - 1) % $board->cols; $y = floor( ($snakes->position-1) / $board->cols); $cellwidth = ($board->width - $board->headerx - $board->footerx) / $board->cols; $cellheight = ($board->height - $board->headery - $board->footery) / $board->rows; unset( $pos); switch( $board->direction){ case 1: if( ($y % 2) == 1){ $x = $board->cols - $x - 1; } $pos->x = round( $board->headerx + $x * $cellwidth + ($cellwidth-$pawn_width)/2); $pos->y = round( $board->footery + ($board->rows - $y-1) * $cellheight)- $board->height-10 + ($cellheight-$pawn_height)/2; break; } return $pos; } function game_snakes_computenextquestion( $game, &$snakes, &$query) { global $USER; //Retrieves CONST_GAME_TRIES_REPETITION words and select the one which is used fewer times if( ($recs = game_questions_selectrandom( $game, CONST_GAME_TRIES_REPETITION)) == false){ return false; } $glossaryid = 0; $questionid = 0; $min_num = 0; foreach( $recs as $rec){ $select = "gameid=$game->id AND userid='$USER->id' AND questionid='$rec->questionid' AND glossaryentryid='$rec->glossaryentryid'"; if(($rec2 = get_record_select('game_repetitions', $select, 'id,repetitions r')) != false){ if( ($rec2->r < $min_num) or ($min_num == 0)){ $min_num = $rec2->r; $query->glossaryentryid = $rec->glossaryentryid; $query->questionid = $rec->questionid; } } else{ $query->glossaryentryid = $rec->glossaryentryid; $query->questionid = $rec->questionid; break; } } if( ($query->glossaryentryid == 0) AND ($query->questionid == 0)) return false; $query->attemptid = $snakes->id; $query->gameid = $game->id; $query->userid = $USER->id; $query->sourcemodule = $game->sourcemodule; $query->score = 0; $query->timelastattempt = time(); if( !($query->id = insert_record( 'game_queries', $query))){ error( "Can't insert to table game_queries"); } $snakes->queryid = $query->id; $updrec->id = $snakes->id; $updrec->queryid = $query->id; $updrec->dice = rand( 1, 6); if( !update_record( 'game_snakes', $updrec)){echo "
"; error( 'game_questions_selectrandom: error updating in game_snakes'); } $snakes->dice = $updrec->dice; game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); return true; } function game_snakes_showquestion( $id, $game, $snakes, $query) { if( $query->sourcemodule == 'glossary'){ game_snakes_showquestion_glossary( $id, $snakes, $query); }else { game_snakes_showquestion_question( $game, $id, $snakes, $query); } } function game_snakes_showquestion_question( $game, $id, $snakes, $query) { global $CFG; $questionlist = $query->questionid; $questions = game_sudoku_getquestions( $questionlist); /// Start the form echo '
'; echo "
wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; echo "
\n"; // Add a hidden field with the quiz id echo '\n"; echo ''; echo '\n"; /// Print all the questions // Add a hidden field with questionids echo '\n"; foreach ($questions as $question) { global $QTYPES; unset( $cmoptions); $cmoptions->course = $game->course; $cmoptions->shuffleanswers = $question->options->shuffleanswers = false; $cmoptions->optionflags->optionflags = 0; $cmoptions->id = 0; $attempt = 0; if (!$QTYPES[$question->qtype]->create_session_and_responses( $question, $state, $cmoptions, $attempt)) { error( 'game_sudoku_showquestions_quiz: problem'); } $state->last_graded = new StdClass; $state->last_graded->event = QUESTION_EVENTOPEN; $state->event = QUESTION_EVENTOPEN; $options->scores->score = 0; $question->maxgrade = 100; $state->manualcomment = ''; $cmoptions->optionflags = 0; $options->correct_responses = 0; $options->feedback = 0; $options->readonly = 0; print_question($question, $state, '', $cmoptions, $options); break; } echo "
\n"; } function game_snakes_showquestion_glossary( $id, $snakes, $query) { global $CFG; $entry = get_record( 'glossary_entries', 'id', $query->glossaryentryid); /// Start the form echo '
'; echo "
wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; echo "
\n"; // Add a hidden field with the queryid echo '\n"; echo ''; echo '\n"; /// Print all the questions // Add a hidden field with glossaryentryid echo '\n"; echo game_filtertext( $entry->definition, 0).'
'; //Accessibility