当前位置: 首页>>代码示例>>PHP>>正文


PHP game_addattempt函数代码示例

本文整理汇总了PHP中game_addattempt函数的典型用法代码示例。如果您正苦于以下问题:PHP game_addattempt函数的具体用法?PHP game_addattempt怎么用?PHP game_addattempt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了game_addattempt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: game_cryptex_continue

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);
}
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:60,代码来源:play.php

示例2: game_millionaire_continue

/**
 * This file plays the game millionaire
 * 
 * @author  bdaloukas
 * @version $Id: play.php,v 1.31 2012/07/25 11:16:05 bdaloukas Exp $
 * @package game
 **/
function game_millionaire_continue($id, $game, $attempt, $millionaire, $context)
{
    // User must select quiz or question as a source module.
    if ($game->quizid == 0 and $game->questioncategoryid == 0) {
        if ($game->sourcemodule == 'quiz') {
            print_error(get_string('millionaire_must_select_quiz', 'game'));
        } else {
            print_error(get_string('millionaire_must_select_questioncategory', 'game'));
        }
    }
    if ($attempt != false and $millionaire != false) {
        // Continue an existing game.
        return game_millionaire_play($id, $game, $attempt, $millionaire, $context);
    }
    if ($attempt == false) {
        $attempt = game_addattempt($game);
    }
    $newrec = new stdClass();
    $newrec->id = $attempt->id;
    $newrec->queryid = 0;
    $newrec->level = 0;
    $newrec->state = 0;
    if (!game_insert_record('game_millionaire', $newrec)) {
        print_error('error inserting in game_millionaire');
    }
    game_millionaire_play($id, $game, $attempt, $newrec, $context);
}
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:34,代码来源:play.php

示例3: game_hiddenpicture_continue

function game_hiddenpicture_continue($id, $game, $attempt, $hiddenpicture)
{
    global $CFG, $USER;
    if ($attempt != false and $hiddenpicture != false) {
        //Continue a previous attempt
        return game_hiddenpicture_play($id, $game, $attempt, $hiddenpicture);
    }
    if ($attempt == false) {
        //Start a new attempt
        $attempt = game_addattempt($game);
    }
    $cols = $game->param1;
    $rows = $game->param2;
    if ($cols == 0) {
        error(get_string('hiddenpicture_nocols', 'game'));
    }
    if ($rows == 0) {
        error(get_string('hiddenpicture_norows', 'game'));
    }
    //new attempt
    $n = $game->param1 * $game->param2;
    $recs = game_questions_selectrandom($game, $n);
    $newrec = game_hiddenpicture_selectglossaryentry($game, $attempt);
    if ($recs === false) {
        error(get_string('hiddenpicture_no_questions', 'game'));
    }
    $positions = array();
    $pos = 1;
    for ($col = 0; $col < $cols; $col++) {
        for ($row = 0; $row < $rows; $row++) {
            $positions[] = $pos++;
        }
    }
    $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;
        $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 = insert_record("game_queries", $query)) == 0) {
            error('error inserting in game_queries');
        }
    }
    //The score is zero
    game_updateattempts($game, $attempt, 0, 0);
    game_hiddenpicture_play($id, $game, $attempt, $newrec);
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:58,代码来源:play.php

示例4: game_cross_continue

function game_cross_continue($id, $game, $attempt, $cross, $g = '', $endofgame = '')
{
    if ($endofgame) {
        if ($g == '') {
            game_updateattempts($game, $attempt, -1, true);
            $endofgame = false;
        }
    }
    if ($attempt != false and $cross != false) {
        return game_cross_play($id, $game, $attempt, $cross, $g, false, false, $endofgame, false, false, false, false);
    }
    if ($attempt == false) {
        $attempt = game_addattempt($game);
    }
    $textlib = textlib_get_instance();
    $cross = new CrossDB();
    $questions = array();
    $infos = array();
    $answers = array();
    $recs = game_questions_shortanswer($game);
    if ($recs == false) {
        error('game_cross_continue: ' . get_string('cross_nowords', 'game'));
    }
    $infos = array();
    foreach ($recs as $rec) {
        if ($game->param7 == false) {
            if ($textlib->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);
    }
    $cross->setwords($answers, $game->param1);
    if ($cross->computedata($crossm, $crossd, $game->param2)) {
        $new_crossd = 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];
            }
            $new_crossd[] = $rec;
        }
        $cross->save($game, $crossm, $new_crossd, $attempt->id);
        game_updateattempts($game, $attempt, 0, 0);
        return game_cross_play($id, $game, $attempt, $crossm, '', false, false, false, false, false, false, false);
    }
    if (count($crossd) == 0) {
        error('game_cross_continue: ' . get_string('cross_nowords', 'game'));
    }
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:56,代码来源:play.php

示例5: game_cryptex_continue

function game_cryptex_continue($id, $game, $attempt, $cryptexrec, $endofgame)
{
    if ($endofgame) {
        game_updateattempts($game, $attempt, -1, true);
        $endofgame = false;
    }
    if ($attempt != false and $cryptexrec != false) {
        $crossm = get_record_select('game_cross', "id={$attempt->id}");
        return game_cryptex_play($id, $game, $attempt, $cryptexrec, $crossm);
    }
    if ($attempt === false) {
        $attempt = game_addattempt($game);
    }
    $textlib = textlib_get_instance();
    $cryptex = new CryptexDB();
    $questions = array();
    $infos = array();
    $answers = array();
    $recs = game_questions_shortanswer($game);
    if ($recs == false) {
        error(get_string('cryptex_nowords', 'game'));
    }
    $infos = array();
    foreach ($recs as $rec) {
        if ($game->param7 == false) {
            if ($textlib->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);
    }
    $cryptex->setwords($answers, $game->param1);
    if ($cryptex->computedata($crossm, $crossd, $letters, $game->param2)) {
        $new_crossd = 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, '');
            $new_crossd[] = $rec;
        }
        $cryptexrec = $cryptex->save($game, $crossm, $new_crossd, $attempt->id, $letters);
    }
    game_updateattempts($game, $attempt, 0, 0);
    return game_cryptex_play($id, $game, $attempt, $cryptexrec, $crossm);
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:53,代码来源:play.php

示例6: game_bookquiz_continue

function game_bookquiz_continue($id, $game, $attempt, $bookquiz, $chapterid = 0)
{
    if ($attempt != false and $bookquiz != false) {
        return game_bookquiz_play($id, $game, $attempt, $bookquiz, $chapterid);
    }
    if ($attempt == false) {
        $attempt = game_addattempt($game);
    }
    unset($bookquiz);
    $bookquiz->lastchapterid = 0;
    $bookquiz->id = $attempt->id;
    if (!game_insert_record('game_bookquiz', $bookquiz)) {
        error('game_bookquiz_continue: error inserting in game_bookquiz');
    }
    return game_bookquiz_play($id, $game, $attempt, $bookquiz, 0);
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:16,代码来源:play.php

示例7: game_bookquiz_continue

function game_bookquiz_continue($id, $game, $attempt, $bookquiz, $chapterid, $context)
{
    if ($attempt != false and $bookquiz != false) {
        return game_bookquiz_play($id, $game, $attempt, $bookquiz, $chapterid, $context);
    }
    if ($attempt == false) {
        $attempt = game_addattempt($game);
    }
    $bookquiz = new stdClass();
    $bookquiz->lastchapterid = 0;
    $bookquiz->id = $attempt->id;
    $bookquiz->bookid = $game->bookid;
    if (!game_insert_record('game_bookquiz', $bookquiz)) {
        print_error('game_bookquiz_continue: error inserting in game_bookquiz');
    }
    return game_bookquiz_play($id, $game, $attempt, $bookquiz, 0, $context);
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:17,代码来源:play.php

示例8: game_cross_continue

function game_cross_continue($id, $game, $attempt, $cross, $g, $endofgame, $context)
{
    if ($endofgame) {
        if ($g == '') {
            game_updateattempts($game, $attempt, -1, true);
            $endofgame = false;
        }
    }
    if ($attempt != false and $cross != false) {
        return game_cross_play($id, $game, $attempt, $cross, $g, false, false, $endofgame, false, false, false, false, true, $context);
    }
    if ($attempt == false) {
        $attempt = game_addattempt($game);
    }
    game_cross_new($game, $attempt->id, $crossm);
    game_updateattempts($game, $attempt, 0, 0);
    return game_cross_play($id, $game, $attempt, $crossm, '', false, false, false, false, false, false, false, true, $context);
}
开发者ID:antoniorodrigues,项目名称:redes-digitais,代码行数:18,代码来源:play.php

示例9: game_snakes_continue

function game_snakes_continue($id, $game, $attempt, $snakes)
{
    if ($attempt != false and $snakes != false) {
        return game_snakes_play($id, $game, $attempt, $snakes);
    }
    if ($attempt === false) {
        $attempt = game_addattempt($game);
    }
    $newrec->id = $attempt->id;
    $newrec->snakesdatabaseid = $game->param3;
    $newrec->position = 1;
    $newrec->queryid = 0;
    $newrec->dice = rand(1, 6);
    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);
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:19,代码来源:play.php

示例10: game_millionaire_continue

/**
 * This files plays the game millionaire
 * 
 * @author  bdaloukas
 * @version $Id: play.php,v 1.16 2009/09/12 08:12:56 bdaloukas Exp $
 * @package game
 **/
function game_millionaire_continue($id, $game, $attempt, $millionaire)
{
    //User must select quiz or question as a source module
    if ($game->quizid == 0 and $game->questioncategoryid == 0) {
        error(get_string($game->sourcemodule == 'quiz' ? 'millionaire_must_select_quiz' : 'millionaire_must_select_questioncategory'));
    }
    if ($attempt != false and $millionaire != false) {
        //continue an existing game
        return game_millionaire_play($id, $game, $attempt, $millionaire);
    }
    if ($attempt == false) {
        $attempt = game_addattempt($game);
    }
    $newrec->id = $attempt->id;
    $newrec->queryid = 0;
    $newrec->level = 0;
    $newrec->state = 0;
    if (!game_insert_record('game_millionaire', $newrec)) {
        error('error inserting in game_millionaire');
    }
    game_millionaire_play($id, $game, $attempt, $newrec);
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:29,代码来源:play.php

示例11: game_sudoku_continue

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);
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:72,代码来源:play.php

示例12: game_hiddenpicture_continue

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);
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:66,代码来源:play.php

示例13: game_getattempt

function game_getattempt($game, &$detail, $autoadd = false)
{
    global $DB, $USER;
    $select = "gameid={$game->id} AND userid={$USER->id} and timefinish=0 ";
    if ($USER->id == 1) {
        $key = 'mod/game:instanceid' . $game->id;
        if (array_key_exists($key, $_SESSION)) {
            $select .= ' AND id="' . $_SESSION[$key] . '"';
        } else {
            $select .= ' AND id=-1';
        }
    }
    if ($recs = $DB->get_records_select('game_attempts', $select)) {
        foreach ($recs as $attempt) {
            if ($USER->id == 1) {
                $_SESSION[$key] = $attempt->id;
            }
            $detail = $DB->get_record('game_' . $game->gamekind, array('id' => $attempt->id));
            return $attempt;
        }
    }
    if ($autoadd) {
        game_addattempt($game);
        return game_getattempt($game, $detail, false);
    }
    return false;
}
开发者ID:nadavkav,项目名称:Moodle2-Hebrew-plugins,代码行数:27,代码来源:locallib.php

示例14: game_sudoku_continue

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);
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:64,代码来源:play.php

示例15: game_hangman_continue


//.........这里部分代码省略.........
        if ($game->param7 == false) {
            // I don't allow spaces.
            if (strpos($answer, " ")) {
                continue;
            }
        }
        $copy = false;
        $select2 = 'gameid=? AND userid=? AND questionid=? AND glossaryentryid=?';
        if (($rec2 = $DB->get_record_select('game_repetitions', $select2, array($game->id, $USER->id, $rec->questionid, $rec->glossaryentryid), 'id,repetitions AS r')) != false) {
            if ($rec2->r < $minnum or $minnum == 0) {
                $minnum = $rec2->r;
                $copy = true;
            }
        } else {
            $minnum = 0;
            $copy = true;
        }
        if ($copy) {
            $found = true;
            $min = new stdClass();
            $min->questionid = $rec->questionid;
            $min->glossaryentryid = $rec->glossaryentryid;
            $min->attachment = $rec->attachment;
            $min->questiontext = $rec->questiontext;
            $min->answerid = $rec->answerid;
            $min->answer = $answer;
            $min->language = $game->language;
            $min->allletters = $allletters;
            if ($minnum == 0) {
                break;
                // We found an unused word.
            }
        } else {
            $unchanged++;
        }
        if ($unchanged > 2) {
            if ($found) {
                break;
            }
        }
    }
    if ($found == false) {
        print_error(get_string('no_words', 'game'));
    }
    // Found one word for hangman.
    if ($attempt == false) {
        $attempt = game_addattempt($game);
    }
    if (!$DB->set_field('game_attempts', 'language', $min->language, array('id' => $attempt->id))) {
        print_error("game_hangman_continue: Can't set language");
    }
    $query = new stdClass();
    $query->attemptid = $attempt->id;
    $query->gameid = $game->id;
    $query->userid = $USER->id;
    $query->sourcemodule = $game->sourcemodule;
    $query->questionid = $min->questionid;
    $query->glossaryentryid = $min->glossaryentryid;
    $query->attachment = $min->attachment;
    $query->questiontext = addslashes($min->questiontext);
    $query->score = 0;
    $query->timelastattempt = time();
    $query->answertext = $min->answer;
    $query->answerid = $min->answerid;
    if (!($query->id = $DB->insert_record('game_queries', $query))) {
        print_error("game_hangman_continue: Can't insert to table game_queries");
    }
    $newrec = new stdClass();
    $newrec->id = $attempt->id;
    $newrec->queryid = $query->id;
    if ($updatehangman == false) {
        $newrec->maxtries = $game->param4;
        if ($newrec->maxtries == 0) {
            $newrec->maxtries = 1;
        }
        $newrec->finishedword = 0;
        $newrec->corrects = 0;
    }
    $newrec->allletters = $min->allletters;
    $letters = '';
    if ($game->param1) {
        $letters .= game_substr($min->answer, 0, 1);
    }
    if ($game->param2) {
        $letters .= game_substr($min->answer, -1, 1);
    }
    $newrec->letters = $letters;
    if ($updatehangman == false) {
        if (!game_insert_record('game_hangman', $newrec)) {
            print_error('game_hangman_continue: error inserting in game_hangman');
        }
    } else {
        if (!$DB->update_record('game_hangman', $newrec)) {
            print_error('game_hangman_continue: error updating in game_hangman');
        }
        $newrec = $DB->get_record('game_hangman', array('id' => $newrec->id));
    }
    game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid);
    game_hangman_play($id, $game, $attempt, $newrec, false, false, $context);
}
开发者ID:antoniorodrigues,项目名称:redes-digitais,代码行数:101,代码来源:play.php


注:本文中的game_addattempt函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。