Пример #1
0
function game_cryptex_continue($id, $game, $attempt, $cryptexrec, $endofgame, $context)
{
    global $DB, $USER;
    if ($endofgame) {
        game_updateattempts($game, $attempt, -1, true);
        $endofgame = false;
    }
    if ($attempt != false and $cryptexrec != false) {
        $crossm = $DB->get_record('game_cross', array('id' => $attempt->id));
        return game_cryptex_play($id, $game, $attempt, $cryptexrec, $crossm, false, false, false, $context);
    }
    if ($attempt === false) {
        $attempt = game_addattempt($game);
    }
    $cryptex = new CryptexDB();
    $questions = array();
    $infos = array();
    $answers = array();
    $recs = game_questions_shortanswer($game);
    if ($recs == false) {
        print_error(get_string('no_words', 'game'));
    }
    $infos = array();
    $reps = array();
    foreach ($recs as $rec) {
        if ($game->param7 == false) {
            if (game_strpos($rec->answertext, ' ')) {
                continue;
                // Spaces not allowed.
            }
        }
        $rec->answertext = game_upper($rec->answertext);
        $answers[$rec->answertext] = game_repairquestion($rec->questiontext);
        $infos[$rec->answertext] = array($game->sourcemodule, $rec->questionid, $rec->glossaryentryid);
        $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) {
            $reps[$rec->answertext] = $rec2->r;
        }
    }
    $cryptex->setwords($answers, $game->param1, $reps);
    // The game->param4 is minimum words.
    // The game->param2 is maximum words.
    if ($cryptex->computedata($crossm, $crossd, $letters, $game->param4, $game->param2)) {
        $newcrossd = array();
        foreach ($crossd as $rec) {
            if (array_key_exists($rec->answertext, $infos)) {
                $info = $infos[$rec->answertext];
                $rec->id = 0;
                $rec->sourcemodule = $info[0];
                $rec->questionid = $info[1];
                $rec->glossaryentryid = $info[2];
            }
            game_update_queries($game, $attempt, $rec, 0, '');
            $newcrossd[] = $rec;
        }
        $cryptexrec = $cryptex->savecryptex($game, $crossm, $newcrossd, $attempt->id, $letters);
    }
    game_updateattempts($game, $attempt, 0, 0);
    return game_cryptex_play($id, $game, $attempt, $cryptexrec, $crossm, false, false, false, $context);
}
Пример #2
0
function game_cross_new($game, $attemptid, &$crossm)
{
    global $DB, $USER;
    $cross = new CrossDB();
    $questions = array();
    $infos = array();
    $answers = array();
    $recs = game_questions_shortanswer($game);
    if ($recs == false) {
        print_error('game_cross_continue: ' . get_string('no_words', 'game'));
    }
    $infos = array();
    $reps = array();
    foreach ($recs as $rec) {
        if ($game->param7 == false) {
            if (game_strpos($rec->answertext, ' ')) {
                continue;
                // Spaces not allowed.
            }
        }
        $rec->answertext = game_upper($rec->answertext);
        $answers[$rec->answertext] = game_repairquestion($rec->questiontext);
        $infos[$rec->answertext] = array($game->sourcemodule, $rec->questionid, $rec->glossaryentryid, $rec->attachment);
        $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) {
            $reps[$rec->answertext] = $rec2->r;
        }
    }
    $cross->setwords($answers, $game->param1, $reps);
    // The game->param4 is minimum words in crossword.
    // The game->param2 is maximum words in crossword.
    if ($cross->computedata($crossm, $crossd, $lettets, $game->param4, $game->param2, $game->param8)) {
        $newcrossd = array();
        foreach ($crossd as $rec) {
            $info = $infos[$rec->answertext];
            if ($info != false) {
                $rec->sourcemodule = $info[0];
                $rec->questionid = $info[1];
                $rec->glossaryentryid = $info[2];
                $rec->attachment = $info[3];
            }
            $newcrossd[] = $rec;
        }
        $cross->savecross($game, $crossm, $newcrossd, $attemptid);
    }
    if (count($crossd) == 0) {
        print_error('game_cross_continue: ' . get_string('no_words', 'game') . $game->id);
    }
}
Пример #3
0
function hangman_existall($str, $strfind)
{
    $n = game_strlen($str);
    for ($i = 0; $i < $n; $i++) {
        $pos = game_strpos($strfind, game_substr($str, $i, 1));
        if ($pos === false) {
            return false;
        }
    }
    return true;
}
Пример #4
0
function hangman_onincorrect($id, $wordline, $word, $game, $attempt, $hangman, $onlyshow, $showsolution)
{
    echo "\r\n<br/><br/><font size=\"5\">\n{$wordline}</font>\r\n";
    if ($onlyshow or $showsolution) {
        return;
    }
    echo '<p><BR/><font size="5" color="red">' . get_string('hangman_loose', 'game') . '</font><BR/><BR/></p>';
    if ($game->param6) {
        // Show the correct answer.
        if (game_strpos($word, ' ') != false) {
            echo '<br/>' . get_string('hangman_correct_phrase', 'game');
        } else {
            echo '<br/>' . get_string('hangman_correct_word', 'game');
        }
        echo '<B>' . $word . "</B><BR/><BR/>\r\n";
    }
    game_hangman_show_nextword($id, $game, $attempt, $hangman, true);
}