Example #1
0
function game_cryptex_check($id, $game, $attempt, $cryptexrec, $q, $answer, $context)
{
    global $DB;
    if ($attempt === false) {
        game_cryptex_continue($id, $game, $attempt, $cryptexrec, false);
        return;
    }
    $crossm = $DB->get_record_select('game_cross', "id={$attempt->id}");
    $query = $DB->get_record_select('game_queries', "id={$q}");
    $answer1 = trim(game_upper($query->answertext));
    $answer2 = trim(game_upper($answer));
    $len1 = textlib::strlen($answer1);
    $len2 = textlib::strlen($answer2);
    $equal = $len1 == $len2;
    if ($equal) {
        for ($i = 0; $i < $len1; $i++) {
            if (textlib::substr($answer1, $i, 1) != textlib::substr($answer2, $i, 1)) {
                $equal = true;
                break;
            }
        }
    }
    if ($equal == false) {
        game_update_queries($game, $attempt, $query, 0, $answer2, true);
        game_cryptex_play($id, $game, $attempt, $cryptexrec, $crossm, true, false, false, $context);
        return;
    }
    game_update_queries($game, $attempt, $query, 1, $answer2);
    $onlyshow = false;
    $showsolution = false;
    game_cryptex_play($id, $game, $attempt, $cryptexrec, $crossm, true, $onlyshow, $showsolution, $context);
}
function game_cryptex_check($id, $game, $attempt, $cryptexrec, $q, $answer)
{
    if ($attempt === false) {
        game_cryptex_continue($id, $game, $attempt, $cryptexrec);
        return;
    }
    $crossm = get_record_select('game_cross', "id={$attempt->id}");
    $query = get_record_select('game_queries', "id={$q}");
    $answer1 = trim(game_upper($query->answertext));
    $answer2 = trim(game_upper($answer));
    $textlib = textlib_get_instance();
    $len1 = $textlib->strlen($answer1);
    $len2 = $textlib->strlen($answer2);
    $equal = $len1 == $len2;
    if ($equal) {
        for ($i = 0; $i < $len1; $i++) {
            if ($textlib->substr($answer1, $i, 1) != $textlib->substr($answer2, $i, 1)) {
                $equal = true;
                break;
            }
        }
    }
    if ($equal == false) {
        game_update_queries($game, $attempt, $query, 0, $answer2);
        game_cryptex_play($id, $game, $attempt, $cryptexrec, $crossm, true);
        return;
    }
    game_update_queries($game, $attempt, $query, 1, $answer2);
    game_cryptex_play($id, $game, $attempt, $cryptexrec, $crossm, true);
}
function game_create($game, $id, $forcenew, $course, $context)
{
    global $USER, $CFG, $DB;
    $attempt = game_getattempt($game, $detail);
    switch ($game->gamekind) {
        case 'cross':
            game_cross_continue($id, $game, $attempt, $detail, '', $forcenew, $context);
            break;
        case 'hangman':
            if (array_key_exists('newletter', $_GET)) {
                $newletter = $_GET['newletter'];
            } else {
                $newletter = '';
            }
            if (array_key_exists('action2', $_GET)) {
                $action2 = $_GET['action2'];
            } else {
                $action2 = '';
            }
            game_hangman_continue($id, $game, $attempt, $detail, $newletter, $action2, $context);
            break;
        case 'millionaire':
            game_millionaire_continue($id, $game, $attempt, $detail, $context);
            break;
        case 'bookquiz':
            if (array_key_exists('chapterid', $_GET)) {
                $chapterid = (int) $_GET['chapterid'];
            } else {
                $chapterid = 0;
            }
            game_bookquiz_continue($id, $game, $attempt, $detail, $chapterid);
            break;
        case 'sudoku':
            game_sudoku_continue($id, $game, $attempt, $detail, '', $context);
            break;
        case 'cryptex':
            game_cryptex_continue($id, $game, $attempt, $detail, $forcenew, $context);
            break;
        case 'snakes':
            game_snakes_continue($id, $game, $attempt, $detail, $context);
            break;
        case 'hiddenpicture':
            game_hiddenpicture_continue($id, $game, $attempt, $detail, $context);
            break;
        default:
            error("Game {$game->gamekind} not found");
            break;
    }
}
function game_create($game, $id, $forcenew, $course, $context)
{
    global $USER, $CFG, $DB;
    $attempt = game_getattempt($game, $detail);
    $chapterid = optional_param('chapterid', 0, PARAM_INT);
    $newletter = optional_param('newletter', '', PARAM_ALPHA);
    $action2 = optional_param('action2', '', PARAM_ALPHA);
    switch ($game->gamekind) {
        case 'cross':
            game_cross_continue($id, $game, $attempt, $detail, '', $forcenew, $context);
            break;
        case 'hangman':
            game_hangman_continue($id, $game, $attempt, $detail, $newletter, $action2, $context);
            break;
        case 'millionaire':
            game_millionaire_continue($id, $game, $attempt, $detail, $context);
            break;
        case 'bookquiz':
            game_bookquiz_continue($id, $game, $attempt, $detail, $chapterid, $context);
            break;
        case 'sudoku':
            game_sudoku_continue($id, $game, $attempt, $detail, '', $context);
            break;
        case 'cryptex':
            game_cryptex_continue($id, $game, $attempt, $detail, $forcenew, $context);
            break;
        case 'snakes':
            game_snakes_continue($id, $game, $attempt, $detail, $context);
            break;
        case 'hiddenpicture':
            game_hiddenpicture_continue($id, $game, $attempt, $detail, $context);
            break;
        default:
            print_error("Game {$game->gamekind} not found");
            break;
    }
}
function game_create($game, $id, $forcenew, $course)
{
    global $USER, $CFG;
    $attempt = game_getattempt($game, $detail);
    switch ($game->gamekind) {
        case 'cross':
            game_cross_continue($id, $game, $attempt, $detail, '', $forcenew);
            break;
        case 'hangman':
            if (array_key_exists('newletter', $_GET)) {
                $newletter = $_GET['newletter'];
            } else {
                $newletter = '';
            }
            if (array_key_exists('action2', $_GET)) {
                $action2 = $_GET['action2'];
            } else {
                $action2 = '';
            }
            game_hangman_continue($id, $game, $attempt, $detail, $newletter, $action2);
            break;
        case 'millionaire':
            game_millionaire_continue($id, $game, $attempt, $detail);
            break;
        case 'bookquiz':
            if (array_key_exists('chapterid', $_GET)) {
                $chapterid = (int) $_GET['chapterid'];
            } else {
                $chapterid = 0;
            }
            game_bookquiz_continue($id, $game, $attempt, $detail, $chapterid);
            break;
        case 'sudoku':
            game_sudoku_continue($id, $game, $attempt, $detail);
            break;
        case 'cryptex':
            game_cryptex_continue($id, $game, $attempt, $detail, $forcenew);
            break;
        case 'snakes':
            game_snakes_continue($id, $game, $attempt, $detail);
            break;
        case 'hiddenpicture':
            game_hiddenpicture_continue($id, $game, $attempt, $detail);
            break;
        case '':
            echo get_string('useupdategame', 'game');
            print_continue($CFG->wwwroot . '/course/view.php?id=' . $course->id);
            break;
        default:
            error("Game {$game->gamekind} not found");
            break;
    }
}