public function showhtml_base($crossm, $crossd, $showsolution, $showhtmlsolutions, $showstudentguess, $context, $game) { $this->mLegendh = array(); $this->mLegendv = array(); $sret = "CrosswordWidth = {$crossm->cols};\n"; $sret .= "CrosswordHeight = {$crossm->rows};\n"; $sret .= "Words=" . count($crossd) . ";\n"; $swordlength = ""; $sguess = ""; $ssolutions = ''; $shtmlsolutions = ''; $swordx = ""; $swordy = ""; $sclue = ""; $lasthorizontalword = -1; $i = -1; $legendv = array(); $legendh = array(); if ($game->glossaryid) { $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); $contextglossary = game_get_context_module_instance($cmglossary->id); } foreach ($crossd as $rec) { if ($rec->horizontal == false and $lasthorizontalword == -1) { $lasthorizontalword = $i; } $i++; $swordlength .= "," . game_strlen($rec->answertext); if ($rec->questionid != 0) { $q = game_filterquestion(str_replace('\\"', '"', $rec->questiontext), $rec->questionid, $context->id, $game->course); $rec->questiontext = game_repairquestion($q); } else { // Glossary. $q = game_filterglossary(str_replace('\\"', '"', $rec->questiontext), $rec->glossaryentryid, $contextglossary->id, $game->course); $rec->questiontext = game_repairquestion($q); } $sclue .= ',"' . game_tojavascriptstring(game_filtertext($rec->questiontext, 0)) . "\"\r\n"; if ($showstudentguess) { $sguess .= ',"' . $rec->studentanswer . '"'; } else { $sguess .= ",''"; } $swordx .= "," . ($rec->col - 1); $swordy .= "," . ($rec->row - 1); if ($showsolution) { $ssolutions .= ',"' . $rec->answertext . '"'; } else { $ssolutions .= ',""'; } if ($showhtmlsolutions) { $shtmlsolutions .= ',"' . base64_encode($rec->answertext) . '"'; } $attachment = ''; $s = $rec->questiontext . $attachment; if ($rec->horizontal) { if (array_key_exists($rec->row, $legendh)) { $legendh[$rec->row][] = $s; } else { $legendh[$rec->row] = array($s); } } else { if (array_key_exists($rec->col, $legendv)) { $legendv[$rec->col][] = $s; } else { $legendv[$rec->col] = array($s); } } } $letters = get_string('lettersall', 'game'); $this->mlegendh = array(); foreach ($legendh as $key => $value) { if (count($value) == 1) { $this->mlegendh[$key] = $value[0]; } else { for ($i = 0; $i < count($value); $i++) { $this->mlegendh[$key . game_substr($letters, $i, 1)] = $value[$i]; } } } $this->mlegendv = array(); foreach ($legendv as $key => $value) { if (count($value) == 1) { $this->mlegendv[$key] = $value[0]; } else { for ($i = 0; $i < count($value); $i++) { $this->mlegendv[$key . game_substr($letters, $i, 1)] = $value[$i]; } } } ksort($this->mlegendh); ksort($this->mlegendv); $sret .= "WordLength = new Array( " . game_substr($swordlength, 1) . ");\n"; $sret .= "Clue = new Array( " . game_substr($sclue, 1) . ");\n"; $sguess = str_replace(' ', '_', $sguess); $sret .= "Guess = new Array( " . game_substr($sguess, 1) . ");\n"; $sret .= "Solutions = new Array( " . game_substr($ssolutions, 1) . ");\n"; if ($showhtmlsolutions) { $sret .= "HtmlSolutions = new Array( " . game_substr($shtmlsolutions, 1) . ");\n"; } $sret .= "WordX = new Array( " . game_substr($swordx, 1) . ");\n"; $sret .= "WordY = new Array( " . game_substr($swordy, 1) . ");\n"; $sret .= "LastHorizontalWord = {$lasthorizontalword};\n"; return $sret; }
function showhtml_base($crossm, $crossd, $showsolution, $showhtmlsolutions, $showstudentguess, $context, $game) { $textlib = textlib_get_instance(); $this->m_LegendH = array(); $this->m_LegendV = array(); $sRet = "CrosswordWidth = {$crossm->cols};\n"; $sRet .= "CrosswordHeight = {$crossm->rows};\n"; $sRet .= "Words=" . count($crossd) . ";\n"; $sWordLength = ""; $sguess = ""; $ssolutions = ''; $shtmlsolutions = ''; $sWordX = ""; $sWordY = ""; $sClue = ""; $LastHorizontalWord = -1; $i = -1; $LegendV = array(); $LegendH = array(); if ($game->glossaryid) { $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); $contextglossary = get_context_instance(CONTEXT_MODULE, $cmglossary->id); } foreach ($crossd as $rec) { if ($rec->horizontal == false and $LastHorizontalWord == -1) { $LastHorizontalWord = $i; } $i++; $sWordLength .= "," . $textlib->strlen($rec->answertext); if ($rec->questionid != 0) { $q = game_filterquestion(str_replace('\\"', '"', $rec->questiontext), $rec->questionid, $context->id, $game->course); $rec->questiontext = game_repairquestion($q); } else { //glossary $q = game_filterglossary(str_replace('\\"', '"', $rec->questiontext), $rec->glossaryentryid, $contextglossary->id, $game->course); $rec->questiontext = game_repairquestion($q); } $sClue .= ',"' . game_tojavascriptstring(game_filtertext($rec->questiontext, 0)) . "\"\r\n"; if ($showstudentguess) { $sguess .= ',"' . $rec->studentanswer . '"'; } else { $sguess .= ",''"; } $sWordX .= "," . ($rec->col - 1); $sWordY .= "," . ($rec->row - 1); if ($showsolution) { $ssolutions .= ',"' . $rec->answertext . '"'; } else { $ssolutions .= ',""'; } if ($showhtmlsolutions) { $shtmlsolutions .= ',"' . base64_encode($rec->answertext) . '"'; } $attachment = ''; //if( game_issoundfile( $rec->attachment)){ // $attachment = game_showattachment( $rec->attachment); //} $s = $rec->questiontext . $attachment; if ($rec->horizontal) { if (array_key_exists($rec->row, $LegendH)) { $LegendH[$rec->row][] = $s; } else { $LegendH[$rec->row] = array($s); } } else { if (array_key_exists($rec->col, $LegendV)) { $LegendV[$rec->col][] = $s; } else { $LegendV[$rec->col] = array($s); } } } $letters = get_string('lettersall', 'game'); $textlib = textlib_get_instance(); $this->m_LegendV = array(); foreach ($LegendH as $key => $value) { if (count($value) == 1) { $this->m_LegendH[$key] = $value[0]; } else { for ($i = 0; $i < count($value); $i++) { $this->m_LegendH[$key . $textlib->substr($letters, $i, 1)] = $value[$i]; } } } $this->m_LegendV = array(); foreach ($LegendV as $key => $value) { if (count($value) == 1) { $this->m_LegendV[$key] = $value[0]; } else { for ($i = 0; $i < count($value); $i++) { $this->m_LegendV[$key . $textlib->substr($letters, $i, 1)] = $value[$i]; } } } ksort($this->m_LegendH); ksort($this->m_LegendV); $sClue = $textlib->substr($sClue, 1, $textlib->strlen($sClue) - 1); $sRet .= "WordLength = new Array( " . $textlib->substr($sWordLength, 1, $textlib->strlen($sWordLength) - 1) . ");\n"; $sRet .= "Clue = new Array( " . $sClue . ");\n"; $sguess = str_replace(' ', '_', $sguess); $sRet .= "Guess = new Array( " . $textlib->substr($sguess, 1, $textlib->strlen($sguess) - 1) . ");\n"; $sRet .= "Solutions = new Array( " . $textlib->substr($ssolutions, 1, $textlib->strlen($ssolutions) - 1) . ");\n"; if ($showhtmlsolutions) { $sRet .= "HtmlSolutions = new Array( " . $textlib->substr($shtmlsolutions, 1, $textlib->strlen($shtmlsolutions) - 1) . ");\n"; } $sRet .= "WordX = new Array( " . $textlib->substr($sWordX, 1, $textlib->strlen($sWordX) - 1) . ");\n"; $sRet .= "WordY = new Array( " . $textlib->substr($sWordY, 1, $textlib->strlen($sWordY) - 1) . ");\n"; $sRet .= "LastHorizontalWord = {$LastHorizontalWord};\n"; return $sRet; }
function game_cryptex_play($id, $game, $attempt, $cryptexrec, $crossm, $updateattempt = false, $onlyshow = false, $showsolution = false, $context) { global $DB; $textlib = textlib_get_instance(); global $CFG; if ($game->toptext != '') { echo $game->toptext . '<br>'; } echo '<br>'; $cryptex = new CryptexDB(); $language = $attempt->language; $questions = $cryptex->load($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 = $textlib->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 = $textlib->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); } } ?> <style type="text/css"><!-- .answerboxstyle { background-color: #FFFAF0; border-color: #808080; border-style: solid; border-width: 1px; display: block; padding: .75em; width: 240pt; } --></style> <?php echo '<table border=0>'; echo '<tr><td>'; $cryptex->display($crossm->cols, $crossm->rows, $cryptexrec->letters, $mask, $showsolution, $textdir); ?> </td> <td width=10%> </td> <td> <form method="get" action="<?php echo $CFG->wwwroot; ?> /mod/game/attempt.php"> <div id="answerbox" class="answerboxstyle" style="display:none;"> <div id="wordclue" name="wordclue" class="cluebox"> </div> <input id="action" name="action" type="hidden" value="cryptexcheck"> <input id="q" name="q" type="hidden" > <input id="id" name="id" value="<?php echo $id; ?> " type="hidden"> <div style="margin-top:1em;"><input id="answer" name="answer" type="text" size="24" style="font-weight: bold; text-transform:uppercase;" autocomplete="off"></div> <table border="0" cellspacing="0" cellpadding="0" width="100%" style="margin-top:1em;"><tr> <td align="right"> <button id="okbutton" type="submit" class="button" style="font-weight: bold;">OK</button> <button id="cancelbutton" type="button" class="button" onclick="DeselectCurrentWord();">Cancel</button> </td></tr></table> </form> </td> </tr> </table> <?php $grade = round(100 * $gradeattempt); echo '<br>' . get_string('grade', 'game') . ' ' . $grade . ' %'; echo "<br><br>"; $i = 0; $else = ''; $contextglossary = false; foreach ($questions as $key => $q) { $i++; if ($showsolution == false) { //When I want to show the solution a want to show the questions to. if (array_key_exists($q->id, $corrects)) { continue; } } $questiontext = $q->questiontext; if ($q->questionid != 0) { $questiontext = game_filterquestion($questiontext, $q->questionid, $context->id, $game->course); } else { if ($contextglossary === false) { $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); $contextglossary = get_context_instance(CONTEXT_MODULE, $cmglossary->id); } $questiontext = game_filterglossary($questiontext, $q->glossaryentryid, $contextglossary->id, $game->course); } $question = "{$i}. " . $questiontext; if ($onlyshow == false and $showsolution == false) { if ($game->param8 == 0 || $game->param8 > $q->tries) { $question .= ' <input type="submit" value="' . get_string('answer') . '" onclick="OnCheck( ' . $q->id . ');" />'; $questiontext = str_replace(array("\n", "\r"), array(' ', ' '), $questiontext); if ($else != '') { $else .= "\r\n else "; } $else .= "if (id == {$q->id})\r\n question=\"{$i}. {$questiontext}\";"; } } $question = str_replace('\\"', '"', $question); echo $question; if ($showsolution) { echo " {$q->answertext}<B></b>"; } echo '<br>'; } if ($game->bottomtext != '') { echo '<br><br>' . $game->bottomtext; } ?> <script> function OnCheck( id) { var question; <?php echo $else; ?> document.getElementById("q").value = id; document.getElementById("wordclue").innerHTML = question; // Finally, show the answer box. document.getElementById("answerbox").style.display = "block"; try { document.getElementById("answer").focus(); document.getElementById("answer").select(); } catch (e) { } } </script> <?php }
function game_show_query($game, $query, $text) { if ($game->glossaryid) { $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); $contextglossary = game_get_context_module_instance($cmglossary->id); return game_filterglossary(str_replace('\\"', '"', $text), $query->glossaryentryid, $contextglossary->id, $game->course); } else { if ($query->questionid) { $cmgame = get_coursemodule_from_instance('game', $game->id, $game->course); $context = game_get_context_module_instance($cmgame->id); $text = str_replace(array("\\'", '\\"'), array("'", '"'), $text); return game_filterquestion($text, $query->questionid, $context->id, $game->course); } } return $text; }
function game_snakes_showquestion_glossary($id, $snakes, $query, $game) { global $CFG, $DB; $entry = $DB->get_record('glossary_entries', array('id' => $query->glossaryentryid)); /// Start the form echo "<form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"" . get_string('sudoku_submit', 'game') . "\"></center>\n"; // Add a hidden field with the queryid echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; echo '<input type="hidden" name="action" value="snakescheckg" />'; echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; /// Print all the questions // Add a hidden field with glossaryentryid echo '<input type="hidden" name="glossaryentryid" value="' . $query->glossaryentryid . "\" />\n"; $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); $contextglossary = get_context_instance(CONTEXT_MODULE, $cmglossary->id); $s = game_filterglossary(str_replace('\\"', '"', $entry->definition), $query->glossaryentryid, $contextglossary->id, $game->course); echo $s . '<br>'; echo get_string('answer') . ': '; echo "<input type=\"text\" name=\"answer\" size=30 /><br>"; echo "</form>\n"; }
function hangman_showpage(&$done, &$correct, &$wrong, $max, &$wordline, &$wordline2, &$links, $game, &$attempt, &$hangman, &$query, $onlyshow, $showsolution, $context) { global $USER, $CFG, $DB; $id = optional_param('id', 0, PARAM_INT); // Course Module ID. $word = $query->answertext; $newletter = optional_param('newletter', "", PARAM_TEXT); if ($newletter == '_') { $newletter = ' '; } if ($newletter == 'A') { $letters = $hangman->letters; if ($newletter != null) { if (game_strpos($letters, $newletter) === false) { $letters .= $newletter; } if (game_strpos($letters, 'Ã') === false) { $letters .= 'Ã'; } } } elseif ($newletter == 'C') { $letters = $hangman->letters; if ($newletter != null) { if (game_strpos($letters, $newletter) === false) { $letters .= $newletter; } if (game_strpos($letters, 'Ç') === false) { $letters .= 'Ç'; } } } else { $letters = $hangman->letters; if ($newletter != null) { if (game_strpos($letters, $newletter) === false) { $letters .= $newletter; } } } $links = ""; $alpha = $hangman->allletters; $wrong = 0; if ($query->questionid) { $questiontext = str_replace(array("\\'", '\\"'), array("'", '"'), $query->questiontext); $query->questiontext = game_filterquestion($questiontext, $query->questionid, $context->id, $game->course); } else { $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); $contextglossary = game_get_context_module_instance($cmglossary->id); $query->questiontext = game_filterglossary(str_replace('\\"', '"', $query->questiontext), $query->glossaryentryid, $contextglossary->id, $game->course); } if ($game->param5) { $s = trim(game_filtertext($query->questiontext, $game->course)); if ($s != '.' and $s != '') { echo "<br/><b>" . $s . '</b>'; } if ($query->attachment != '') { $file = "{$CFG->wwwroot}/file.php/{$game->course}/moddata/{$query->attachment}"; echo "<img src=\"{$file}\" />"; } echo "<br/><br/>"; } $wordline = $wordline2 = ""; $len = game_strlen($word); $done = 1; $answer = ''; $correct = 0; for ($x = 0; $x < $len; $x++) { $char = game_substr($word, $x, 1); if ($showsolution) { $wordline2 .= $char == " " ? ' ' : $char; $done = 0; } if (game_strpos($letters, $char) === false) { $wordline .= "_<font size=\"1\"> </font>\r\n"; $done = 0; $answer .= '_'; } else { $wordline .= $char == " " ? ' ' : $char; $answer .= $char; $correct++; } } $lenalpha = game_strlen($alpha); $fontsize = 5; for ($c = 0; $c < $lenalpha; $c++) { $char = game_substr($alpha, $c, 1); if (game_strpos($letters, $char) === false) { // User doesn't select this character. $params = 'id=' . $id . '&newletter=' . urlencode($char); if ($onlyshow or $showsolution) { $links .= $char; } else { $links .= "<font size=\"{$fontsize}\"><a href=\"attempt.php?{$params}\">{$char}</a></font>\r\n"; } continue; } if ($char == 'A') { if (game_strpos($word, $char) === false and game_strpos($word, 'Ã') === false) { $links .= "\r\n<font size=\"{$fontsize}\" color=\"red\">{$char} </font>"; $wrong++; } else { $links .= "\r\n<B><font size=\"{$fontsize}\">{$char} </font></B> "; } } elseif ($char == 'C') { if (game_strpos($word, $char) === false and game_strpos($word, 'Ç') === false) { $links .= "\r\n<font size=\"{$fontsize}\" color=\"red\">{$char} </font>"; $wrong++; } else { $links .= "\r\n<B><font size=\"{$fontsize}\">{$char} </font></B> "; } } elseif (game_strpos($word, $char) === false) { $links .= "\r\n<font size=\"{$fontsize}\" color=\"red\">{$char} </font>"; $wrong++; } else { $links .= "\r\n<B><font size=\"{$fontsize}\">{$char} </font></B> "; } } $finishedword = ($done or $wrong >= $max); $finished = false; $updrec = new stdClass(); $updrec->id = $hangman->id; $updrec->letters = $letters; if ($finishedword) { if ($hangman->finishedword == 0) { // Only one time per word increace the variable try. $hangman->try = $hangman->try + 1; if ($hangman->try > $hangman->maxtries) { $finished = true; } if ($done) { $hangman->corrects = $hangman->corrects + 1; $updrec->corrects = $hangman->corrects; } } $updrec->try = $hangman->try; $updrec->finishedword = 1; } $query->percent = ($correct - $wrong / $max) / game_strlen($word); if ($query->percent < 0) { $query->percent = 0; } if ($onlyshow or $showsolution) { return; } if (!$DB->update_record('game_hangman', $updrec)) { print_error("hangman_showpage: Can't update game_hangman id={$updrec->id}"); } if ($done) { $score = 1; } else { if ($wrong >= $max) { $score = 0; } else { $score = -1; } } game_updateattempts($game, $attempt, $score, $finished); game_update_queries($game, $attempt, $query, $score, $answer); }
function game_sudoku_showquestions_glossary($id, $game, $attempt, $sudoku, $offsetentries, $numbers, $correctentries, $onlyshow, $showsolution) { global $CFG; $entries = game_sudoku_getglossaryentries($game, $offsetentries, $questionlist, $numbers); //I will sort with the number of each question $entries2 = array(); foreach ($entries as $q) { $ofs = $numbers[$q->id]; $entries2[$ofs] = $q; } ksort($entries2); if (count($entries2) == 0) { game_sudoku_showquestion_onfinish($id, $game, $attempt, $sudoku); return; } $number = 0; $found = false; $cmglossary = get_coursemodule_from_instance('glossary', $game->glossaryid, $game->course); $contextglossary = get_context_instance(CONTEXT_MODULE, $cmglossary->id); foreach ($entries2 as $entry) { $ofs = $numbers[$entry->id]; if (array_key_exists($ofs, $correctentries)) { continue; //I don't show the correct answers } if ($found == false) { $found = true; // Start the form echo "<br><form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; if ($onlyshow === false) { echo "<center><input type=\"submit\" name=\"submit\" value=\"" . get_string('sudoku_submit', 'game') . "\"></center>\n"; } // Add a hidden field with the quiz id echo '<div>'; echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; echo '<input type="hidden" name="action" value="sudokucheckg" />'; // Print all the questions // Add a hidden field with questionids echo '<input type="hidden" name="questionids" value="' . $questionlist . "\" />\n"; } $text = game_filterglossary(str_replace('\\"', '"', $entry->definition), $entry->id, $contextglossary->id, $game->course); $s = '<b>A' . $ofs . '.</b> ' . $text . '<br>'; if ($showsolution) { $s .= get_string('answer') . ': '; $s .= "<input type=\"text\" name=\"resp{$entry->id}\" value=\"{$entry->concept}\"size=30 /><br>"; } else { if ($onlyshow === false) { $s .= get_string('answer') . ': '; $s .= "<input type=\"text\" name=\"resp{$entry->id}\" size=30 /><br>"; } } echo $s . "<hr>\r\n"; } if ($found) { echo "</div>"; // Finish the form if ($onlyshow === false) { echo "<center><input type=\"submit\" name=\"submit\" value=\"" . get_string('sudoku_submit', 'game') . "\"></center>\n"; } echo "</form>\n"; } }