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_sudoku_continue($id, $game, $attempt, $sudoku, $endofgame = '') { global $CFG, $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); } if ($attempt == false) { $attempt = game_addattempt($game); } //new game srand((double) microtime() * 1000000); $recsudoku = getrandomsudoku(); if ($recsudoku == false) { $link = "<a href=\"{$CFG->wwwroot}/mod/game/db/importsudoku.php\">import</a>"; echo get_string('sudoku_emptydatabase', 'game', $link); die; } $newrec->id = $attempt->id; $newrec->guess = ''; $newrec->data = $recsudoku->data; $newrec->opened = $recsudoku->opened; $need = 81 - $recsudoku->opened; $recs = game_questions_selectrandom($game, $need); if ($recs === false) { error(get_string('sudoku_no_questions', 'game')); } $closed = game_sudoku_getclosed($newrec->data); $n = min(count($closed), count($recs)); //if the teacher set the maximum number of questions if ($game->param2 > 0) { if ($game->param2 < $n) { $n = $game->param2; } } $closed = array_rand($closed, $n); if (!game_insert_record('game_sudoku', $newrec)) { error('error inserting in game_sudoku'); } $i = 0; foreach ($recs as $rec) { if ($i >= $n) { break; } unset($query); $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 = insert_record("game_queries", $query)) == 0) { error('error inserting in game_queries'); } } game_updateattempts($game, $attempt, 0, 0); game_sudoku_play($id, $game, $attempt, $newrec); }