function game_sudoku_continue($id, $game, $attempt, $sudoku, $endofgame, $context) { global $CFG, $DB, $USER; if ($endofgame) { game_updateattempts($game, $attempt, -1, true); $endofgame = false; } if ($attempt != false and $sudoku != false) { return game_sudoku_play($id, $game, $attempt, $sudoku, false, false, $context); } if ($attempt == false) { $attempt = game_addattempt($game); } //new game srand((double) microtime() * 1000000); $recsudoku = getrandomsudoku(); if ($recsudoku == false) { print_error('Empty sudoku database'); } $newrec = new stdClass(); $newrec->id = $attempt->id; $newrec->guess = ''; $newrec->data = $recsudoku->data; $newrec->opened = $recsudoku->opened; $need = 81 - $recsudoku->opened; $closed = game_sudoku_getclosed($newrec->data); $n = min(count($closed), $need); //if the teacher set the maximum number of questions if ($game->param2 > 0) { if ($game->param2 < $n) { $n = $game->param2; } } $recs = game_questions_selectrandom($game, CONST_GAME_TRIES_REPETITION * $n); if ($recs === false) { mysql_execute("DELETE FROM {game_sudoku} WHERE id={$game->id}"); print_error(get_string('no_questions', 'game')); } $closed = array_rand($closed, $n); $selected_recs = game_select_from_repetitions($game, $recs, $n); if (!game_insert_record('game_sudoku', $newrec)) { print_error('error inserting in game_sudoku'); } $i = 0; $field = $game->sourcemodule == 'glossary' ? 'glossaryentryid' : 'questionid'; foreach ($recs as $rec) { if ($game->sourcemodule == 'glossary') { $key = $rec->glossaryentryid; } else { $key = $rec->questionid; } if (!array_key_exists($key, $selected_recs)) { continue; } $query = new stdClass(); $query->attemptid = $newrec->id; $query->gamekind = $game->gamekind; $query->gameid = $game->id; $query->userid = $USER->id; $query->col = $closed[$i++]; $query->sourcemodule = $game->sourcemodule; $query->questionid = $rec->questionid; $query->glossaryentryid = $rec->glossaryentryid; $query->score = 0; if (($query->id = $DB->insert_record('game_queries', $query)) == 0) { print_error('error inserting in game_queries'); } game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); } game_updateattempts($game, $attempt, 0, 0); game_sudoku_play($id, $game, $attempt, $newrec, false, false, $context); }
function game_hiddenpicture_continue($id, $game, $attempt, $hiddenpicture, $context) { global $DB, $USER; if ($attempt != false and $hiddenpicture != false) { //Continue a previous attempt return game_hiddenpicture_play($id, $game, $attempt, $hiddenpicture, false, $context); } if ($attempt == false) { //Start a new attempt $attempt = game_addattempt($game); } $cols = $game->param1; $rows = $game->param2; if ($cols == 0) { print_error(get_string('hiddenpicture_nocols', 'game')); } if ($rows == 0) { print_error(get_string('hiddenpicture_norows', 'game')); } //new attempt $n = $game->param1 * $game->param2; $recs = game_questions_selectrandom($game, CONST_GAME_TRIES_REPETITION * $n); $selected_recs = game_select_from_repetitions($game, $recs, $n); $newrec = game_hiddenpicture_selectglossaryentry($game, $attempt); if ($recs === false) { print_error(get_string('no_questions', 'game')); } $positions = array(); $pos = 1; for ($col = 0; $col < $cols; $col++) { for ($row = 0; $row < $rows; $row++) { $positions[] = $pos++; } } $i = 0; $field = $game->sourcemodule == 'glossary' ? 'glossaryentryid' : 'questionid'; foreach ($recs as $rec) { if ($game->sourcemodule == 'glossary') { $key = $rec->glossaryentryid; } else { $key = $rec->questionid; } if (!array_key_exists($key, $selected_recs)) { continue; } $query = new stdClass(); $query->attemptid = $newrec->id; $query->gamekind = $game->gamekind; $query->gameid = $game->id; $query->userid = $USER->id; $pos = array_rand($positions); $query->col = $positions[$pos]; unset($positions[$pos]); $query->sourcemodule = $game->sourcemodule; $query->questionid = $rec->questionid; $query->glossaryentryid = $rec->glossaryentryid; $query->score = 0; if (($query->id = $DB->insert_record('game_queries', $query)) == 0) { print_error('error inserting in game_queries'); } game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); } //The score is zero game_updateattempts($game, $attempt, 0, 0); game_hiddenpicture_play($id, $game, $attempt, $newrec, false, $context); }