Browse Source

Fix:Coding style

MOODLE_20_STABLE
Vasilis Daloukas 9 years ago
parent
commit
b5f11fca18
  1. 81
      lang/en/game.php
  2. 395
      millionaire/play.php
  3. 62
      report/default.php
  4. 242
      report/overview/report.php
  5. 224
      snakes/createboard.php
  6. 175
      snakes/play.php

81
lang/en/game.php

@ -1,31 +1,46 @@
<?php // $Id: game.php,v 1.22 2012/07/26 05:38:59 bdaloukas Exp $
// translated by Vasilis Daloukas
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
//bookquiz/importodt.php
// Translated by Vasilis Daloukas.
// File bookquiz/importodt.php.
$string[ 'bookquiz_import_odt'] = 'Import from an OpenOffice file (odt)';
$string[ 'bookquiz_not_select_book'] = 'You have not select book';
$string[ 'bookquiz_subchapter'] = 'Create subchapters';
//bookquiz/play.php
// File bookquiz/play.php.
$string[ 'bookquiz_empty'] = 'The book is empty';
$string[ 'sudoku_submit'] = 'Grade answers';
//bookquiz/questions.php
// File bookquiz/questions.php.
$string[ 'bookquiz_categories'] = 'Categories';
$string[ 'bookquiz_chapters'] = 'Chapters';
$string[ 'bookquiz_numquestions'] = 'Questions';
//classes
// Classes.
$string[ 'eventgamecreated'] = 'Game created';
$string[ 'eventgamedeleted'] = 'Game deleted';
$string[ 'eventgamesupdated'] = 'Game updated';
$string[ 'eventgameviewed'] = 'Game viewed';
$string[ 'eventgameplayed'] = 'Game played';
//cross/cross_class.php
// File cross/cross_class.php.
$string[ 'lettersall'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
//cross/crossdb_class.php
// File cross/crossdb_class.php.
$string[ 'and'] = 'and';
$string[ 'cross_correct'] = 'corrert character';
$string[ 'cross_corrects'] = 'correct characters';
@ -36,7 +51,7 @@ $string[ 'cross_found_one'] = 'Found';
$string[ 'grade'] = 'Grade';
$string[ 'cross_disabletransformuppercase'] = 'Disables text-transform:uppercase in CSS';
//cross/play.php
// File cross/play.php.
$string[ 'cross_across'] = 'Across';
$string[ 'cross_checkbutton'] = 'Check crossword';
$string[ 'cross_down'] = 'Down';
@ -53,10 +68,10 @@ $string[ 'no_words'] = 'There are no words';
$string[ 'print'] = 'Print';
$string[ 'win'] = 'Congratulations !!!';
//cryptex/play.php
// File cryptex/play.php.
$string[ 'finish'] = 'End of game';
//db/access.php
// File db/access.php.
$string[ 'game:attempt'] = 'Play game';
$string[ 'game:deleteattempts'] = 'Delete attempts';
$string[ 'game:grade'] = 'Grade games manually';
@ -67,7 +82,7 @@ $string[ 'game:reviewmyattempts'] = 'reviewmyattempts';
$string[ 'game:view'] = 'view';
$string[ 'game:viewreports'] = 'viewreports';
//hangman/play.php
// File hangman/play.php.
$string[ 'hangman_correct_phrase'] = 'The correct phrase was: ';
$string[ 'hangman_correct_word'] = 'The correct word was: ';
$string[ 'hangman_gradeinstance'] = 'Grade in whole game';
@ -77,7 +92,7 @@ $string[ 'hangman_restletters_one'] = 'You have <b>ONLY 1</b> try';
$string[ 'hangman_wrongnum'] = 'Wrong: %d out of %d';
$string[ 'nextword'] = 'Next word';
//hiddenpicture/play.php
// File hiddenpicture/play.php.
$string[ 'hiddenpicture_mainsubmit'] = 'Grade main answer';
$string[ 'hiddenpicture_nocols'] = 'Have to specify the number of cols horizontaly';
$string[ 'hiddenpicture_nomainquestion'] = 'There are no glossary entries on glossary {$a->name} with an attached picture';
@ -86,11 +101,11 @@ $string[ 'must_select_glossary'] = 'You must select a glossary';
$string[ 'no_questions'] = "There are no questions";
$string[ 'noglossaryentriesfound'] = 'No glossary entries found';
//millionaire/play.php
// File millionaire/play.php.
$string[ 'millionaire_must_select_questioncategory'] = 'You must select one question category';
$string[ 'millionaire_must_select_quiz'] = 'You must select one quiz';
//report/overview/report.php
// File report/overview/report.php.
$string[ 'allattempts'] = 'Show all tries';
$string[ 'allstudents'] = 'Show all $a';
$string[ 'attemptduration'] = 'Attempt duration';
@ -111,21 +126,21 @@ $string[ 'timecompleted'] = 'Completed';
$string[ 'unfinished'] = 'open';
$string[ 'withselected'] = 'With selected';
//snakes/play.php
// File snakes/play.php.
$string[ 'snakes_dice'] = 'Dice, $a spots.';
$string[ 'snakes_player'] = 'Player, position: $a.';
//sudoku/create.php
// File sudoku/create.php.
$string[ 'sudoku_create_count'] = 'Number of sudokus that will be created';
$string[ 'sudoku_create_start'] = 'Start creating sudokus';
$string[ 'sudoku_creating'] = 'Creating <b>{$a}</b> sudoku';
//sudoku/play.php
// File sudoku/play.php.
$string[ 'sudoku_finishattemptbutton'] = 'End of game';
$string[ 'sudoku_guessnumber'] = 'Guess the correct number';
$string[ 'sudoku_noentriesfound'] = 'No words found in glossary';
//export.php
// File export.php.
$string[ 'export'] = 'Export';
$string[ 'html_hascheckbutton'] = 'Has check button:';
$string[ 'html_hasprintbutton'] = 'Has print button:';
@ -141,11 +156,11 @@ $string[ 'javame_type'] = 'Type:';
$string[ 'javame_vendor'] = 'Vendor:';
$string[ 'javame_version'] = 'Version:';
//exporthtml_hangman.php
// File exporthtml_hangman.php.
$string[ 'hangman_loose'] = '<BIG><B>Game over</B></BIG>';
$string[ 'html_hangman_new'] = 'New';
//exporthtml_millionaire.php
// File exporthtml_millionaire.php.
$string[ 'millionaire_helppeople'] = 'Help of people';
$string[ 'millionaire_info_people'] = 'People say';
$string[ 'millionaire_info_telephone'] = 'I think that the correct answer is ';
@ -156,14 +171,14 @@ $string[ 'millionaire_telephone'] = 'Help of telephone';
$string[ 'must_select_questioncategory'] = 'You must select a question category';
$string[ 'must_select_quiz'] = 'You must select a quiz';
//exporthtml_snakes.php
// File exporthtml_snakes.php.
$string[ 'html_snakes_check'] = 'Check';
$string[ 'html_snakes_correct'] = 'Correct!';
$string[ 'html_snakes_no_selection'] = 'Have to select something!';
$string[ 'html_snakes_wrong'] = "Your answer isn't correct. Stay on the same seat.";
$string[ 'score'] = 'Score';
//index.php
// File index.php.
$string[ 'helpbookquiz'] = 'When the student answers correct can go to the next chapter.';
$string[ 'helpcross'] = 'This game takes words from either a Glossary or quiz short answer questions and generates a random crossword puzzle. Teacher can set the maximum number of columns/rows or words that contains. Student can press the button “Check crossword” to check if the answers are correct. Every crossword is dynamic so it is different to every student.';
$string[ 'helpcryptex'] = 'This game is like a crossword but the answers are hidden inside a random cryptex.';
@ -178,7 +193,7 @@ $string[ 'modulenameplural'] = 'Games';
$string[ 'pluginadministration'] = 'Game administration';
$string[ 'pluginname'] = 'Game';
//lib.php
// File lib.php.
$string[ 'attempt'] = 'Attempt';
$string[ 'bookquiz_questions'] = 'Associate question categories to chapter of book';
$string[ 'export_to_html'] = 'Export to HTML';
@ -200,7 +215,7 @@ $string[ 'results'] = 'Results';
$string[ 'showanswers'] = 'Show answers';
$string[ 'showattempts'] = 'Show attempts';
//locallib.php
// File locallib.php.
$string[ 'attemptfirst'] = 'First attempt';
$string[ 'attemptlast'] = 'Last attempt';
$string[ 'convertfrom'] = '-';
@ -208,7 +223,7 @@ $string[ 'convertto'] = '-';
$string[ 'gradeaverage'] = 'Average grade';
$string[ 'gradehighest'] = 'Highest grade';
//mod_form.php
// File mod_form.php.
$string[ 'bookquiz_layout'] = 'Layout';
$string[ 'bookquiz_layout0'] = 'Question at the top of the book';
$string[ 'bookquiz_layout1'] = 'Question at the bottom of the book';
@ -276,11 +291,11 @@ $string[ 'sudoku_options'] = 'Sudoku options';
$string[ 'toptext'] = 'Text at the top of page';
$string[ 'userdefined'] = 'User defined';
//preview.php
// File preview.php.
$string[ 'only_teachers'] = 'Only teacher can see this page';
$string[ 'preview'] = 'Preview';
//review.php
// File review.php.
$string[ 'attempts'] = 'Attempts';
$string[ 'completedon'] = 'Completed on';
$string[ 'outof'] = '{$a->grade} out of a maximum of {$a->maxgrade}';
@ -290,7 +305,7 @@ $string[ 'showall'] = 'Show all';
$string[ 'startagain'] = 'Start again';
$string[ 'timetaken'] = 'Time taken';
//settings.php
// File settings.php.
$string[ 'hangmanimagesets'] = 'Number of image sets used by hangman';
$string[ 'hidebookquiz'] = 'Hide the "Book with questions" game';
$string[ 'hidecross'] = 'Hide the Crossword game';
@ -310,22 +325,22 @@ $string[ 'confighidemillionaire'] = 'Configs if the Millionaire game is shown to
$string[ 'confighidesnakes'] = 'Configs if the "Snakes and Ladders" game is shown to teachers or not';
$string[ 'confighidesudoku'] = 'Configs if the Sudoku game is shown to teachers or not';
//showanswers.php
// File showanswers.php.
$string[ 'clearrepetitions'] = 'Clear statistics';
$string[ 'computerepetitions'] = 'Compute statistics again';
$string[ 'feedbacks'] = 'Messages correct answer';
$string[ 'repetitions'] = 'Repetitions';
//showattempts.php
// File showattempts.php.
$string[ 'lastip'] = 'IP student';
$string[ 'showsolution'] = 'solution';
$string[ 'timefinish'] = 'End of game';
$string[ 'timelastattempt'] = 'Last attempt';
$string[ 'timestart'] = 'Start';
//tabs.php
// File tabs.php.
//view.php
// File view.php.
$string[ 'attemptgamenow'] = 'Attempt game now';
$string[ 'comment'] = 'Comment';
$string[ 'continueattemptgame'] = 'Continue a previous attempt of game';

395
millionaire/play.php

@ -1,4 +1,19 @@
<?php // $Id: play.php,v 1.31 2012/07/25 11:16:05 bdaloukas Exp $
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file plays the game millionaire
*
@ -7,18 +22,18 @@
* @package game
**/
function game_millionaire_continue( $id, $game, $attempt, $millionaire, $context)
{
//User must select quiz or question as a source module
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')
if ($game->sourcemodule == 'quiz') {
print_error( get_string( 'millionaire_must_select_quiz', 'game'));
else
} else {
print_error( get_string( 'millionaire_must_select_questioncategory', 'game'));
}
}
if ($attempt != false and $millionaire != false) {
//continue an existing game
// Continue an existing game.
return game_millionaire_play( $id, $game, $attempt, $millionaire, $context);
}
@ -39,21 +54,18 @@ function game_millionaire_continue( $id, $game, $attempt, $millionaire, $context
game_millionaire_play( $id, $game, $attempt, $newrec, $context);
}
function game_millionaire_play( $id, $game, $attempt, $millionaire, $context)
{
function game_millionaire_play( $id, $game, $attempt, $millionaire, $context) {
global $DB;
$buttons = optional_param('buttons', 0, PARAM_INT);
$Help5050_x = optional_param('Help5050_x', 0, PARAM_INT);
$HelpTelephone_x = optional_param('HelpTelephone_x', 0, PARAM_INT);
$HelpPeople_x = optional_param('HelpPeople_x', 0, PARAM_INT);
$Quit_x = optional_param('Quit_x', 0, PARAM_INT);
$help5050x = optional_param('Help5050_x', 0, PARAM_INT);
$helptelephonex = optional_param('HelpTelephone_x', 0, PARAM_INT);
$helppeoplex = optional_param('HelpPeople_x', 0, PARAM_INT);
$quitx = optional_param('Quit_x', 0, PARAM_INT);
if ($millionaire->queryid) {
$query = $DB->get_record( 'game_queries', array( 'id' => $millionaire->queryid));
}else
{
} else {
$query = new StdClass;
}
@ -67,31 +79,31 @@ function game_millionaire_play( $id, $game, $attempt, $millionaire, $context)
}
}
if( $found == 1)
;//nothing
else if( !empty($Help5050_x))
if ($found == 1) {
$found = $found; // Nothing.
} else if (!empty($help5050x)) {
game_millionaire_OnHelp5050( $game, $id, $millionaire, $game, $query, $context);
else if( !empty($HelpTelephone_x))
} else if (!empty($helptelephonex)) {
game_millionaire_OnHelpTelephone( $game, $id, $millionaire, $query, $context);
else if( !empty($HelpPeople_x))
} else if (!empty($helppeoplex)) {
game_millionaire_OnHelpPeople( $game, $id, $millionaire, $query, $context);
else if( !empty($Quit_x))
} else if (!empty($quitx)) {
game_millionaire_OnQuit( $id, $game, $attempt, $query, $context);
else
} else {
game_millionaire_ShowNextQuestion( $id, $game, $attempt, $millionaire, $context);
}
}
function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer, $info, $context)
{
global $OUTPUT;
function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, $info, $context) {
global $CFG, $OUTPUT;
$question = str_replace( array("\'", '\"'), array("'", '"'), $query->questiontext);
if( $game->param8 == '')
if ($game->param8 == '') {
$color = 408080;
else
} else {
$color = substr( '000000'.base_convert($game->param8, 10, 16), -6);
}
$color1 = 'black';
$color2 = 'DarkOrange';
@ -99,8 +111,6 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer,
$stylequestion = "background:$colorback;color:$color1";
$stylequestionselected = "background:$colorback;color:$color2";
global $CFG;
$state = $millionaire->state;
$level = $millionaire->level;
@ -109,49 +119,51 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer,
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 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 '<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)
{
if ($state & 1) {
$gif = "5050x";
$disabled = "disabled=1";
}else
{
} 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;';
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)
{
if ($state & 2) {
$gif = "telephonex";
$disabled = "disabled=1";
}else
{
} 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)
{
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
{
} 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="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 '<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";
@ -160,27 +172,26 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer,
$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)
{
$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;
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;
$btr = true;
break;
case 12:
//$question = game_filterquestion($question, $query->questionid, $context->id, $game->course);
$question = game_show_query( $game, $query, $question);
echo "<tr>";
echo "<td rowspan=12 colspan=2 valign=top style=\"$styletext\">$question</td>\r\n";
$bTR = true;
$btr = true;
break;
case 11:
case 10:
@ -194,42 +205,45 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer,
case 2:
case 1:
echo "<tr>";
$bTR = true;
$btr = true;
break;
default:
echo "<tr>";
$bTR = true;
$btr = true;
}
if( $i == $level+1)
if ($i == $level + 1) {
$style = "background:$color1;color:$color2";
else
} else {
$style = $stylequestion;
}
echo "<td style='$style' align=right>$i</td>";
if( $i < $level+1)
if ($i < $level + 1) {
echo "<td style='$style'>&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;</td>";
else if( $i == 15 and $level <= 1)
} else if ($i == 15 and $level <= 1) {
echo "<td style='$style'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
else
} else {
echo "<td style='$style'></td>";
echo "<td style='$style' align=right>".sprintf( "%10d", $aVal[ $i-1])."</td>\r\n";
if( $bTR)
}
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;
$bfirst = true;
$letters = get_string( 'lettersall', 'game');
for( $i=1; $i <= count( $aAnswer); $i++)
{
for ($i = 1; $i <= count( $aanswer); $i++) {
$name = "btAnswer".$i;
$s = game_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)){
if ((strpos( $aanswer[ $i - 1], 'color:') != false) or (strpos( $aanswer[ $i - 1], 'background:') != false)) {
$style = '';
}
if ($state == 15 and $i + 1 == $query->correct) {
@ -239,20 +253,20 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer,
$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);
$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] != ""){
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;
if ($bfirst) {
$bfirst = false;
$info = game_filtertext($info, $game->course);
echo "<td style=\"$style\" rowspan=".count( $aAnswer)." colspan=3>$info</td>";
echo "<td style=\"$style\" rowspan=".count( $aanswer)." colspan=3>$info</td>";
}
echo "\r\n</tr>\r\n";
}
@ -260,38 +274,37 @@ function game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer,
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 "<input type=hidden name=buttons value=\"".count( $aanswer)."\">\r\n";
echo "</table>\r\n";
echo "</form>\r\n";
}
function game_millionaire_ShowNextQuestion( $id, $game, $attempt, $millionaire, $context)
{
game_millionaire_SelectQuestion( $aAnswer, $game, $attempt, $millionaire, $query, $context);
function game_millionaire_shownextquestion( $id, $game, $attempt, $millionaire, $context) {
game_millionaire_selectquestion( $aanswer, $game, $attempt, $millionaire, $query, $context);
if ($game->toptext != '') {
echo $game->toptext.'<br><br>';
}
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, "", $context);
game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, "", $context);
if ($game->bottomtext != '') {
echo '<br>'.$game->bottomtext;
}
}
//updates tables: games_millionaire, game_attempts, game_questions
function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$millionaire, &$query, $context)
{
// Updates tables: games_millionaire, game_attempts, game_questions.
function game_millionaire_selectquestion( &$aanswer, $game, $attempt, &$millionaire, &$query, $context) {
global $DB, $USER;
if (($game->sourcemodule != 'quiz') and ($game->sourcemodule != 'question')) {
print_error( get_string('millionaire_sourcemodule_must_quiz_question', 'game', get_string( 'modulename', 'quiz')).' '.get_string( 'modulename', $attempt->sourcemodule));
print_error( get_string('millionaire_sourcemodule_must_quiz_question', 'game',
get_string( 'modulename', 'quiz')).' '.get_string( 'modulename', $attempt->sourcemodule));
}
if ($millionaire->queryid != 0) {
game_millionaire_loadquestions( $game, $millionaire, $query, $aAnswer, $context);
game_millionaire_loadquestions( $game, $millionaire, $query, $aanswer, $context);
return;
}
@ -299,26 +312,23 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
if ($game->quizid == 0) {
print_error( get_string( 'must_select_quiz', 'game'));
}
if( game_get_moodle_version() < '02.07')
{
if (game_get_moodle_version() < '02.07') {
$select = "qtype='multichoice' AND quiz='$game->quizid' AND qmo.questionid=q.id".
" AND qqi.question=q.id";
$table = "{quiz_question_instances} qqi,{question} q, {qtype_multichoice_options} qmo";
$order = '';
}else
{
} else {
$select = "qtype='multichoice' AND qs.quizid='$game->quizid' AND qmo.questionid=q.id".
" AND qs.questionid=q.id";
$table = "{quiz_slots} qs,{question} q, {qtype_multichoice_options} qmo";
$order = 'qs.page,qs.slot';
}
}else
{
} else {
if ($game->questioncategoryid == 0) {
print_error( get_string( 'must_select_questioncategory', 'game'));
}
//include subcategories
// Include subcategories.
$select = 'category='.$game->questioncategoryid;
if ($game->subcategories) {
$cats = question_categorylist( $game->questioncategoryid);
@ -331,10 +341,11 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
$table = '{question} q, {qtype_multichoice_options} qmo';
}
$select .= ' AND hidden=0';
if( $game->shuffle or $game->quizid == 0)
if ($game->shuffle or $game->quizid == 0) {
$questionid = game_question_selectrandom( $game, $table, $select, 'q.id as id', true);
else
} else {
$questionid = game_millionaire_select_serial_question( $game, $table, $select, 'q.id as id', $millionaire->level, $order);
}
if ($questionid == 0) {
print_error( get_string( 'no_questions', 'game'));
@ -351,7 +362,7 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
$correct = 0;
$ids = array();
foreach ($recs as $rec) {
$aAnswer[] = game_filterquestion_answer(str_replace( '\"', '"', $rec->answer), $rec->id, $context->id, $game->course);
$aanswer[] = game_filterquestion_answer(str_replace( '\"', '"', $rec->answer), $rec->id, $context->id, $game->course);
$ids[] = $rec->id;
if ($rec->fraction == 1) {
@ -359,12 +370,12 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
}
}
$count = count( $aAnswer);
$count = count( $aanswer);
for ($i = 1; $i <= $count; $i++) {
$sel = mt_rand(0, $count - 1);
$temp = array_splice( $aAnswer, $sel, 1);
$aAnswer[ ] = $temp[ 0];
$temp = array_splice( $aanswer, $sel, 1);
$aanswer[ ] = $temp[ 0];
$temp = array_splice( $ids, $sel, 1);
$ids[ ] = $temp[ 0];
@ -382,7 +393,6 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
$query->answertext = implode( ',', $ids);
$query->correct = array_search( $correct, $ids) + 1;
if (!$query->id = $DB->insert_record( 'game_queries', $query)) {
print_object( $query);
print_error( 'error inserting to game_queries');
}
@ -399,51 +409,53 @@ function game_millionaire_SelectQuestion( &$aAnswer, $game, $attempt, &$milliona
game_update_queries( $game, $attempt, $query, $score, '');
}
function game_millionaire_select_serial_question( $game, $table, $select, $id_fields="id", $level, $order)
{
function game_millionaire_select_serial_question( $game, $table, $select, $idfields = "id", $level, $order) {
global $DB, $USER;
$sql = "SELECT $id_fields,$id_fields FROM ".$table." WHERE $select ";
if( $order != '')
$sql = "SELECT $idfields,$id_fields FROM ".$table." WHERE $select ";
if ($order != '') {
$sql .= " ORDER BY $order";
}
if( ($recs = $DB->get_records_sql( $sql)) == false)
if (($recs = $DB->get_records_sql( $sql)) == false) {
return false;
}
$questions = array();
foreach( $recs as $rec)
foreach ($recs as $rec) {
$questions[] = $rec->id;
}
$count = count( $questions);
if( $count == 0)
if ($count == 0) {
return false;
}
$from = round($level * ($count - 1) / 15);
$to = round(max( $from, ($level + 1) * ($count - 1) / 15)) - 1;
if( $to < $from)
if ($to < $from) {
$to = $from;
}
$pos = mt_rand( round( $from), round( $to));
return $questions[ $pos];
}
function game_millionaire_loadquestions( $game, $millionaire, &$query, &$aAnswer, $context)
{
function game_millionaire_loadquestions( $game, $millionaire, &$query, &$aanswer, $context) {
global $DB;
$query = $DB->get_record( 'game_queries', array( 'id' => $millionaire->queryid), 'id,questiontext,answertext,correct,questionid');
$query = $DB->get_record( 'game_queries', array( 'id' => $millionaire->queryid),
'id,questiontext,answertext,correct,questionid');
$aids = explode( ',', $query->answertext);
$aAnswer = array();
foreach( $aids as $id)
{
$aanswer = array();
foreach ($aids as $id) {
$rec = $DB->get_record( 'question_answers', array( 'id' => $id), 'id,answer');
$aAnswer[] = game_filterquestion_answer(str_replace( '\"', '"', $rec->answer), $id, $context->id, $game->course);
$aanswer[] = game_filterquestion_answer(str_replace( '\"', '"', $rec->answer), $id, $context->id, $game->course);
}
}
//flag 1:5050, 2:telephone 4:people
function game_millionaire_setstate( &$millionaire, $mask)
{
// Flag 1:5050, 2:telephone 4:people.
function game_millionaire_setstate( &$millionaire, $mask) {
global $DB;
$millionaire->state |= $mask;
@ -456,133 +468,119 @@ function game_millionaire_setstate( &$millionaire, $mask)
}
}
function game_millionaire_onhelp5050( $game, $id, &$millionaire, $query, $context) {
game_millionaire_loadquestions( $game, $millionaire, $query, $aanswer, $context);
function game_millionaire_onhelp5050( $game, $id, &$millionaire, $query, $context)
{
game_millionaire_loadquestions( $game, $millionaire, $query, $aAnswer, $context);
if( ($millionaire->state & 1) != 0)
{
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, '', $context);
if (($millionaire->state & 1) != 0) {
game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, '', $context);
return;
}
game_millionaire_setstate( $millionaire, 1);
$n = count( $aAnswer);
if( $n > 2)
{
for(;;)
{
$n = count( $aanswer);
if ($n > 2) {
for (;;) {
$wrong = mt_rand( 1, $n);
if ($wrong != $query->correct) {
break;
}
}
for( $i=1; $i <= $n; $i++)
{
for ($i = 1; $i <= $n; $i++) {
if ($i <> $wrong and $i <> $query->correct) {
$aAnswer[ $i-1] = "";
$aanswer[ $i - 1] = "";
}
}
}
game_millionaire_showgrid( $game, $millionaire, $id, $query, $aAnswer, '', $context);
game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, '', $context);
}
function game_millionaire_OnHelpTelephone( $game, $id, &$millionaire, $query, $context)
{
game_millionaire_loadquestions( $game, $millionaire, $query, $aAnswer, $context);
function game_millionaire_onhelptelephone( $game, $id, &$millionaire, $query, $context) {
game_millionaire_loadquestions( $game, $millionaire, $query, $aanswer, $context);
if( ($millionaire->state & 2) != 0)
{
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, '', $context);
if (($millionaire->state & 2) != 0) {
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aanswer, '', $context);
return;
}
game_millionaire_setstate( $millionaire, 2);
$n = count( $aAnswer);
$n = count( $aanswer);
if ($n < 2) {
$wrong = $query->correct;
}else
{
for(;;)
{
} else {
for (;;) {
$wrong = mt_rand( 1, $n);
if( $wrong != $query->correct)
if ($wrong != $query->correct) {
break;
}
}
//with 80% gives the correct answer
if( mt_rand( 1, 10) <= 8)
}
// With 80% gives the correct answer.
if (mt_rand( 1, 10) <= 8) {
$response = $query->correct;
else
} else {
$response = $wrong;
}
$info = get_string( 'millionaire_info_telephone','game').'<br><b>'.$aAnswer[ $response-1].'</b>';
$info = get_string( 'millionaire_info_telephone', 'game').'<br><b>'.$aanswer[ $response - 1].'</b>';
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, $info, $context);
game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, $info, $context);
}
function game_millionaire_OnHelpPeople( $game, $id, &$millionaire, $query, $context)
{
game_millionaire_loadquestions( $game, $millionaire, $query, $aAnswer, $context);
function game_millionaire_onhelppeople( $game, $id, &$millionaire, $query, $context) {
game_millionaire_loadquestions( $game, $millionaire, $query, $aanswer, $context);
if (($millionaire->state & 4) != 0) {
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, '', $context);
game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, '', $context);
return;
}
game_millionaire_setstate( $millionaire, 4);
$n = count( $aAnswer);
$n = count( $aanswer);
$sum = 0;
$aPercent = array();
for( $i = 0; $i+1 < $n; $i++)
{
$apercent = array();
for ($i = 0; $i + 1 < $n; $i++) {
$percent = mt_rand( 0, 100 - $sum);
$aPercent[ $i] = $percent;
$apercent[ $i] = $percent;
$sum += $percent;
}
$aPercent[ $n-1] = 100 - $sum;
if( mt_rand( 1, 100) <= 80)
{
//with percent 80% sets in the correct answer the biggest percent
$max_pos = 0;
for( $i=1; $i+1 < $n; $i++)
{
if( $aPercent[ $i] >= $aPercent[ $max_pos])
$max_pos = $i;
$apercent[ $n - 1] = 100 - $sum;
if (mt_rand( 1, 100) <= 80) {
// With percent 80% sets in the correct answer the biggest percent.
$maxpos = 0;
for ($i = 1; $i + 1 < $n; $i++) {
if ($apercent[ $i] >= $apercent[ $maxpos]) {
$maxpos = $i;
}
$temp = $apercent[ $maxpos];
$apercent[ $maxpos] = $apercent[ $query->correct - 1];
$apercent[ $query->correct - 1] = $temp;
}
$temp = $aPercent[ $max_pos];
$aPercent[ $max_pos] = $aPercent[ $query->correct-1];
$aPercent[ $query->correct-1] = $temp;
}
$info = '<br>'.get_string( 'millionaire_info_people', 'game').':<br>';
for ($i = 0; $i < $n; $i++) {
$info .= "<br>". game_substr( get_string( 'lettersall', 'game'), $i, 1) ." : ".$aPercent[ $i]. ' %';
$info .= "<br>". game_substr( get_string( 'lettersall', 'game'), $i, 1) ." : ".$apercent[ $i]. ' %';
}
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, game_substr( $info, 4), $context);
game_millionaire_showgrid( $game, $millionaire, $id, $query, $aanswer, game_substr( $info, 4), $context);
}
function game_millionaire_OnAnswer( $id, $game, $attempt, &$millionaire, $query, $answer, $context)
{
function game_millionaire_onanswer( $id, $game, $attempt, &$millionaire, $query, $answer, $context) {
global $DB;
game_millionaire_loadquestions( $game, $millionaire, $query, $aAnswer, $context);
if( $answer == $query->correct)
{
game_millionaire_loadquestions( $game, $millionaire, $query, $aanswer, $context);
if ($answer == $query->correct) {
if ($millionaire->level < 15) {
$millionaire->level++;
}
$finish = ($millionaire->level == 15 ? 1 : 0);
$scorequestion = 1;
}else
{
} else {
$finish = 1;
$scorequestion = 0;
}
@ -600,31 +598,26 @@ function game_millionaire_onhelp5050( $game, $id, &$millionaire, $query, $conte
print_error( 'error updating in game_millionaire');
}
if( $answer == $query->correct)
{
//correct
if ($answer == $query->correct) {
// Correct.
if ($finish) {
echo get_string( 'win', 'game');
game_millionaire_OnQuit( $id, $game, $attempt, $query);
}else
{
$millionaire->queryid = 0; //so the next function select a new question
game_millionaire_ShowNextQuestion( $id, $game, $attempt, $millionaire, $context);
} else {
$millionaire->queryid = 0; // So the next function select a new question.
}
}else
{
//wrong answer
game_millionaire_ShowNextQuestion( $id, $game, $attempt, $millionaire, $context);
} else {
// Wrong answer.
$info = get_string( 'millionaire_info_wrong_answer', 'game').
'<br><br><b><center>'.$aAnswer[ $query->correct-1].'</b>';
'<br><br><b><center>'.$aanswer[ $query->correct - 1].'</b>';
$millionaire->state = 15;
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aAnswer, $info, $context);
game_millionaire_ShowGrid( $game, $millionaire, $id, $query, $aanswer, $info, $context);
}
}
function game_millionaire_onquit( $id, $game, $attempt, $query)
{
function game_millionaire_onquit( $id, $game, $attempt, $query) {
global $CFG, $DB;
game_updateattempts( $game, $attempt, -1, true);
@ -634,7 +627,7 @@ function game_millionaire_onhelp5050( $game, $id, &$millionaire, $query, $conte
}
echo '<br>';
echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id=$id\">".get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id=$id\">".
get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
echo "<a href=\"{$CFG->wwwroot}/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> ';
}

62
report/default.php

@ -1,33 +1,49 @@
<?php // $Id: default.php,v 1.2 2012/07/25 11:16:07 bdaloukas Exp $
////////////////////////////////////////////////////////////////////
/// Default class for report plugins
///
/// Doesn't do anything on it's own -- it needs to be extended.
/// This class displays quiz reports. Because it is called from
/// within /mod/game/report.php you can assume that the page header
/// and footer are taken care of.
///
/// This file can refer to itself as report.php to pass variables
/// to itself - all these will also be globally available. You must
/// pass "id=$cm->id" or q=$quiz->id", and "mode=reportname".
////////////////////////////////////////////////////////////////////
// Included by ../report.php
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/*
* Default class for report plugins
*
* Doesn't do anything on it's own -- it needs to be extended.
* This class displays quiz reports. Because it is called from
* within /mod/game/report.php you can assume that the page header
* and footer are taken care of.
*
* This file can refer to itself as report.php to pass variables
* to itself - all these will also be globally available. You must
* pass "id=$cm->id" or q=$quiz->id", and "mode=reportname".
*/
// Included by ../report.php.
class game_default_report {
function display($cm, $course, $game) { /// This function just displays the report
public function display($cm, $course, $game) {
// This function just displays the report.
return true;
}
function print_header_and_tabs($cm, $course, $game, $reportmode="overview", $meta=""){
public function print_header_and_tabs($cm, $course, $game, $reportmode = "overview", $meta = "") {
global $CFG;
/// Define some strings
// Define some strings.
$strgames = get_string("modulenameplural", "game");
$strgame = get_string("modulename", "game");
/// Print the page header
// Print the page header.
if (function_exists( 'build_navigation')) {
$navigation = build_navigation('', $cm);
echo $OUTPUT->heading( $course->shortname, $course->shortname, $navigation);
@ -38,12 +54,10 @@ class game_default_report {
'', $meta, true, update_module_button($cm->id, $course->id, $strgame), navmenu($course, $cm));
}
/// Print the tabs
// Print the tabs.
$currenttab = 'reports';
$mode = $reportmode;
include('tabs.php');
require('tabs.php');
}
}
?>

242
report/overview/report.php

@ -1,4 +1,19 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This script lists student attempts
*
@ -15,24 +30,24 @@ class game_report extends game_default_report {
/**
* Display the report.
*/
function display($game, $cm, $course) {
public function display($game, $cm, $course) {
global $CFG, $SESSION, $db, $QTYPES;
// Define some strings
// Define some strings.
$strreallydel = addslashes(get_string('deleteattemptcheck', 'game'));
$strtimeformat = get_string('strftimedatetime');
$strreviewquestion = get_string('reviewresponse', 'quiz');
// Only print headers if not asked to download data
if (!$download = optional_param('download', NULL)) {
// Only print headers if not asked to download data.
if (!$download = optional_param('download', null)) {
$this->print_header_and_tabs($cm, $course, $game, $reportmode = "overview");
}
// Deal with actions
// Deal with actions.
$action = optional_param('action', '', PARAM_ACTION);
switch ($action) {
case 'delete': // Some attempts need to be deleted
case 'delete': // Some attempts need to be deleted.
$attemptids = optional_param('attemptid', array(), PARAM_INT);
foreach ($attemptids as $attemptid) {
@ -41,8 +56,8 @@ class game_report extends game_default_report {
delete_records('game_queries', 'attemptid', $attemptid);
// Search game_attempts for other instances by this user.
// If none, then delete record for this game, this user from game_grades
// else recalculate best grade
// If none, then delete record for this game, this user from game_grades.
// else recalculate best grade.
$userid = $todelete->userid;
if (!record_exists('game_attempts', 'userid', $userid, 'gameid', $game->id)) {
@ -55,12 +70,14 @@ class game_report extends game_default_report {
break;
}
// Print information on the number of existing attempts
if (!$download) { //do not print notices when downloading
// Print information on the number of existing attempts.
if (!$download) {
// Do not print notices when downloading.
if ($attemptnum = count_records('game_attempts', 'gameid', $game->id)) {
$a = new stdClass;
$a->attemptnum = $attemptnum;
$a->studentnum = count_records_select('game_attempts', "gameid = '$game->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
$a->studentnum = count_records_select('game_attempts',
"gameid = '$game->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
$a->studentstring = $course->students;
notify( get_string('numattempts', 'game', $a));
@ -68,8 +85,8 @@ class game_report extends game_default_report {
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// find out current groups mode
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
// Find out current groups mode.
if ($groupmode = groupmode($course, $cm)) { // Groups are being used.
if (!$download) {
$currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id&amp;mode=overview");
} else {
@ -79,7 +96,7 @@ class game_report extends game_default_report {
$currentgroup = get_and_set_current_group($course, $groupmode);
}
// Set table options
// Set table options.
$noattempts = optional_param('noattempts', 0, PARAM_INT);
$detailedmarks = optional_param('detailedmarks', 0, PARAM_INT);
$pagesize = optional_param('pagesize', 10, PARAM_INT);
@ -88,15 +105,16 @@ class game_report extends game_default_report {
$pagesize = 10;
}
// Now check if asked download of data
// Now check if asked download of data.
if ($download) {
$filename = clean_filename("$course->shortname ".format_string($game->name, true));
$sort = '';
}
// Define table columns
// Define table columns.
$tablecolumns = array('checkbox', 'picture', 'fullname', 'timestart', 'timefinish', 'duration');
$tableheaders = array(NULL, '', get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted','game'), get_string('attemptduration', 'game'));
$tableheaders = array(null, '', get_string('fullname'), get_string('startedon', 'game'),
get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
if ($game->grade) {
$tablecolumns[] = 'grade';
@ -104,8 +122,8 @@ class game_report extends game_default_report {
}
if ($detailedmarks) {
// we want to display marks for all questions
// Start by getting all questions
// We want to display marks for all questions.
// Start by getting all questions.
$questionlist = game_questions_in_game( $game->questions);
$questionids = explode(',', $questionlist);
$sql = "SELECT q.*, i.score AS maxgrade, i.id AS instance".
@ -119,13 +137,13 @@ class game_report extends game_default_report {
$number = 1;
foreach ($questionids as $key => $id) {
if ($questions[$id]->length) {
// Only print questions of non-zero length
// Only print questions of non-zero length.
$tablecolumns[] = '$'.$id;
$tableheaders[] = '#'.$number;
$questions[$id]->number = $number;
$number += $questions[$id]->length;
} else {
// get rid of zero length questions
// Get rid of zero length questions.
unset($questions[$id]);
unset($questionids[$key]);
}
@ -138,7 +156,7 @@ class game_report extends game_default_report {
}
if (!$download) {
// Set up the table
// Set up the table.
$table = new flexible_table('mod-game-report-overview-report');
@ -160,20 +178,20 @@ class game_report extends game_default_report {
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'generaltable generalbox');
// Start working -- this is necessary as soon as the niceties are over
// Start working -- this is necessary as soon as the niceties are over.
$table->setup();
} else if ($download == 'ODS') {
require_once("$CFG->libdir/odslib.class.php");
$filename .= ".ods";
// Creating a workbook
// Creating a workbook.
$workbook = new MoodleODSWorkbook("-");
// Sending HTTP headers
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet
// Creating the first worksheet.
$sheettitle = get_string('reportoverview', 'game');
$myxls =& $workbook->add_worksheet($sheettitle);
// format types
// Format types.
$format =& $workbook->add_format();
$format->set_bold(0);
$formatbc =& $workbook->add_format();
@ -193,8 +211,8 @@ class game_report extends game_default_report {
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
// Here starts workshhet headers
// Here starts workshhet headers.
$headers = array(get_string('fullname'),
get_string('startedon', 'game'),
get_string('timecompleted', 'game'),
@ -222,14 +240,14 @@ class game_report extends game_default_report {
require_once("$CFG->libdir/excellib.class.php");
$filename .= ".xls";
// Creating a workbook
// Creating a workbook.
$workbook = new MoodleExcelWorkbook("-");
// Sending HTTP headers
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet
// Creating the first worksheet.
$sheettitle = get_string('reportoverview', 'game');
$myxls =& $workbook->add_worksheet($sheettitle);
// format types
// Format types.
$format =& $workbook->add_format();
$format->set_bold(0);
$formatbc =& $workbook->add_format();
@ -249,9 +267,10 @@ class game_report extends game_default_report {
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
// Here starts workshhet headers
$headers = array(get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
// Here starts workshhet headers.
$headers = array(get_string('fullname'), get_string('startedon', 'game'),
get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
if ($game->grade) {
$headers[] = get_string('grade', 'game').'/'.$game->grade;
@ -279,7 +298,8 @@ class game_report extends game_default_report {
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Pragma: public");
$headers = get_string('fullname')."\t".get_string('startedon', 'game')."\t".get_string('timecompleted', 'game')."\t".get_string('attemptduration', 'game');
$headers = get_string('fullname')."\t".get_string('startedon', 'game').
"\t".get_string('timecompleted', 'game')."\t".get_string('attemptduration', 'game');
if ($game->grade) {
$headers .= "\t".get_string('grade', 'game')."/".$game->grade;
@ -297,48 +317,54 @@ class game_report extends game_default_report {
$contextlists = get_related_contexts_string( get_context_instance( CONTEXT_COURSE, $course->id));
// Construct the SQL
// Construct the SQL.
$select = 'SELECT qa.id,'.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, '.
'qa.id as attemptuniqueid, qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, '.
// 'qa.uniqueid as attemptuniqueid, qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, '.
'qa.score, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
if ($course->id != SITEID) { // this is too complicated, so just do it for each of the four cases.
if ($course->id != SITEID) {
// This is too complicated, so just do it for each of the four cases.
if (!empty($currentgroup) && empty($noattempts)) {
// we want a particular group and we only want to see students WITH attempts.
// We want a particular group and we only want to see students WITH attempts.
// So join on groups_members and do an inner join on attempts.
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '.
groups_members_join_sql().
'JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
$where = ' WHERE ra.contextid ' . $contextlists . ' AND '. groups_members_where_sql($currentgroup) .' AND qa.preview = 0';
$where = ' WHERE ra.contextid ' . $contextlists .
' AND '. groups_members_where_sql($currentgroup) .' AND qa.preview = 0';
} else if (!empty($currentgroup) && !empty($noattempts)) {
// We want a particular group and we want to do something funky with attempts
// We want a particular group and we want to do something funky with attempts.
// So join on groups_members and left join on attempts...
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '.
groups_members_join_sql().
'LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
$where = ' WHERE ra.contextid ' .$contextlists . ' AND '.groups_members_where_sql($currentgroup);
if ($noattempts == 1) {
// noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts)
$where .= ' AND qa.userid IS NULL'; // show ONLY no attempts;
// Noattempts = 1 means only no attempts, so make the left join ask.
// For only records where the right is null (no attempts).
$where .= ' AND qa.userid IS NULL'; // Show ONLY no attempts.
} else {
// We are including attempts, so exclude previews.
$where .= ' AND qa.preview = 0';
}
} else if (empty($currentgroup)) {
// We don't care about group, and we to do something funky with attempts
// So do a left join on attempts
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
// We don't care about group, and we to do something funky with attempts.
// So do a left join on attempts.
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '.
' LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
$where = " WHERE ra.contextid $contextlists";
if (empty($noattempts)) {
$where .= ' AND qa.userid IS NOT NULL AND qa.preview = 0'; // show ONLY students with attempts;
// Show ONLY students with attempts.
$where .= ' AND qa.userid IS NOT NULL AND qa.preview = 0';
} else if ($noattempts == 1) {
// noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts)
$where .= ' AND qa.userid IS NULL'; // show ONLY students without attempts;
// The noattempts = 1 means only no attempts,.
// So make the left join ask for only records where the right is null (no attempts).
// Show ONLY students without attempts.
$where .= ' AND qa.userid IS NULL';
} else if ($noattempts == 3) {
// we want all attempts
// We want all attempts.
$from = 'FROM {user} u JOIN {game_attempts} qa ON u.id = qa.userid ';
$where = ' WHERE qa.gameid = '.$game->id.' AND qa.preview = 0';
} // noattempts = 2 means we want all students, with or without attempts
} // The noattempts = 2 means we want all students, with or without attempts.
}
$countsql = 'SELECT COUNT(DISTINCT('.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).')) '.$from.$where;
} else {
@ -349,22 +375,21 @@ class game_report extends game_default_report {
}
}
if (!$download) {
// Add extra limits due to initials bar
// Add extra limits due to initials bar.
if ($table->get_sql_where()) {
$where .= ' AND '.$table->get_sql_where();
}
// Count the records NOW, before funky question grade sorting messes up $from
// Count the records NOW, before funky question grade sorting messes up $from.
if (!empty($countsql)) {
$totalinitials = count_records_sql($countsql);
if ($table->get_sql_where()) {
$countsql .= ' AND '.$table->get_sql_where();
}
$total = count_records_sql($countsql);
}
// Add extra limits due to sorting by question grade
// Add extra limits due to sorting by question grade.
if ($sort = $table->get_sql_sort()) {
$sortparts = explode(',', $sort);
$newsort = array();
@ -386,13 +411,12 @@ class game_report extends game_default_report {
}
}
// Reconstruct the sort string
// Reconstruct the sort string.
$sort = ' ORDER BY '.implode(', ', $newsort);
}
// Fix some wired sorting
// Fix some wired sorting.
if (empty($sort)) {
//$sort = ' ORDER BY uniqueid';
$sort = ' ORDER BY qa.id';
}
@ -402,12 +426,13 @@ class game_report extends game_default_report {
// If there is feedback, include it in the query.
if ($hasfeedback) {
$select .= ', qf.feedbacktext ';
$from .= " JOIN {game_feedback} AS qf ON " .
$from .= " JOIN {game_feedback} qf ON " .
"qf.gameid = $game->id AND qf.mingrade <= qa.score * $game->grade AND qa.score * $game->grade < qf.maxgrade";
}
// Fetch the attempts
if (!empty($from)) { // if we're in the site course and displaying no attempts, it makes no sense to do the query.
// Fetch the attempts.
if (!empty($from)) {
// If we're in the site course and displaying no attempts, it makes no sense to do the query.
if (!$download) {
$attempts = get_records_sql($select.$from.$where.$sort,
$table->get_page_start(), $table->get_page_size());
@ -418,48 +443,57 @@ class game_report extends game_default_report {
$attempts = array();
}
// Build table rows
// Build table rows.
if (!$download) {
$table->initialbars($totalinitials > 20);
}
if (!empty($attempts) || !empty($noattempts)) {
if ($attempts) {
foreach ($attempts as $attempt) {
$picture = print_user_picture($attempt->userid, $course->id, $attempt->picture, false, true);
// uncomment the commented lines below if you are choosing to show unenrolled users and
// have uncommented the corresponding lines earlier in this script
//if (in_array($attempt->userid, $unenrolledusers)) {
// $userlink = '<a class="dimmed" href="'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).'</a>';
//}
//else {
$userlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).'</a>';
//}
/* Uncomment the commented lines below if you are choosing to show unenrolled users and
* have uncommented the corresponding lines earlier in this script
* if (in_array($attempt->userid, $unenrolledusers)) {
* $userlink = '<a class="dimmed" href="'.$CFG->wwwroot.
* '/user/view.php?id='.$attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).'</a>';
*}
*else {
* $userlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.
* $attempt->userid.'&amp;course='.$course->id.'">'.fullname($attempt).'</a>';
*}
*/
if (!$download) {
$row = array(
'<input type="checkbox" name="attemptid[]" value="'.$attempt->attempt.'" />',
$picture,
$userlink,
empty($attempt->attempt) ? '-' : '<a href="review.php?q='.$game->id.'&amp;attempt='.$attempt->attempt.'">'.userdate($attempt->timestart, $strtimeformat).'</a>',
empty($attempt->timefinish) ? '-' : '<a href="review.php?q='.$game->id.'&amp;attempt='.$attempt->attempt.'">'.userdate($attempt->timefinish, $strtimeformat).'</a>',
empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time($attempt->duration))
empty($attempt->attempt) ? '-' : '<a href="review.php?q='.
$game->id.'&amp;attempt='.$attempt->attempt.'">'.
userdate($attempt->timestart, $strtimeformat).'</a>',
empty($attempt->timefinish) ? '-' : '<a href="review.php?q='.
$game->id.'&amp;attempt='.$attempt->attempt.'">'.
userdate($attempt->timefinish, $strtimeformat).'</a>',
empty($attempt->attempt) ? '-' : (
empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time(
$attempt->duration))
);
} else {
$row = array(fullname($attempt),
empty($attempt->attempt) ? '-' : userdate($attempt->timestart, $strtimeformat),
empty($attempt->timefinish) ? '-' : userdate($attempt->timefinish, $strtimeformat),
empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time($attempt->duration))
empty($attempt->attempt) ? '-' : (
empty($attempt->timefinish) ? get_string(
'unfinished', 'game') : format_time($attempt->duration))
);
}
if ($game->grade) {
if (!$download) {
$row[] = $attempt->score === NULL ? '-' : '<a href="review.php?q='.$game->id.'&amp;attempt='.$attempt->attempt.'">'.round($attempt->score * $game->grade,$game->decimalpoints).'</a>';
$row[] = $attempt->score === null ? '-' : '<a href="review.php?q='.
$game->id.'&amp;attempt='.$attempt->attempt.'">'.
round($attempt->score * $game->grade, $game->decimalpoints).'</a>';
} else {
$row[] = $attempt->score === NULL ? '-' : round($attempt->score * $game->grade,$game->decimalpoints);
$row[] = $attempt->score === null ? '-' : round($attempt->score * $game->grade, $game->decimalpoints);
}
}
if ($detailedmarks) {
@ -469,13 +503,19 @@ class game_report extends game_default_report {
}
} else {
foreach ($questionids as $questionid) {
if ($gradedstateid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->attemptuniqueid, 'questionid', $questionid)) {
$grade = round(get_field('question_states', 'grade', 'id', $gradedstateid), $game->decimalpoints);
if ($gradedstateid = get_field('question_sessions', 'newgraded',
'attemptid', $attempt->attemptuniqueid, 'questionid', $questionid)) {
$grade = round(get_field('question_states', 'grade', 'id',
$gradedstateid), $game->decimalpoints);
} else {
$grade = '--';
}
if (!$download) {
$row[] = link_to_popup_window ('/mod/game/reviewquestion.php?state='.$gradedstateid.'&amp;number='.$questions[$questionid]->number, 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true);
$row[] = link_to_popup_window (
'/mod/game/reviewquestion.php?state='.
$gradedstateid.'&amp;number='.
$questions[$questionid]->number, 'reviewquestion', $grade,
450, 650, $strreviewquestion, 'none', true);
} else {
$row[] = $grade;
}
@ -505,31 +545,38 @@ class game_report extends game_default_report {
}
}
if (!$download) {
// Start form
// Start form.
echo '<div id="tablecontainer">';
echo '<form id="attemptsform" method="post" action="report.php" onsubmit="var menu = document.getElementById(\'menuaction\'); return (menu.options[menu.selectedIndex].value == \'delete\' ? confirm(\''.$strreallydel.'\') : true);">';
echo '<form id="attemptsform" method="post" action="report.php" '.
'onsubmit="var menu = document.getElementById(\'menuaction\'); '.
'return (menu.options[menu.selectedIndex].value == \'delete\' ? confirm(\''.$strreallydel.'\') : true);">';
echo '<div>';
echo '<input type="hidden" name="id" value="'.$cm->id.'" />';
echo '<input type="hidden" name="mode" value="overview" />';
// Print table
// Print table.
$table->print_html();
// Print "Select all" etc.
// Print "Select all" etc..
if (!empty($attempts)) {
echo '<table id="commands">';
echo '<tr><td>';
echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectall', 'game').'</a> / ';
echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.get_string('selectnone', 'game').'</a> ';
echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.
get_string('selectall', 'game').'</a> / ';
echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.
get_string('selectnone', 'game').'</a> ';
echo '&nbsp;&nbsp;';
$options = array('delete' => get_string('delete'));
echo choose_from_menu($options, 'action', '', get_string('withselected', 'game'), 'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true);
echo choose_from_menu($options, 'action', '', get_string('withselected', 'game'),
'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true);
echo '<noscript id="noscriptmenuaction" style="display: inline;"><div>';
echo '<input type="submit" value="'.get_string('go').'" /></div></noscript>';
echo '<script type="text/javascript">'."\n<!--\n".'document.getElementById("noscriptmenuaction").style.display = "none";'."\n-->\n".'</script>';
echo '<script type="text/javascript">'."\n<!--\n".
'document.getElementById("noscriptmenuaction").style.display = "none";'
."\n-->\n".'</script>';
echo '</td></tr></table>';
}
// Close form
// Close form.
echo '</div>';
echo '</form></div>';
@ -545,7 +592,7 @@ class game_report extends game_default_report {
$options['detailedmarks'] = $detailedmarks;
echo '<td>';
$options["download"] = "ODS";
print_single_button("report.php", $options, get_string("downloadods", 'game')); ///check bdaloukas
print_single_button("report.php", $options, get_string("downloadods", 'game'));
echo "</td>\n";
echo '<td>';
$options["download"] = "Excel";
@ -572,7 +619,7 @@ class game_report extends game_default_report {
$table->print_html();
}
}
// Print display options
// Print display options.
echo '<div class="controls">';
echo '<form id="options" action="report.php" method="get">';
echo '<div>';
@ -598,7 +645,10 @@ class game_report extends game_default_report {
choose_from_menu($options, 'noattempts', $noattempts, '');
echo '</td></tr>';
echo '<tr align="left">';
echo '<td colspan="2"><input type="checkbox" id="checkdetailedmarks" name="detailedmarks" '.($detailedmarks?'checked="checked" ':'').'value="1" /> <label for="checkdetailedmarks">'.get_string('showdetailedmarks', 'game').'</label> ';
echo '<td colspan="2"><input type="checkbox" id="checkdetailedmarks" name="detailedmarks" '.
($detailedmarks ? 'checked="checked" ' : '').
'value="1" /> <label for="checkdetailedmarks">'.
get_string('showdetailedmarks', 'game').'</label> ';
echo '</td></tr>';
echo '<tr><td colspan="2" align="center">';
echo '<input type="submit" value="'.get_string('go').'" />';
@ -611,5 +661,3 @@ class game_report extends game_default_report {
return true;
}
}
?>

224
snakes/createboard.php

@ -1,26 +1,30 @@
<?php // $Id: createboard.php,v 1.5 2012/07/25 11:16:07 bdaloukas Exp $
// This file creates a board for "Snakes and Ladders"
/*
require( "../../../config.php");
$im=game_createsnakesboard( $_GET[ 'file'], $_GET[ 'colsx'], $_GET[ 'colsy'], $_GET[ 'ofstop'], $_GET[ 'ofsbottom'], $_GET[ 'ofsright'], $_GET[ 'ofsleft'], $_GET[ 'aboard']);
header('Content-type: image/jpg');
imagejpeg($im);
imagedestroy($im);
*/
function game_createsnakesboard($imageasstring, $colsx, $colsy, $ofstop, $ofsbottom, $ofsright, $ofsleft, $board, $setwidth, $setheight)
{
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// This file creates a board for "Snakes and Ladders".
function game_createsnakesboard($imageasstring, $colsx, $colsy, $ofstop, $ofsbottom,
$ofsright, $ofsleft, $board, $setwidth, $setheight) {
global $CFG;
$dir = $CFG->dirroot.'/mod/game/snakes/1';
$im = imagecreatefromstring($imageasstring);
//check if need resize
if( $setwidth >0 or $setheight > 0)
{
// Check if need resize.
if ( $setwidth > 0 or $setheight > 0) {
$source = $im;
$width = imagesx($source);
$height = imagesy($source);
@ -39,35 +43,30 @@ function game_createsnakesboard($imageasstring, $colsx, $colsy, $ofstop, $ofsbot
$cy = imagesy($im) - $ofstop - $ofsbottom;
$color = 0xFF0000;
for( $i=0; $i <= $colsx; $i++)
{
for ($i = 0; $i <= $colsx; $i++) {
imageline( $im, $ofsleft + $i * $cx / $colsx, $ofstop, $ofsleft + $i * $cx / $colsx, $cy + $ofstop, $color);
}
for( $i=0; $i <= $colsy; $i++)
{
for ($i = 0; $i <= $colsy; $i++) {
imageline( $im, $ofsleft, $ofstop + $i * $cy / $colsy, $cx + $ofsleft, $ofstop + $i * $cy / $colsy, $color);
}
$filenamenumbers = $dir.'/numbers.png';
$img_numbers = imageCreateFrompng( $filenamenumbers);
$size_numbers = getimagesize ($filenamenumbers);
$imgnumbers = imagecreatefrompng( $filenamenumbers);
$sizenumbers = getimagesize ($filenamenumbers);
for( $iy=0; $iy < $colsy; $iy++)
{
for ($iy = 0; $iy < $colsy; $iy++) {
if ($iy % 2 == 0) {
$inc = false;
$num = ($colsy - $iy) * $colsy;
}else
{
} else {
$inc = true;
$num = ($colsy - $iy) * $colsy - ($colsy - 1);
}
$ypos = $iy * $cy / $colsy + $ofstop;
for( $ix=0; $ix < $colsx; $ix++)
{
for ($ix = 0; $ix < $colsx; $ix++) {
$xpos = $ix * $cx / $colsx + $ofsleft;
shownumber( $im, $img_numbers, $num, $xpos, $ypos, $cx/4, $cy/4, $size_numbers);
shownumber( $im, $imgnumbers, $num, $xpos, $ypos, $cx / 4, $cy / 4, $sizenumbers);
$num = ($inc ? $num + 1 : $num - 1);
}
}
@ -77,36 +76,33 @@ function game_createsnakesboard($imageasstring, $colsx, $colsy, $ofstop, $ofsbot
return $im;
}
function computexy( $pos, &$x, &$y, $colsx, $colsy)
{
function computexy( $pos, &$x, &$y, $colsx, $colsy) {
$x = ($pos - 1) % $colsx;
$y = ($colsy - 1) - floor( ($pos - 1) / $colsy);
if($y % 2 == 0)
if ($y % 2 == 0) {
$x = ($colsx - 1) - $x;
}
}
function makeboard( $im, $dir, $cx, $cy, $board, $colsx, $colsy, $ofsleft, $ofstop)
{
function makeboard( $im, $dir, $cx, $cy, $board, $colsx, $colsy, $ofsleft, $ofstop) {
$a = explode( ',', $board);
foreach( $a as $s)
{
if( substr( $s,0,1) == 'L')
foreach ($a as $s) {
if (substr( $s, 0, 1) == 'L') {
makeboardL( $im, $dir, $cx, $cy, substr( $s, 1), $colsx, $colsy, $ofsleft, $ofstop);
else
} else {
makeboardS( $im, $dir, $cx, $cy, substr( $s, 1), $colsx, $colsy, $ofsleft, $ofstop);
}
}
}
function makeboardL( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop)
{
function makeboardl( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop) {
$pos = strpos( $s, '-');
$from = substr( $s, 0, $pos);
$to = substr( $s, $pos + 1);
computexy( $from, $startx, $starty, $colsx, $colsy);
computexy( $to, $x2, $y2, $colsx, $colsy);
if( ($x2 < $startx) and ($y2 < $starty))
{
if (($x2 < $startx) and ($y2 < $starty)) {
$temp = $x2; $x2 = $startx; $startx = $temp;
$temp = $y2; $y2 = $starty; $starty = $temp;
}
@ -115,15 +111,13 @@ function makeboardL( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop)
$letter = ( $movex * $movey < 0 ? 'b' : 'a');
$_startx = $startx; $_movex=$movex; $_starty = $starty; $_movey=$movey;
$oldstartx = $startx; $oldmovex = $movex; $oldstarty = $starty; $oldmovey = $movey;
if( $movex < 0)
{
if ($movex < 0) {
$startx += $movex;
$movex = -$movex;
}
if( $movey < 0)
{
if ($movey < 0) {
$starty += $movey;
$movey = -$movey;
}
@ -132,36 +126,33 @@ function makeboardL( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop)
$file = $dir.'/l'.$letter.$movey.$movex.'.png';
if (file_exists( $file)) {
$stamp = game_imagecreatefrompng( $file);
}else
{
} else {
$file = $dir.'/la'.$movey.$movex.'.png';
$source = game_imagecreatefrompng( $file);
if( $source != 0)
if ( $source != 0) {
$stamp = imagerotate($source, 90, 0);
}
}else
{
}
} else {
$file = $dir.'/la'.$movex.$movey.'.png';
$stamp = game_imagecreatefrompng( $file);
}
$dst_x = $startx*$cx/$colsx;
$dst_y = $starty*$cy/$colsy;
$dst_w = ($movex+1) * $cx / $colsx;
$dst_h = ($movey+1) * $cy / $colsy;
$dstx = $startx * $cx / $colsx;
$dsty = $starty * $cy / $colsy;
$dstw = ($movex + 1) * $cx / $colsx;
$dsth = ($movey + 1) * $cy / $colsy;
if( $stamp == 0)
{
game_printladder( $im, $file, $dst_x+$ofsleft, $dst_y+$ofstop, $dst_w, $dst_h, $cx/$colsx, $cy/$colsy);
}else
{
imagecopyresampled( $im, $stamp, $ofsleft+$dst_x, $ofstop+$dst_y, 0, 0, $dst_w, $dst_h, 100*$movex+100, 100*$movey+100);
if ($stamp == 0) {
game_printladder( $im, $file, $dstx + $ofsleft, $dsty + $ofstop, $dstw, $dsth, $cx / $colsx, $cy / $colsy);
} else {
imagecopyresampled( $im, $stamp, $ofsleft + $dstx, $ofstop + $dsty, 0, 0, $dstw, $dsth,
100 * $movex + 100, 100 * $movey + 100);
}
}
function makeboardS( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop)
{
function makeboards( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop) {
$pos = strpos( $s, '-');
$from = substr( $s, 0, $pos);
$to = substr( $s, $pos + 1);
@ -169,8 +160,7 @@ function makeboardS( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop)
computexy( $from, $startx, $starty, $colsx, $colsy);
computexy( $to, $x2, $y2, $colsx, $colsy);
$swap = 0;
if( ($x2 < $startx) and ($y2 < $starty))
{
if (($x2 < $startx) and ($y2 < $starty)) {
$temp = $x2; $x2 = $startx; $startx = $temp;
$temp = $y2; $y2 = $starty; $starty = $temp;
$swap = 1;
@ -178,109 +168,108 @@ function makeboardS( $im, $dir, $cx, $cy, $s, $colsx, $colsy, $ofsleft, $ofstop)
$movex = $x2 - $startx;
$movey = $y2 - $starty;
//a*d
//***
//b*c
/* a*d
*
* b*c
*/
$stamp = $rotate = 0;
if ($movex >= 0 and $movey < 0) {
$letter = 'b';
$file = $dir.'/sa'.$movey.$movex.'.png';
$source = game_imagecreatefrompng( $file);
if( $source != 0)
{
if ($source != 0) {
$stamp = imagerotate($source, 270, 0);
$starty += $movey; $movey = -$movey;
}else
} else {
$rotate = 270;
}
} else if ($movex < 0 and $movey < 0) {
$letter = 'c';
$file = $dir.'/sa'.$movey.$movex.'.png';
$source = game_imagecreatefrompng( $file);
if( $source != 0)
{
if ($source != 0) {
$stamp = imagerotate($source, 180, 0);
$startx += $movex; $movex = -$movex;
$starty += $movey; $movey = -$movey;
}else
} else {
$rotate = 180;
}
} else if (($movex < 0) and ($movey >= 0)) {
$letter = 'd';
$file = $dir.'/sa'.$movey.$movex.'.png';
$source = game_imagecreatefrompng( $file);
if( $source != 0)
{
if ($source != 0) {
$stamp = imagerotate($source, 270, 0);
$startx += $movex; $movex = -$movex;
}else
} else {
$rotate = 270;
}else
{
}
} else {
$file = $dir.'/sa'.$movex.$movey.'.png';
$stamp = game_imagecreatefrompng( $file);
}
if( ($swap != 0) and ($stamp == 0))
{
if (($swap != 0) and ($stamp == 0)) {
$temp = $x2; $x2 = $startx; $startx = $temp;
$temp = $y2; $y2 = $starty; $starty = $temp;
$movex = $x2 - $startx;
$movey = $y2 - $starty;
}
$dst_x = $startx*$cx/$colsx;
$dst_y = $starty*$cy/$colsy;
$dst_w = ($movex+1) * $cx / $colsx;
$dst_h = ($movey+1) * $cy / $colsy;
$dstx = $startx * $cx / $colsx;
$dsty = $starty * $cy / $colsy;
$dstw = ($movex + 1) * $cx / $colsx;
$dsth = ($movey + 1) * $cy / $colsy;
if( $stamp == 0)
{
game_printsnake( $im, $file, $dst_x+$ofsleft, $dst_y+$ofstop, $dst_w, $dst_h, $cx/$colsx, $cy/$colsy);
}else
imagecopyresampled( $im, $stamp, $dst_x+$ofsleft, $dst_y+$ofstop, 0, 0, $dst_w, $dst_h, 100*$movex+100, 100*$movey+100);
if ($stamp == 0) {
game_printsnake( $im, $file, $dstx + $ofsleft, $dsty + $ofstop, $dstw, $dsth, $cx / $colsx, $cy / $colsy);
} else {
imagecopyresampled( $im, $stamp, $dstx + $ofsleft, $dsty + $ofstop, 0, 0, $dstw, $dsth,
100 * $movex + 100, 100 * $movey + 100);
}
}
function game_imagecreatefrompng( $file) {
if( file_exists( $file))
if (file_exists( $file)) {
return imagecreatefrompng( $file);
}
return 0;
}
function shownumber( $img_handle, $img_numbers, $number, $x1 , $y1, $width, $height, $size_numbers){
function shownumber( $imghandle, $imgnumbers, $number, $x1 , $y1, $width, $height, $sizenumbers) {
if ($number < 10) {
$width_number = $size_numbers[ 0] / 10;
$dstX = $x1 + $width / 10;
$dstY = $y1 + $height / 10;
$srcX = $number * $size_numbers[ 0] / 10;
$srcW = $size_numbers[ 0]/10;
$srcH = $size_numbers[ 1];
$dstW = $width / 10;
$dstH = $dstW * $srcH / $srcW;
imagecopyresampled( $img_handle, $img_numbers, $dstX, $dstY, $srcX, 0, $dstW, $dstH, $srcW, $srcH);
}else
{
$widthnumber = $sizenumbers[ 0] / 10;
$dstx = $x1 + $width / 10;
$dsty = $y1 + $height / 10;
$srcx = $number * $sizenumbers[ 0] / 10;
$srcw = $sizenumbers[ 0] / 10;
$srch = $sizenumbers[ 1];
$dstw = $width / 10;
$dsth = $dstw * $srch / $srcw;
imagecopyresampled( $imghandle, $imgnumbers, $dstx, $dsty, $srcx, 0, $dstw, $dsth, $srcw, $srch);
} else {
$number1 = floor( $number / 10);
$number2 = $number % 10;
shownumber( $img_handle, $img_numbers, $number1, $x1-$width/20, $y1, $width, $height, $size_numbers);
shownumber( $img_handle, $img_numbers, $number2, $x1+$width/20, $y1, $width, $height, $size_numbers);
shownumber( $imghandle, $imgnumbers, $number1, $x1 - $width / 20, $y1, $width, $height, $sizenumbers);
shownumber( $imghandle, $imgnumbers, $number2, $x1 + $width / 20, $y1, $width, $height, $sizenumbers);
}
}
function returnRotatedPoint($x,$y,$cx,$cy,$a)
{
// radius using distance formula
function returnrotatedpoint($x, $y, $cx, $cy, $a) {
// Radius using distance formula.
$r = sqrt(pow(($x - $cx), 2) + pow(($y - $cy), 2));
// initial angle in relation to center
$iA = rad2deg(atan2(($y-$cy),($x-$cx)));
$nx = $r * cos(deg2rad($a + $iA));
$ny = $r * sin(deg2rad($a + $iA));
// Initial angle in relation to center.
$ia = rad2deg(atan2(($y - $cy), ($x - $cx)));
$nx = $r * cos(deg2rad($a + $ia));
$ny = $r * sin(deg2rad($a + $ia));
return array("x" => $cx + $nx, "y" => $cy + $ny);
}
function game_printladder( $im, $file, $x, $y, $width, $height, $cellx, $celly)
{
function game_printladder( $im, $file, $x, $y, $width, $height, $cellx, $celly) {
$color = imagecolorallocate($im, 0, 0, 255);
$x2 = $x + $width - $cellx / 2;
$y2 = $y + $height - $celly / 2;
@ -297,8 +286,7 @@ function game_printladder( $im, $file, $x, $y, $width, $height, $cellx, $celly)
imageline( $im, $x2, $y2, $a[ 'x'], $a[ 'y'], $color);
}
function game_printsnake( $im, $file, $x, $y, $width, $height, $cellx, $celly)
{
function game_printsnake( $im, $file, $x, $y, $width, $height, $cellx, $celly) {
$color = imagecolorallocate($im, 0, 255, 0);
$x2 = $x + $width - $cellx / 2;
$y2 = $y + $height - $celly / 2;

175
snakes/play.php

@ -1,9 +1,22 @@
<?php // $Id: play.php,v 1.26 2012/07/26 05:39:00 bdaloukas Exp $
// This files plays the game "Snakes and Ladders"
function game_snakes_continue( $id, $game, $attempt, $snakes, $context)
{
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// This files plays the game "Snakes and Ladders".
function game_snakes_continue( $id, $game, $attempt, $snakes, $context) {
if ($attempt != false and $snakes != false) {
return game_snakes_play( $id, $game, $attempt, $snakes, $context);
}
@ -15,8 +28,9 @@ function game_snakes_continue( $id, $game, $attempt, $snakes, $context)
$newrec = new stdClass();
$newrec->id = $attempt->id;
$newrec->snakesdatabaseid = $game->param3;
if( $newrec->snakesdatabaseid == 0)
if ($newrec->snakesdatabaseid == 0) {
$newrec->snakesdatabaseid = 1;
}
$newrec->position = 1;
$newrec->queryid = 0;
$newrec->dice = rand( 1, 6);
@ -29,8 +43,7 @@ function game_snakes_continue( $id, $game, $attempt, $snakes, $context)
return game_snakes_play( $id, $game, $attempt, $newrec, $context);
}
function game_snakes_play( $id, $game, $attempt, $snakes, $context)
{
function game_snakes_play( $id, $game, $attempt, $snakes, $context) {
global $CFG, $DB, $OUTPUT;
$board = game_snakes_get_board( $game);
@ -45,19 +58,18 @@ function game_snakes_play( $id, $game, $attempt, $snakes, $context)
echo '<B>'.get_string( 'win', 'game').'</B><BR>';
echo '<br>';
echo "<a href=\"$CFG->wwwroot/mod/game/attempt.php?id=$id\">".get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
echo "<a href=\"$CFG->wwwroot/mod/game/attempt.php?id=$id\">".
get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
echo "<a href=\"$CFG->wwwroot/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> ';
$gradeattempt = 1;
$finish = 1;
game_updateattempts( $game, $attempt, $gradeattempt, $finish);
}else
{
} else {
$finish = false;
if ($snakes->queryid == 0) {
game_snakes_computenextquestion( $game, $snakes, $query);
}else
{
} else {
$query = $DB->get_record( 'game_queries', array( 'id' => $snakes->queryid));
}
if ($game->toptext != '') {
@ -66,9 +78,9 @@ function game_snakes_play( $id, $game, $attempt, $snakes, $context)
$showboard = true;
}
if( $showboard and $game->param8 == 0)
if ($showboard and $game->param8 == 0) {
game_snakes_showquestion( $id, $game, $snakes, $query, $context);
}
?>
<script language="javascript" event="onload" for="window">
<!--
@ -87,13 +99,12 @@ function game_snakes_play( $id, $game, $attempt, $snakes, $context)
<tr>
<td>
<div id="board" STYLE="position:relative; left:0px;top:0px; width:<?php p($board->width); ?>px; height:<?php p($board->height); ?>px;">
<div id="board" STYLE="position:relative; left:0px;top:0px;
width:<?php p($board->width); ?>px; height:<?php p($board->height); ?>px;">
<img src="<?php echo $board->imagesrc; ?>"></img>
</div>
<?php
if ($finish == false) {
game_snakes_showdice( $snakes, $board);
}
@ -107,26 +118,30 @@ if( $finish == false){
echo '<br>'.$game->bottomtext;
}
if( $showboard and $game->param8 != 0)
if ($showboard and $game->param8 != 0) {
game_snakes_showquestion( $id, $game, $snakes, $query, $context);
}
}
function game_snakes_showdice( $snakes, $board)
{
function game_snakes_showdice( $snakes, $board) {
$pos = game_snakes_computeplayerposition( $snakes, $board);
?>
<div ID="player1" STYLE="position:relative; left:<?php p( $pos->x);?>px; top:<?php p( $pos->y);?>px;" >
<img src="snakes/1/player1.png" alt="<?php print_string('snakes_player', 'game', ($snakes->position +1)); /*Accessibility. */ ?>" width="<?php echo $pos->width; ?>" height="<?php echo $pos->height; ?>"/>
<img src="snakes/1/player1.png"
alt="<?php print_string('snakes_player', 'game', ($snakes->position + 1)); /*Accessibility. */ ?>"
width="<?php echo $pos->width; ?>"
height="<?php echo $pos->height; ?>"/>
</div>
<div ID="dice" STYLE="position:relative; left:<?php p( $board->width + round($board->width/3));?>px;top:<?php p( -2*round($board->height/3));?>px; ">
<div ID="dice" STYLE="position:relative;
left:<?php p( $board->width + round($board->width / 3)); ?>px;
top:<?php p( -2 * round($board->height / 3));?>px; ">
<img src="snakes/1/dice<?php p($snakes->dice);?>.png" alt="<?php print_string('snakes_dice', 'game', $snakes->dice) ?>" />
</div>
<?php
}
function game_snakes_computeplayerposition( $snakes, $board)
{
function game_snakes_computeplayerposition( $snakes, $board) {
$x = ($snakes->position - 1) % $board->cols;
$y = floor( ($snakes->position - 1) / $board->cols);
@ -155,38 +170,37 @@ function game_snakes_computeplayerposition( $snakes, $board)
return $pos;
}
function game_snakes_computenextquestion( $game, &$snakes, &$query)
{
function game_snakes_computenextquestion( $game, &$snakes, &$query) {
global $DB, $USER;
//Retrieves CONST_GAME_TRIES_REPETITION words and select the one which is used fewer times
// Retrieves CONST_GAME_TRIES_REPETITION words and select the one which is used fewer times.
if (($recs = game_questions_selectrandom( $game, 1, CONST_GAME_TRIES_REPETITION)) == false) {
return false;
}
$glossaryid = 0;
$questionid = 0;
$min_num = 0;
$minnum = 0;
$query = new stdClass();
foreach ($recs as $rec) {
$a = array( 'gameid' => $game->id, 'userid' => $USER->id, 'questionid' => $rec->questionid, 'glossaryentryid' => $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) {
if( ($rec2->r < $min_num) or ($min_num == 0)){
$min_num = $rec2->r;
if (($rec2->r < $minnum) or ($minnum == 0)) {
$minnum = $rec2->r;
$query->glossaryentryid = $rec->glossaryentryid;
$query->questionid = $rec->questionid;
}
}
else{
} else {
$query->glossaryentryid = $rec->glossaryentryid;
$query->questionid = $rec->questionid;
break;
}
}
if( ($query->glossaryentryid == 0) AND ($query->questionid == 0))
if (($query->glossaryentryid == 0) and ($query->questionid == 0)) {
return false;
}
$query->attemptid = $snakes->id;
$query->gameid = $game->id;
$query->userid = $USER->id;
@ -213,64 +227,64 @@ function game_snakes_computenextquestion( $game, &$snakes, &$query)
return true;
}
function game_snakes_showquestion( $id, $game, $snakes, $query, $context)
{
function game_snakes_showquestion( $id, $game, $snakes, $query, $context) {
if ($query->sourcemodule == 'glossary') {
game_snakes_showquestion_glossary( $id, $snakes, $query, $game);
}else
{
} else {
game_snakes_showquestion_question( $game, $id, $snakes, $query, $context);
}
}
function game_snakes_showquestion_question( $game, $id, $snakes, $query, $context)
{
function game_snakes_showquestion_question( $game, $id, $snakes, $query, $context) {
global $CFG;
$questionlist = $query->questionid;
$questions = game_sudoku_getquestions( $questionlist);
/// Start the form
echo "<form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n";
// 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 quiz id
// Add a hidden field with the quiz id.
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n";
echo '<input type="hidden" name="action" value="snakescheck" />';
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n";
/// Print all the questions
foreach( $questions as $question)
// Print all the questions.
foreach ($questions as $question) {
game_print_question( $game, $question, $context);
// Add a hidden field with questionids
}
// Add a hidden field with questionids.
echo '<input type="hidden" name="questionids" value="'.$questionlist."\" />\n";
echo "</form>\n";
}
function game_snakes_showquestion_glossary( $id, $snakes, $query, $game)
{
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";
// 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
// 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
// Print all the questions.
// Add a hidden field with glossaryentryid
// 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 = game_get_context_module_instance( $cmglossary->id);
$s = game_filterglossary(str_replace( '\"', '"', $entry->definition), $query->glossaryentryid, $contextglossary->id, $game->course);
$s = game_filterglossary(str_replace( '\"', '"', $entry->definition), $query->glossaryentryid,
$contextglossary->id, $game->course);
echo $s.'<br>';
echo get_string( 'answer').': ';
@ -279,9 +293,7 @@ function game_snakes_showquestion_glossary( $id, $snakes, $query, $game)
echo "</form>\n";
}
function game_snakes_check_questions( $id, $game, $attempt, $snakes, $context)
{
function game_snakes_check_questions( $id, $game, $attempt, $snakes, $context) {
global $QTYPES, $CFG, $DB;
$responses = data_submitted();
@ -302,24 +314,22 @@ function game_snakes_check_questions( $id, $game, $attempt, $snakes, $context)
$grade = game_grade_responses( $question, $responses, 100, $answertext);
if ($grade < 99) {
//wrong answer
// Wrong answer.
game_update_queries( $game, $attempt, $query, 0, $answertext);
continue;
}
//correct answer
// Correct answer.
$correct = true;
game_update_queries( $game, $attempt, $query, 1, '');
}
//set the grade of the whole game
// Set the grade of the whole game.
game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context);
}
function game_snakes_check_glossary( $id, $game, $attempt, $snakes, $context)
{
function game_snakes_check_glossary( $id, $game, $attempt, $snakes, $context) {
global $QTYPES, $CFG, $DB;
$responses = data_submitted();
@ -337,24 +347,21 @@ function game_snakes_check_glossary( $id, $game, $attempt, $snakes, $context)
$useranswer = $responses->answer;
if (game_upper( $useranswer) != game_upper( $glossaryentry->concept)) {
//wrong answer
// Wrong answer.
$correct = false;
game_update_queries( $game, $attempt, $query, 0, $useranswer);//last param is grade
}else
{
//correct answer
game_update_queries( $game, $attempt, $query, 0, $useranswer); // Last param is grade.
} else {
// Correct answer.
$correct = true;
game_update_queries( $game, $attempt, $query, 1, $useranswer);//last param is grade
game_update_queries( $game, $attempt, $query, 1, $useranswer); // Last param is grade.
}
//set the grade of the whole game
// Set the grade of the whole game.
game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context);
}
function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context)
{
function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context) {
global $DB;
$data = $DB->get_field( 'game_snakes_database', 'data', array( 'id' => $snakes->snakesdatabaseid));
@ -362,12 +369,10 @@ function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query,
if ($correct) {
if (($next = game_snakes_foundlander( $snakes->position + $snakes->dice, $data))) {
$snakes->position = $next;
}else
{
} else {
$snakes->position = $snakes->position + $snakes->dice;
}
}else
{
} else {
if (($next = game_snakes_foundsnake( $snakes->position, $data))) {
$snakes->position = $next;
}
@ -393,9 +398,8 @@ function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query,
game_snakes_play( $id, $game, $attempt, $snakes, $context);
}
//in lander go forward
function game_snakes_foundlander( $position, $data)
{
// In lander go forward.
function game_snakes_foundlander( $position, $data) {
preg_match( "/L$position-([0-9]*)/", $data, $matches);
if (count( $matches)) {
@ -405,9 +409,8 @@ function game_snakes_foundlander( $position, $data)
return 0;
}
//in snake go backward
function game_snakes_foundsnake( $position, $data)
{
// In snake go backward.
function game_snakes_foundsnake( $position, $data) {
preg_match( "/S([0-9]*)-$position,/", $data.',', $matches);
if (count( $matches)) {

Loading…
Cancel
Save