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 r')) != false){ $reps[ $rec->answertext] = $rec2->r; } } $cryptex->setwords( $answers, $game->param1, $reps); //game->param4 is minimum words //game->param2 is maximum words if( $cryptex->computedata( $crossm, $crossd, $letters, $game->param4, $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->savecryptex( $game, $crossm, $new_crossd, $attempt->id, $letters); } game_updateattempts( $game, $attempt, 0, 0); return game_cryptex_play( $id, $game, $attempt, $cryptexrec, $crossm, false, false, false, $context); } //q means game_queries.id 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 = game_strlen( $answer1); $len2 = game_strlen( $answer2); $equal = ( $len1 == $len2); if( $equal){ for( $i=0; $i < $len1; $i++) { if( game_substr( $answer1, $i, 1) != game_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_play( $id, $game, $attempt, $cryptexrec, $crossm, $updateattempt=false, $onlyshow=false, $showsolution=false, $context) { global $DB; global $CFG; if( $game->toptext != ''){ echo $game->toptext.'
'; } echo '
'; $cryptex = new CryptexDB(); $language = $attempt->language; $questions = $cryptex->loadcryptex( $crossm, $mask, $corrects, $attempt->language); if( $language != $attempt->language){ if( !$DB->set_field( 'game_attempts', 'language', $attempt->language, array( 'id' => $attempt->id))){ print_error( "game_cross_play: Can't set language"); } } if( $attempt->language != '') $wordrtl = game_right_to_left( $attempt->language); else $wordrtl = right_to_left(); $reverseprint = ($wordrtl != right_to_left()); if( $reverseprint) $textdir = 'dir="'.($wordrtl ? 'rtl' : 'ltr').'"'; else $textdir = ''; $len = game_strlen( $mask); //count1 means there is a guested letter //count2 means there is a letter that not guessed $count1 = $count2 = 0; for($i=0; $i < $len; $i++) { $c = game_substr( $mask, $i, 1); if( $c == '1'){ $count1++; }else if( $c == '2') { $count2++; } } if( $count1 + $count2 == 0){ $gradeattempt = 0; }else { $gradeattempt = $count1 / ($count1 + $count2); } $finished = ($count2 == 0); if( ($finished === false) && ($game->param8 > 0)) { $found = false; foreach ( $questions as $q) { if ( $q->tries < $game->param8) $found = true; } if( $found == false) $finished = true; //rich max tries } if( $updateattempt){ game_updateattempts( $game, $attempt, $gradeattempt, $finished); } if( ($onlyshow == false) and ($showsolution == false)){ if( $finished){ game_cryptex_onfinished( $id, $game, $attempt, $cryptexrec); } } ?> '; echo ''; $cryptex->displaycryptex( $crossm->cols, $crossm->rows, $cryptexrec->letters, $mask, $showsolution, $textdir); ?>