コード例 #1
0
 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;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
function game_print_question_shortanswer($game, $question, $context)
{
    $questiontext = $question->questiontext;
    ?>
<div class="qtext">
  <?php 
    echo game_filterquestion(str_replace('\\"', '"', $questiontext), $question->id, $context->id, $game->course);
    ?>
</div>

<div class="ablock clearfix">
  <div class="prompt">
    <?php 
    echo get_string("answer", "quiz") . ': ';
    ?>
  </div>
  <div class="answer">
    <input type="text" name="resp<?php 
    echo $question->id;
    ?>
_" size="80"/>
  </div>
</div>
<?php 
}
コード例 #4
0
ファイル: play.php プロジェクト: vinoth4891/clinique
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 . '<br>';
    }
    echo '<br>';
    $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 = 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->displaycryptex($crossm->cols, $crossm->rows, $cryptexrec->letters, $mask, $showsolution, $textdir);
    ?>
</td>

<td width=10%>&nbsp;</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> &nbsp;
<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) {
        //print_r( $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;
            }
        }
        $question = "{$i}. " . $q->questiontext;
        $question = game_filterquestion(str_replace('\\"', '"', $question), $q->questionid, $context->id, $game->course);
        $question2 = strip_tags($question);
        //ADDED BY DP (AUG 2009) - fixes " breaking the Answer button for this question
        if ($onlyshow == false and $showsolution == false) {
            if ($game->param8 == 0 || $game->param8 > $q->tries) {
                $question .= ' &nbsp;<input type="submit" value="' . get_string('answer') . '" onclick="OnCheck( ' . $q->id . ',\'' . $question2 . '\');" />';
            }
        }
        echo $question;
        if ($showsolution) {
            echo " &nbsp;&nbsp;&nbsp;{$q->answertext}<B></b>";
        }
        echo '<br>';
    }
    if ($game->bottomtext != '') {
        echo '<br><br>' . $game->bottomtext;
    }
    ?>
		<script>
			function OnCheck( id, question)
			{
				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 
}
コード例 #5
0
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;
}
コード例 #6
0
function game_showanswers_question_select($game, $table, $select, $fields, $order, $showcategoryname, $courseid, $context)
{
    global $CFG, $DB, $OUTPUT;
    $sql = "SELECT {$fields} FROM {$table} WHERE {$select} ORDER BY {$order}";
    if (($questions = $DB->get_records_sql($sql)) === false) {
        return;
    }
    $table .= ",{game_repetitions} gr";
    $select .= " AND gr.questionid=q.id AND gr.glossaryentryid=0 AND gr.gameid=" . $game->id;
    $userid = optional_param('userid', 0, PARAM_INT);
    if ($userid) {
        $select .= " AND gr.userid={$userid}";
    }
    $sql = "SELECT q.id as id,SUM(repetitions) as c FROM {$table} WHERE {$select} GROUP BY q.id";
    $reps = $DB->get_records_sql($sql);
    $categorynames = array();
    if ($showcategoryname) {
        $select = '';
        $recs = $DB->get_records('question_categories', null, '', '*', 0, 1);
        foreach ($recs as $rec) {
            if (array_key_exists('course', $rec)) {
                $select = "course={$courseid}";
            } else {
                $context = get_context_instance(50, $courseid);
                $select = " contextid in ({$context->id})";
            }
            break;
        }
        if ($categories = $DB->get_records_select('question_categories', $select, null, '', 'id,name')) {
            foreach ($categories as $rec) {
                $categorynames[$rec->id] = $rec->name;
            }
        }
    }
    echo '<table border="1">';
    echo '<tr><td></td>';
    if ($showcategoryname) {
        echo '<td><b>' . get_string('categories', 'quiz') . '</b></td>';
    }
    echo '<td><b>' . get_string('questions', 'quiz') . '</b></td>';
    echo '<td><b>' . get_string('answers', 'quiz') . '</b></td>';
    echo '<td><b>' . get_string('feedbacks', 'game') . '</b></td>';
    if ($reps) {
        echo '<td><b>' . get_string('repetitions', 'game') . '</b></td>';
    }
    echo "</tr>\r\n";
    $line = 0;
    foreach ($questions as $question) {
        echo '<tr>';
        echo '<td>' . ++$line;
        echo '</td>';
        if ($showcategoryname) {
            echo '<td>';
            if (array_key_exists($question->category, $categorynames)) {
                echo $categorynames[$question->category];
            } else {
                echo '&nbsp;';
            }
            echo '</td>';
        }
        echo '<td>';
        echo "<a title=\"Edit\" " . "href=\"{$CFG->wwwroot}/question/question.php?inpopup=1&amp;id={$question->id}&courseid={$courseid}\" target=\"_blank\">";
        echo "<img src=\"" . $OUTPUT->pix_url('t/edit') . "\" alt=\"Edit\" /></a> ";
        echo game_filterquestion(str_replace(array("\\'", '\\"'), array("'", '"'), $question->questiontext), $question->id, $context->id, $game->course);
        switch ($question->qtype) {
            case 'shortanswer':
                $recs = $DB->get_records('question_answers', array('question' => $question->id), 'fraction DESC', 'id,answer,feedback');
                if ($recs == false) {
                    $rec = false;
                } else {
                    foreach ($recs as $rec) {
                        break;
                    }
                }
                echo "<td>{$rec->answer}</td>";
                if ($rec->feedback == '') {
                    $rec->feedback = '&nbsp;';
                }
                echo "<td>{$rec->feedback}</td>";
                break;
            case 'multichoice':
            case 'truefalse':
                $recs = $DB->get_records('question_answers', array('question' => $question->id));
                $feedback = '';
                echo '<td>';
                $i = 0;
                foreach ($recs as $rec) {
                    if ($i++ > 0) {
                        echo '<br>';
                    }
                    if ($rec->fraction == 1) {
                        echo " <b>{$rec->answer}</b>";
                    } else {
                        echo " {$rec->answer}";
                    }
                    if ($rec->feedback == '') {
                        $feedback .= '<br>';
                    } else {
                        $feedback .= "<b>{$rec->feedback}</b><br>";
                    }
                }
                echo '</td>';
                if ($feedback == '') {
                    $feedback = '&nbsp;';
                }
                echo "<td>{$feedback}</td>";
                break;
            default:
                echo "<td>{$question->qtype}</td>";
                break;
        }
        // Show repetitions.
        if ($reps) {
            if (array_key_exists($question->id, $reps)) {
                $rep = $reps[$question->id];
                echo '<td><center>' . $rep->c . '</td>';
            } else {
                echo '<td>&nbsp;</td>';
            }
        }
        echo "</tr>\r\n";
    }
    echo "</table><br>\r\n\r\n";
}
コード例 #7
0
ファイル: play.php プロジェクト: vinoth4891/clinique
function game_millionaire_showgrid($game, $millionaire, $id, $query, $aAnswer, $info, $context)
{
    global $OUTPUT;
    $question = str_replace('\\"', '"', $query->questiontext);
    if ($game->param8 == '') {
        $color = 408080;
    } else {
        $color = substr('000000' . base_convert($game->param8, 10, 16), -6);
    }
    $color1 = 'black';
    $color2 = 'DarkOrange';
    $colorback = "white";
    $stylequestion = "background:{$colorback};color:{$color1}";
    $stylequestionselected = "background:{$colorback};color:{$color2}";
    global $CFG;
    $state = $millionaire->state;
    $level = $millionaire->level;
    $background = "style='background:#{$color}'";
    echo '<form name="Form1" method="post" action="attempt.php" id="Form1">';
    echo "<table cellpadding=0 cellspacing=0 border=0>\r\n";
    echo "<tr {$background}>";
    echo '<td rowspan=' . (17 + count($aAnswer)) . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
    echo "<td colspan=6>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
    echo '<td rowspan=' . (17 + count($aAnswer)) . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
    echo "</tr>\r\n";
    echo "<tr height=10%>";
    echo "<td {$background} rowspan=3 colspan=2>";
    $dirgif = 'millionaire/1/';
    if ($state & 1) {
        $gif = "5050x";
        $disabled = "disabled=1";
    } else {
        $gif = "5050";
        $disabled = "";
    }
    echo '<input type="image" ' . $disabled . ' name="Help5050" id="Help5050" Title="50 50" src="' . $OUTPUT->pix_url($dirgif . $gif, 'mod_game') . '" alt="" border="0">&nbsp;';
    if ($state & 2) {
        $gif = "telephonex";
        $disabled = "disabled=1";
    } else {
        $gif = "telephone";
        $disabled = "";
    }
    echo '<input type="image" name="HelpTelephone" ' . $disabled . ' id="HelpTelephone" Title="' . get_string('millionaire_telephone', 'game') . '" src="' . $OUTPUT->pix_url($dirgif . $gif, 'mod_game') . '" alt="" border="0">&nbsp;';
    if ($state & 4) {
        $gif = "peoplex";
        $disabled = "disabled=1";
    } else {
        $gif = "people";
        $disabled = "";
    }
    echo '<input type="image" name="HelpPeople" ' . $disabled . ' id="HelpPeople" Title="' . get_string('millionaire_helppeople', 'game') . '" src="' . $OUTPUT->pix_url($dirgif . $gif, 'mod_game') . '" alt="" border="0">&nbsp;';
    echo '<input type="image" name="Quit" id="Quit" Title="' . get_string('millionaire_quit', 'game') . '" src="' . $OUTPUT->pix_url($dirgif . 'x', 'mod_game') . '" alt="" border="0">&nbsp;';
    echo "\r\n";
    echo "</td>\r\n";
    $styletext = "";
    if (strpos($question, 'color:') == false and strpos($question, 'background:') == false) {
        $styletext = "style='{$stylequestion}'";
    }
    $aVal = array(100, 200, 300, 400, 500, 1000, 1500, 2000, 4000, 5000, 10000, 20000, 40000, 80000, 150000);
    for ($i = 15; $i >= 1; $i--) {
        $bTR = false;
        switch ($i) {
            case 15:
                echo "<td rowspan=" . (16 + count($aAnswer)) . " {$background}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\r\n";
                $bTR = true;
                break;
            case 14:
            case 13:
                echo "<tr>\n";
                $bTR = true;
                break;
            case 12:
                $question = game_filterquestion($question, $query->questionid, $context->id, $game->course);
                echo "<tr>";
                echo "<td rowspan=12 colspan=2 valign=top style=\"{$styletext}\">{$question}</td>\r\n";
                $bTR = true;
                break;
            case 11:
            case 10:
            case 9:
            case 8:
            case 7:
            case 6:
            case 5:
            case 4:
            case 3:
            case 2:
            case 1:
                echo "<tr>";
                $bTR = true;
                break;
            default:
                echo "<tr>";
                $bTR = true;
        }
        if ($i == $level + 1) {
            $style = "background:{$color1};color:{$color2}";
        } else {
            $style = $stylequestion;
        }
        echo "<td style='{$style}' align=right>{$i}</td>";
        if ($i < $level + 1) {
            echo "<td style='{$style}'>&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;</td>";
        } else {
            if ($i == 15 and $level <= 1) {
                echo "<td style='{$style}'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
            } else {
                echo "<td style='{$style}'></td>";
            }
        }
        echo "<td style='{$style}' align=right>" . sprintf("%10d", $aVal[$i - 1]) . "</td>\r\n";
        if ($bTR) {
            echo "</tr>\r\n";
        }
    }
    echo "<tr {$background}><td colspan=10>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>\r\n";
    $bFirst = true;
    $letters = get_string('lettersall', 'game');
    for ($i = 1; $i <= count($aAnswer); $i++) {
        $name = "btAnswer" . $i;
        $s = textlib::substr($letters, $i - 1, 1);
        $disabled = $state == 15 ? "disabled=1" : "";
        $style = $stylequestion;
        if (strpos($aAnswer[$i - 1], 'color:') != false or strpos($aAnswer[$i - 1], 'background:') != false) {
            $style = '';
        }
        if ($state == 15 and $i + 1 == $query->correct) {
            $style = $stylequestionselected;
        }
        $button = '<input style="' . $style . '" ' . $disabled . 'type="submit" name="' . $name . '" value="' . $s . '" id="' . $name . "1\"" . " onmouseover=\"this.style.backgroundColor = '{$color2}';{$name}.style.backgroundColor = '{$color2}';\" " . " onmouseout=\"this.style.backgroundColor = '{$colorback}';{$name}.style.backgroundColor = '{$colorback}';\" >";
        $text = game_filtertext($aAnswer[$i - 1], $game->course);
        $answer = "<span id={$name} style=\"{$style}\" " . " onmouseover=\"this.style.backgroundColor = '{$color2}';{$name}1.style.backgroundColor = '{$color2}';\" " . " onmouseout=\"this.style.backgroundColor = '{$colorback}';{$name}1.style.backgroundColor = '{$colorback}';\" >" . $text . '</span>';
        if ($aAnswer[$i - 1] != "") {
            echo "<tr>\n";
            echo "<td style='{$stylequestion}'> {$button}</td>\n";
            echo "<td {$style} width=100%> &nbsp; {$answer}</td>";
            if ($bFirst) {
                $bFirst = false;
                $info = game_filtertext($info, $game->course);
                echo "<td style=\"{$style}\" rowspan=" . count($aAnswer) . " colspan=3>{$info}</td>";
            }
            echo "\r\n</tr>\r\n";
        }
    }
    echo "<tr><td colspan=10 {$background}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>\r\n";
    echo "<input type=hidden name=state value=\"{$state}\">\r\n";
    echo '<input type=hidden name=id value="' . $id . '">';
    echo "<input type=hidden name=buttons value=\"" . count($aAnswer) . "\">\r\n";
    echo "</table>\r\n";
    echo "</form>\r\n";
}
コード例 #8
0
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 == " " ? '&nbsp; ' : $char;
            $done = 0;
        }
        if (game_strpos($letters, $char) === false) {
            $wordline .= "_<font size=\"1\">&nbsp;</font>\r\n";
            $done = 0;
            $answer .= '_';
        } else {
            $wordline .= $char == " " ? '&nbsp; ' : $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 . '&amp;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);
}