Vasilis Daloukas
9 years ago
11 changed files with 5332 additions and 3557 deletions
@ -1,229 +1,220 @@ |
|||||
<?PHP |
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
class CryptexDB extends CrossDB |
// |
||||
{ |
// Moodle is free software: you can redistribute it and/or modify |
||||
function savecryptex( $game, &$crossm, $crossd, $id, $letters) |
// it under the terms of the GNU General Public License as published by |
||||
{ |
// the Free Software Foundation, either version 3 of the License, or |
||||
global $USER; |
// (at your option) any later version. |
||||
|
// |
||||
CrossDB::delete_records( $id); |
// Moodle is distributed in the hope that it will be useful, |
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
if( (CrossDB::savecross( $game, $crossm, $crossd, $id)) == false){ |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
return false; |
// GNU General Public License for more details. |
||||
} |
// |
||||
|
// You should have received a copy of the GNU General Public License |
||||
$crossm->id = $id; |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
$newrec = new stdClass(); |
class CryptexDB extends CrossDB { |
||||
$newrec->id = $id; |
public function savecryptex( $game, &$crossm, $crossd, $id, $letters) { |
||||
$newrec->letters = $letters; |
global $USER; |
||||
|
|
||||
if (!($cryptexid = game_insert_record( "game_cryptex", $newrec))){ |
CrossDB::delete_records( $id); |
||||
print_error( 'Insert page: new page game_cryptex not inserted'); |
|
||||
} |
if ((CrossDB::savecross( $game, $crossm, $crossd, $id)) == false) { |
||||
|
return false; |
||||
return $newrec; |
} |
||||
} |
|
||||
|
$crossm->id = $id; |
||||
|
|
||||
function computeletters( $crossm, $crossd) |
$newrec = new stdClass(); |
||||
{ |
$newrec->id = $id; |
||||
$letters = ''; |
$newrec->letters = $letters; |
||||
$cols = $crossm->cols + 1; |
|
||||
$letters = str_repeat('.', $crossm->cols).'#'; |
if (!($cryptexid = game_insert_record( "game_cryptex", $newrec))) { |
||||
$letters = str_repeat($letters, $crossm->rows) ; |
print_error( 'Insert page: new page game_cryptex not inserted'); |
||||
|
} |
||||
$freqs1 = array(); |
|
||||
$count1 = $count2 = 0; |
return $newrec; |
||||
foreach( $crossd as $rec) |
} |
||||
{ |
|
||||
$pos = $rec->col - 1 + ($rec->row-1) * $cols; |
public function computeletters( $crossm, $crossd) { |
||||
$s = $rec->answertext; |
$letters = ''; |
||||
$len = game_strlen( $s); |
$cols = $crossm->cols + 1; |
||||
|
$letters = str_repeat('.', $crossm->cols).'#'; |
||||
$a = array(); |
$letters = str_repeat($letters, $crossm->rows); |
||||
for( $i=0; $i < $len; $i++){ |
|
||||
$a[] = game_substr( $s, $i, 1); |
$freqs1 = array(); |
||||
} |
$count1 = $count2 = 0; |
||||
|
foreach ($crossd as $rec) { |
||||
for( $i=0; $i < $len; $i++){ |
$pos = $rec->col - 1 + ($rec->row - 1) * $cols; |
||||
$this->setchar( $letters, $pos, $a[ $i]); |
$s = $rec->answertext; |
||||
$pos += ( $rec->horizontal ? 1 : $cols); |
$len = game_strlen( $s); |
||||
|
|
||||
$freqs1[ ++$count1] = $a[ $i]; |
$a = array(); |
||||
if( $i+1 < $len){ |
for ($i = 0; $i < $len; $i++) { |
||||
$freqs2[ ++$count2] = $a[ $i].$a[ $i+1]; |
$a[] = game_substr( $s, $i, 1); |
||||
} |
} |
||||
} |
|
||||
} |
for ($i = 0; $i < $len; $i++) { |
||||
|
$this->setchar( $letters, $pos, $a[ $i]); |
||||
$len = game_strlen( $letters); |
$pos += ( $rec->horizontal ? 1 : $cols); |
||||
$spaces = 0; |
|
||||
for( $i=0; $i < $len; $i++){ |
$freqs1[ ++$count1] = $a[ $i]; |
||||
if( game_substr( $letters, $i, 1) == '.'){ |
if ($i + 1 < $len) { |
||||
$spaces++; |
$freqs2[ ++$count2] = $a[ $i].$a[ $i + 1]; |
||||
} |
} |
||||
} |
} |
||||
|
} |
||||
$step = 1; |
|
||||
while( $spaces) |
$len = game_strlen( $letters); |
||||
{ |
$spaces = 0; |
||||
if( $step == 1){ |
for ($i = 0; $i < $len; $i++) { |
||||
$step = 2; |
if (game_substr( $letters, $i, 1) == '.') { |
||||
$i = array_rand( $freqs1); |
$spaces++; |
||||
$this->insertchar( $letters, $crossm->cols, $crossm->rows, $freqs1[ $i], $spaces); |
} |
||||
}else |
} |
||||
{ |
|
||||
$step=1; |
$step = 1; |
||||
$i = array_rand( $freqs2); |
while ($spaces) { |
||||
$this->insertchars( $letters, $crossm->cols, $crossm->rows, $freqs2[ $i], $spaces); |
if ($step == 1) { |
||||
} |
$step = 2; |
||||
} |
$i = array_rand( $freqs1); |
||||
|
$this->insertchar( $letters, $crossm->cols, $crossm->rows, $freqs1[ $i], $spaces); |
||||
$ret_letters = ""; |
} else { |
||||
for( $row=0; $row < $crossm->rows; $row++){ |
$step = 1; |
||||
$ret_letters .= game_substr( $letters, $cols * $row, ($cols-1)); |
$i = array_rand( $freqs2); |
||||
} |
$this->insertchars( $letters, $crossm->cols, $crossm->rows, $freqs2[ $i], $spaces); |
||||
|
} |
||||
|
} |
||||
return $ret_letters; |
|
||||
} |
$retletters = ""; |
||||
|
for ($row = 0; $row < $crossm->rows; $row++) { |
||||
function displaycryptex( $cols, $rows, $letters, $mask, $showsolution, $textdir) |
$retletters .= game_substr( $letters, $cols * $row, ($cols - 1)); |
||||
{ |
} |
||||
echo "<table border=1 $textdir>"; |
|
||||
for( $row=0; $row < $rows; $row++) |
return $retletters; |
||||
{ |
} |
||||
echo "<tr>"; |
|
||||
for( $col=0; $col < $cols; $col++){ |
public function displaycryptex( $cols, $rows, $letters, $mask, $showsolution, $textdir) { |
||||
$pos = $cols * $row+$col; |
echo "<table border=1 $textdir>"; |
||||
$c = game_substr( $letters, $pos, 1); |
for ($row = 0; $row < $rows; $row++) { |
||||
$m = game_substr( $mask, $pos, 1); |
echo "<tr>"; |
||||
|
for ($col = 0; $col < $cols; $col++) { |
||||
if( $showsolution and $m > '0'){ |
$pos = $cols * $row + $col; |
||||
echo "<td align=center><b><FONT color=red>".$c."</font></td>"; |
$c = game_substr( $letters, $pos, 1); |
||||
}else if( $m == '1'){ |
$m = game_substr( $mask, $pos, 1); |
||||
echo "<td align=center><b><FONT color=red>".$c."</font></td>"; |
|
||||
}else |
if ($showsolution and $m > '0') { |
||||
{ |
echo "<td align=center><b><FONT color=red>".$c."</font></td>"; |
||||
echo "<td align=center>".$c."</td>"; |
} else if ( $m == '1') { |
||||
} |
echo "<td align=center><b><FONT color=red>".$c."</font></td>"; |
||||
} |
} else { |
||||
echo "</tr>\r\n"; |
echo "<td align=center>".$c."</td>"; |
||||
} |
} |
||||
echo "</table>"; |
} |
||||
} |
echo "</tr>\r\n"; |
||||
|
} |
||||
function insertchar( &$letters, $cols, $rows, $char, &$spaces) |
echo "</table>"; |
||||
{ |
} |
||||
$len = game_strlen( $letters); |
|
||||
for( $i=0; $i < $len; $i++){ |
public function insertchar( &$letters, $cols, $rows, $char, &$spaces) { |
||||
if( game_substr( $letters, $i, 1) == '.'){ |
$len = game_strlen( $letters); |
||||
$this->setchar( $letters, $i, $char); |
for ($i = 0; $i < $len; $i++) { |
||||
$spaces--; |
if (game_substr( $letters, $i, 1) == '.') { |
||||
return; |
$this->setchar( $letters, $i, $char); |
||||
} |
$spaces--; |
||||
} |
return; |
||||
} |
} |
||||
|
} |
||||
function insertchars( &$letters, $cols, $rows, $char, &$spaces) |
} |
||||
{ |
|
||||
$len = game_strlen( $letters); |
public function insertchars( &$letters, $cols, $rows, $char, &$spaces) { |
||||
for( $i=0; $i < $len; $i++){ |
$len = game_strlen( $letters); |
||||
if( game_substr( $letters, $i, 1) == '.' and game_substr( $letters, $i+1, 1) == '.' ){ |
for ($i = 0; $i < $len; $i++) { |
||||
$this->setchar( $letters, $i, game_substr( $char, 0, 1)); |
if (game_substr( $letters, $i, 1) == '.' and game_substr( $letters, $i + 1, 1) == '.' ) { |
||||
$this->setchar( $letters, $i+1, game_substr( $char, 1, 1)); |
$this->setchar( $letters, $i, game_substr( $char, 0, 1)); |
||||
$spaces-=2; |
$this->setchar( $letters, $i + 1, game_substr( $char, 1, 1)); |
||||
return true; |
$spaces -= 2; |
||||
} |
return true; |
||||
if( game_substr( $letters, $i, 1) == '.' and game_substr( $letters, $i+$cols+1, 1) == '.' ){ |
} |
||||
$this->setchar( $letters, $i, game_substr( $char, 0, 1)); |
if (game_substr( $letters, $i, 1) == '.' and game_substr( $letters, $i + $cols + 1, 1) == '.' ) { |
||||
$this->setchar( $letters, $i + $cols+1, game_substr( $char, 1, 1)); |
$this->setchar( $letters, $i, game_substr( $char, 0, 1)); |
||||
$spaces-=2; |
$this->setchar( $letters, $i + $cols + 1, game_substr( $char, 1, 1)); |
||||
return true; |
$spaces -= 2; |
||||
} |
return true; |
||||
} |
} |
||||
|
} |
||||
return false; |
|
||||
} |
return false; |
||||
|
} |
||||
function gethash( $word) |
|
||||
{ |
public function gethash( $word) { |
||||
$x = 37; |
$x = 37; |
||||
$len = count( game_strlen( $word)); |
$len = count( game_strlen( $word)); |
||||
|
|
||||
for($i=0; $i < $len; $i++){ |
for ($i = 0; $i < $len; $i++) { |
||||
$x = $x xor ord( game_substr( $word, $i, 1)); |
$x = $x xor ord( game_substr( $word, $i, 1)); |
||||
} |
} |
||||
|
|
||||
return $x; |
return $x; |
||||
} |
} |
||||
|
|
||||
function loadcryptex( $crossm, &$mask, &$corrects, &$language) |
public function loadcryptex( $crossm, &$mask, &$corrects, &$language) { |
||||
{ |
global $DB; |
||||
global $DB; |
|
||||
|
$questions = array(); |
||||
$questions = array(); |
$corrects = array(); |
||||
$corrects = array(); |
|
||||
|
$mask = str_repeat( '0', $crossm->cols * $crossm->rows); |
||||
$mask = str_repeat( '0', $crossm->cols * $crossm->rows); |
|
||||
|
if ($recs = $DB->get_records( 'game_queries', array( 'attemptid' => $crossm->id))) { |
||||
if ($recs = $DB->get_records( 'game_queries', array( 'attemptid' => $crossm->id))) |
foreach ($recs as $rec) { |
||||
{ |
if ($rec->questiontext == '') { |
||||
foreach ($recs as $rec) |
$rec->questiontext = ' '; |
||||
{ |
} |
||||
if( $rec->questiontext == ''){ |
$key = $this->gethash( $rec->questiontext).'-'.$rec->answertext.'-'.$rec->id; |
||||
$rec->questiontext = ' '; |
$questions[ $key] = $rec; |
||||
} |
|
||||
$key = $this->gethash( $rec->questiontext).'-'.$rec->answertext.'-'.$rec->id; |
$word = $rec->answertext; |
||||
$questions[ $key] = $rec; |
$pos = $crossm->cols * ($rec->row - 1) + ($rec->col - 1); |
||||
|
$len = game_strlen( $word); |
||||
$word = $rec->answertext; |
$found = ($rec->answertext == $rec->studentanswer); |
||||
$pos = $crossm->cols * ($rec->row-1)+($rec->col-1); |
|
||||
$len = game_strlen( $word); |
for ($i = 0; $i < $len; $i++) { |
||||
$found = ($rec->answertext == $rec->studentanswer); |
$c = ( $found ? '1' : '2'); |
||||
|
|
||||
for( $i=0; $i < $len; $i++) |
if (game_substr( $mask, $pos, 1) != '1') { |
||||
{ |
game_setchar( $mask, $pos, $c); |
||||
$c = ( $found ? '1' : '2'); |
} |
||||
|
|
||||
if( game_substr( $mask, $pos, 1) != '1'){ |
$pos += ($rec->horizontal ? 1 : $crossm->cols); |
||||
game_setchar( $mask, $pos, $c); |
} |
||||
} |
|
||||
|
if ($found) { |
||||
$pos += ($rec->horizontal ? 1 : $crossm->cols); |
$corrects[ $rec->id] = 1; |
||||
} |
} |
||||
|
|
||||
if( $found){ |
if ($language == '') { |
||||
$corrects[ $rec->id] = 1; |
$language = game_detectlanguage( $rec->answertext); |
||||
} |
} |
||||
|
} |
||||
if( $language == ''){ |
ksort( $questions); |
||||
$language = game_detectlanguage( $rec->answertext); |
} |
||||
} |
|
||||
} |
return $questions; |
||||
ksort( $questions); |
} |
||||
} |
|
||||
|
public function setwords( $answers, $maxcols, $reps) { |
||||
return $questions; |
return Cross::setwords( $answers, $maxcols, $reps); |
||||
} |
} |
||||
|
|
||||
|
public function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords) { |
||||
function setwords( $answers, $maxcols, $reps) |
if (!cross::computedata( $crossm, $crossd, $letters, $minwords, $maxwords)) { |
||||
{ |
return false; |
||||
return Cross::setwords( $answers, $maxcols, $reps); |
} |
||||
} |
|
||||
|
$letters = $this->computeletters( $crossm, $crossd); |
||||
function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords) |
|
||||
{ |
return true; |
||||
if( !cross::computedata( $crossm, $crossd, $letters, $minwords, $maxwords)){ |
} |
||||
return false; |
} |
||||
} |
|
||||
|
|
||||
$letters = $this->computeletters( $crossm, $crossd); |
|
||||
|
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
@ -1,8 +1,21 @@ |
|||||
<?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/>. |
||||
|
|
||||
require( "../../../config.php"); |
require( "../../../config.php"); |
||||
|
|
||||
|
|
||||
execute_sql("truncate TABLE {game_snakes_database}"); |
execute_sql("truncate TABLE {game_snakes_database}"); |
||||
|
|
||||
require( "importsnakes.php"); |
require( "importsnakes.php"); |
||||
|
@ -1,53 +1,63 @@ |
|||||
<?php // $Id: importsnakes.php,v 1.5 2012/07/25 11:16:05 bdaloukas Exp $
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
game_importsnakes(); |
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
function game_importsnakes() |
// it under the terms of the GNU General Public License as published by |
||||
{ |
// the Free Software Foundation, either version 3 of the License, or |
||||
global $DB; |
// (at your option) any later version. |
||||
|
// |
||||
if( $DB->count_records( 'game_snakes_database') != 0){ |
// Moodle is distributed in the hope that it will be useful, |
||||
return; |
// 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. |
||||
$newrec = new stdClass(); |
// |
||||
$newrec->name = '8x8 - 4 Snakes - 4 Ladders'; |
// You should have received a copy of the GNU General Public License |
||||
$newrec->cols = 8; |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
$newrec->rows = 8; |
|
||||
$newrec->fileboard = 'fidaki.jpg'; |
game_importsnakes(); |
||||
$newrec->direction = 1; |
|
||||
$newrec->headerx = 4; |
function game_importsnakes() { |
||||
$newrec->headery = 4; |
global $DB; |
||||
$newrec->footerx = 4; |
|
||||
$newrec->footery = 4; |
if ($DB->count_records( 'game_snakes_database') != 0) { |
||||
$newrec->width = 487; |
return; |
||||
$newrec->height = 487; |
} |
||||
$newrec->data = 'L3-18,S5-19,S8-27,L24-39,L29-53,S32-62,S41-58,L48-63'; |
|
||||
game_importsnakes_do( $newrec); |
$newrec = new stdClass(); |
||||
|
$newrec->name = '8x8 - 4 Snakes - 4 Ladders'; |
||||
$newrec = new stdClass(); |
$newrec->cols = 8; |
||||
$newrec->name = '6x6 - 3 Snakes - 3 Ladders'; |
$newrec->rows = 8; |
||||
$newrec->cols = 6; |
$newrec->fileboard = 'fidaki.jpg'; |
||||
$newrec->rows = 6; |
$newrec->direction = 1; |
||||
$newrec->fileboard = 'fidaki2.jpg'; |
$newrec->headerx = 4; |
||||
$newrec->direction = 1; |
$newrec->headery = 4; |
||||
$newrec->headerx = 8; |
$newrec->footerx = 4; |
||||
$newrec->headery = 8; |
$newrec->footery = 4; |
||||
$newrec->footerx = 8; |
$newrec->width = 487; |
||||
$newrec->footery = 8; |
$newrec->height = 487; |
||||
$newrec->width = 502; |
$newrec->data = 'L3-18,S5-19,S8-27,L24-39,L29-53,S32-62,S41-58,L48-63'; |
||||
$newrec->height = 436; |
game_importsnakes_do( $newrec); |
||||
$newrec->data = 'L2-25,S4-23,L8-18,S16-20,L19-29,S27-33'; |
|
||||
game_importsnakes_do( $newrec); |
$newrec = new stdClass(); |
||||
} |
$newrec->name = '6x6 - 3 Snakes - 3 Ladders'; |
||||
|
$newrec->cols = 6; |
||||
|
$newrec->rows = 6; |
||||
function game_importsnakes_do( $newrec) |
$newrec->fileboard = 'fidaki2.jpg'; |
||||
{ |
$newrec->direction = 1; |
||||
global $DB; |
$newrec->headerx = 8; |
||||
|
$newrec->headery = 8; |
||||
if( !$DB->insert_record( 'game_snakes_database', $newrec)){ |
$newrec->footerx = 8; |
||||
print_object( $newrec); |
$newrec->footery = 8; |
||||
print_error( "Can't insert to table game_snakes_database"); |
$newrec->width = 502; |
||||
} |
$newrec->height = 436; |
||||
} |
$newrec->data = 'L2-25,S4-23,L8-18,S16-20,L19-29,S27-33'; |
||||
|
game_importsnakes_do( $newrec); |
||||
|
} |
||||
|
|
||||
|
function game_importsnakes_do( $newrec) { |
||||
|
global $DB; |
||||
|
|
||||
|
if (!$DB->insert_record( 'game_snakes_database', $newrec)) { |
||||
|
print_error( "Can't insert to table game_snakes_database"); |
||||
|
} |
||||
|
} |
||||
|
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -1,107 +1,119 @@ |
|||||
<?php // $Id: picture.php,v 1.3 2010/07/26 00:13:32 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/>. |
||||
|
|
||||
require( '../../../config.php'); |
require( '../../../config.php'); |
||||
|
|
||||
$id = required_param('id', PARAM_INT); // Course Module ID |
$id = required_param('id', PARAM_INT); // Course Module ID. |
||||
$attemptid = required_param('id2', PARAM_INT); // Course Module ID |
$attemptid = required_param('id2', PARAM_INT); // Course Module ID. |
||||
|
|
||||
$foundcells = required_param('f', PARAM_SEQUENCE); //CSV |
$foundcells = required_param('f', PARAM_SEQUENCE); // CSV. |
||||
$cells = required_param('cells', PARAM_SEQUENCE); //CSV |
$cells = required_param('cells', PARAM_SEQUENCE); // CSV. |
||||
$filehash = required_param('p', PARAM_PATH); |
$filehash = required_param('p', PARAM_PATH); |
||||
$cols = required_param('cols', PARAM_INT); |
$cols = required_param('cols', PARAM_INT); |
||||
$rows = required_param('rows', PARAM_INT); |
$rows = required_param('rows', PARAM_INT); |
||||
$filenamenumbers = required_param('n', PARAM_PATH); //Path to numbers picture |
$filenamenumbers = required_param('n', PARAM_PATH); // Path to numbers picture. |
||||
create_image( $id, $attemptid, $foundcells, $cells, $filehash, $cols, $rows, $filenamenumbers); |
create_image( $id, $attemptid, $foundcells, $cells, $filehash, $cols, $rows, $filenamenumbers); |
||||
|
|
||||
function create_image( $id, $attemptid, $foundcells, $cells, $filehash, $cols, $rows, $filenamenumbers) |
function create_image( $id, $attemptid, $foundcells, $cells, $filehash, $cols, $rows, $filenamenumbers) { |
||||
{ |
|
||||
global $CFG; |
global $CFG; |
||||
|
|
||||
$a = explode( ',', $foundcells); |
$a = explode( ',', $foundcells); |
||||
$found = array(); |
$found = array(); |
||||
foreach( $a as $s){ |
foreach ($a as $s) { |
||||
$found[ $s] = 1; |
$found[ $s] = 1; |
||||
} |
} |
||||
|
|
||||
$a = explode( ',', $cells); |
$a = explode( ',', $cells); |
||||
$cells = array(); |
$cells = array(); |
||||
foreach( $a as $s){ |
foreach ($a as $s) { |
||||
$cells[ $s] = 1; |
$cells[ $s] = 1; |
||||
} |
} |
||||
|
|
||||
$file = get_file_storage()->get_file_by_hash( $filehash); |
$file = get_file_storage()->get_file_by_hash( $filehash); |
||||
$image = $file->get_imageinfo(); |
$image = $file->get_imageinfo(); |
||||
|
|
||||
if( $image === false){ |
if ($image === false) { |
||||
die("Aknown filehash $filehash"); |
die("Aknown filehash $filehash"); |
||||
return false; |
return false; |
||||
} |
} |
||||
$img_handle = imagecreatefromstring($file->get_content()); |
$imghandle = imagecreatefromstring($file->get_content()); |
||||
|
|
||||
$mime = $image[ 'mimetype']; |
$mime = $image[ 'mimetype']; |
||||
|
|
||||
$img_numbers = imageCreateFromPNG( $filenamenumbers); |
|
||||
$size_numbers = getimagesize ($filenamenumbers); |
|
||||
|
|
||||
Header ("Content-type: $mime"); |
$imgnumbers = imagecreatefrompng( $filenamenumbers); |
||||
|
$sizenumbers = getimagesize ($filenamenumbers); |
||||
$color = ImageColorAllocate ($img_handle, 100, 100, 100); |
|
||||
|
header("Content-type: $mime"); |
||||
|
|
||||
|
$color = imagecolorallocate( $imghandle, 100, 100, 100); |
||||
|
|
||||
$width = $image[ 'width']; |
$width = $image[ 'width']; |
||||
$height = $image[ 'height']; |
$height = $image[ 'height']; |
||||
$pos = 0; |
$pos = 0; |
||||
|
|
||||
$font = 1; |
$font = 1; |
||||
|
|
||||
for($y = 0; $y < $rows; $y++){ |
for ($y = 0; $y < $rows; $y++) { |
||||
for( $x=0; $x < $cols; $x++){ |
for ($x = 0; $x < $cols; $x++) { |
||||
$pos++; |
$pos++; |
||||
if( !array_key_exists( $pos, $found)){ |
if (!array_key_exists( $pos, $found)) { |
||||
$x1 = $x * $width / $cols; |
$x1 = $x * $width / $cols; |
||||
$y1 = $y * $height / $rows; |
$y1 = $y * $height / $rows; |
||||
imagefilledrectangle( $img_handle, $x1, $y1, $x1 + $width / $cols, $y1 + $height / $rows, $color); |
imagefilledrectangle( $imghandle, $x1, $y1, $x1 + $width / $cols, $y1 + $height / $rows, $color); |
||||
|
|
||||
if( array_key_exists( $pos, $cells)){ |
if (array_key_exists( $pos, $cells)) { |
||||
shownumber( $img_handle, $img_numbers, $pos, $x1 , $y1, $width / $cols, $height / $rows, $size_numbers); |
shownumber( $imghandle, $imgnumbers, $pos, $x1 , $y1, $width / $cols, $height / $rows, $sizenumbers); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
switch( $mime){ |
switch ($mime) { |
||||
case 'image/png': |
case 'image/png': |
||||
ImagePng ($img_handle); |
imagepng ($imghandle); |
||||
break; |
break; |
||||
case 'image/jpeg': |
case 'image/jpeg': |
||||
ImageJpeg ($img_handle); |
imagejpeg ($imghandle); |
||||
break; |
break; |
||||
case 'image/gif': |
case 'image/gif': |
||||
ImageGif ($img_handle); |
imagegif ($imghandle); |
||||
break; |
break; |
||||
default: |
default: |
||||
die('Aknown mime type $mime'); |
die('Aknown mime type $mime'); |
||||
return false; |
return false; |
||||
} |
} |
||||
|
|
||||
ImageDestroy ($img_handle); |
imagedestroy ($imghandle); |
||||
} |
} |
||||
|
|
||||
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){ |
if ($number < 10) { |
||||
$width_number = $size_numbers[ 0] / 10; |
$widthnumber = $sizenumbers[ 0] / 10; |
||||
$dstX = $x1 + $width / 3; |
$dstx = $x1 + $width / 3; |
||||
$dstY = $y1 + $height / 3; |
$dsty = $y1 + $height / 3; |
||||
$srcX = $number * $size_numbers[ 0] / 10; |
$srcx = $number * $sizenumbers[ 0] / 10; |
||||
$srcW = $size_numbers[ 0]/10; |
$srcw = $sizenumbers[ 0] / 10; |
||||
$srcH = $size_numbers[ 1]; |
$srch = $sizenumbers[ 1]; |
||||
$dstW = $width / 10; |
$dstw = $width / 10; |
||||
$dstH = $dstW * $srcH / $srcW; |
$dsth = $dstw * $srch / $srcw; |
||||
imagecopyresized( $img_handle, $img_numbers, $dstX, $dstY, $srcX, 0, $dstW, $dstH, $srcW, $srcH); |
imagecopyresized( $imghandle, $imgnumbers, $dstx, $dsty, $srcx, 0, $dstw, $dsth, $srcw, $srchh); |
||||
}else |
} else { |
||||
{ |
|
||||
$number1 = floor( $number / 10); |
$number1 = floor( $number / 10); |
||||
$number2 = $number % 10; |
$number2 = $number % 10; |
||||
shownumber( $img_handle, $img_numbers, $number1, $x1-$width/20, $y1, $width, $height, $size_numbers); |
shownumber( $imghandle, $imgnumbers, $number1, $x1 - $width / 20, $y1, $width, $height, $sizenumbers); |
||||
shownumber( $img_handle, $img_numbers, $number2, $x1+$width/20, $y1, $width, $height, $size_numbers); |
shownumber( $imghandle, $imgnumbers, $number2, $x1 + $width / 20, $y1, $width, $height, $sizenumbers); |
||||
} |
} |
||||
} |
} |
||||
|
@ -1,486 +1,498 @@ |
|||||
<?php // $Id: play.php,v 1.19 2012/08/15 09:26:55 bdaloukas Exp $
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
// This file plays the game Hidden Picture |
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
function game_hiddenpicture_continue( $id, $game, $attempt, $hiddenpicture, $context) |
// it under the terms of the GNU General Public License as published by |
||||
{ |
// the Free Software Foundation, either version 3 of the License, or |
||||
global $DB, $USER; |
// (at your option) any later version. |
||||
|
// |
||||
if( $attempt != false and $hiddenpicture != false){ |
// Moodle is distributed in the hope that it will be useful, |
||||
//Continue a previous attempt |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
return game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
} |
// GNU General Public License for more details. |
||||
|
// |
||||
if( $attempt == false){ |
// You should have received a copy of the GNU General Public License |
||||
//Start a new attempt |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
$attempt = game_addattempt( $game); |
|
||||
} |
// This file plays the game Hidden Picture. |
||||
|
|
||||
$cols = $game->param1; |
function game_hiddenpicture_continue( $id, $game, $attempt, $hiddenpicture, $context) { |
||||
$rows = $game->param2; |
global $DB, $USER; |
||||
if( $cols == 0){ |
|
||||
print_error( get_string( 'hiddenpicture_nocols', 'game')); |
if ($attempt != false and $hiddenpicture != false) { |
||||
} |
// Continue a previous attempt. |
||||
if( $rows == 0){ |
return game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
||||
print_error( get_string( 'hiddenpicture_norows', 'game')); |
} |
||||
} |
|
||||
|
if ($attempt == false) { |
||||
//new attempt |
// Start a new attempt. |
||||
$n = $game->param1 * $game->param2; |
$attempt = game_addattempt( $game); |
||||
$recs = game_questions_selectrandom( $game, CONST_GAME_TRIES_REPETITION*$n); |
} |
||||
$selected_recs = game_select_from_repetitions( $game, $recs, $n); |
|
||||
|
$cols = $game->param1; |
||||
$newrec = game_hiddenpicture_selectglossaryentry( $game, $attempt); |
$rows = $game->param2; |
||||
|
if ($cols == 0) { |
||||
if( $recs === false){ |
print_error( get_string( 'hiddenpicture_nocols', 'game')); |
||||
print_error( get_string( 'no_questions', 'game')); |
} |
||||
} |
if ($rows == 0) { |
||||
|
print_error( get_string( 'hiddenpicture_norows', 'game')); |
||||
$positions = array(); |
} |
||||
$pos=1; |
|
||||
for($col=0; $col < $cols; $col++){ |
// New attempt. |
||||
for( $row=0; $row < $rows; $row++){ |
$n = $game->param1 * $game->param2; |
||||
$positions[] = $pos++; |
$recs = game_questions_selectrandom( $game, CONST_GAME_TRIES_REPETITION * $n); |
||||
} |
$selectedrecs = game_select_from_repetitions( $game, $recs, $n); |
||||
} |
|
||||
$i = 0; |
$newrec = game_hiddenpicture_selectglossaryentry( $game, $attempt); |
||||
$field = ($game->sourcemodule == 'glossary' ? 'glossaryentryid' : 'questionid'); |
|
||||
foreach( $recs as $rec) |
if ($recs === false) { |
||||
{ |
print_error( get_string( 'no_questions', 'game')); |
||||
if( $game->sourcemodule == 'glossary') |
} |
||||
$key = $rec->glossaryentryid; |
|
||||
else |
$positions = array(); |
||||
$key = $rec->questionid; |
$pos = 1; |
||||
|
for ($col = 0; $col < $cols; $col++) { |
||||
if( !array_key_exists( $key, $selected_recs)) |
for ($row = 0; $row < $rows; $row++) { |
||||
continue; |
$positions[] = $pos++; |
||||
|
} |
||||
$query = new stdClass(); |
} |
||||
$query->attemptid = $newrec->id; |
$i = 0; |
||||
$query->gamekind = $game->gamekind; |
$field = ($game->sourcemodule == 'glossary' ? 'glossaryentryid' : 'questionid'); |
||||
$query->gameid = $game->id; |
foreach ($recs as $rec) { |
||||
$query->userid = $USER->id; |
if ($game->sourcemodule == 'glossary') { |
||||
|
$key = $rec->glossaryentryid; |
||||
$pos = array_rand( $positions); |
} else { |
||||
$query->col = $positions[ $pos]; |
$key = $rec->questionid; |
||||
unset( $positions[ $pos]); |
} |
||||
|
|
||||
$query->sourcemodule = $game->sourcemodule; |
if (!array_key_exists( $key, $selectedrecs)) { |
||||
$query->questionid = $rec->questionid; |
continue; |
||||
$query->glossaryentryid = $rec->glossaryentryid; |
} |
||||
$query->score = 0; |
|
||||
if( ($query->id = $DB->insert_record( 'game_queries', $query)) == 0){ |
$query = new stdClass(); |
||||
print_error( 'error inserting in game_queries'); |
$query->attemptid = $newrec->id; |
||||
} |
$query->gamekind = $game->gamekind; |
||||
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
$query->gameid = $game->id; |
||||
} |
$query->userid = $USER->id; |
||||
|
|
||||
//The score is zero |
$pos = array_rand( $positions); |
||||
game_updateattempts( $game, $attempt, 0, 0); |
$query->col = $positions[ $pos]; |
||||
|
unset( $positions[ $pos]); |
||||
game_hiddenpicture_play( $id, $game, $attempt, $newrec, false, $context); |
|
||||
} |
$query->sourcemodule = $game->sourcemodule; |
||||
|
$query->questionid = $rec->questionid; |
||||
//Create the game_hiddenpicture record |
$query->glossaryentryid = $rec->glossaryentryid; |
||||
function game_hiddenpicture_selectglossaryentry( $game, $attempt){ |
$query->score = 0; |
||||
global $CFG, $DB, $USER; |
if (($query->id = $DB->insert_record( 'game_queries', $query)) == 0) { |
||||
|
print_error( 'error inserting in game_queries'); |
||||
srand( (double)microtime()*1000000); |
} |
||||
|
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
||||
if( $game->glossaryid2 == 0){ |
} |
||||
print_error( get_string( 'must_select_glossary', 'game')); |
|
||||
} |
// The score is zero. |
||||
$select = "ge.glossaryid={$game->glossaryid2}"; |
game_updateattempts( $game, $attempt, 0, 0); |
||||
$table = '{glossary_entries} ge'; |
|
||||
if( $game->glossarycategoryid2){ |
game_hiddenpicture_play( $id, $game, $attempt, $newrec, false, $context); |
||||
$table .= ",{glossary_entries_categories} gec"; |
} |
||||
$select .= " AND gec.entryid = ge.id AND gec.categoryid = {$game->glossarycategoryid2}"; |
|
||||
} |
// Create the game_hiddenpicture record. |
||||
if( $game->param7 == 0){ |
function game_hiddenpicture_selectglossaryentry( $game, $attempt) { |
||||
//Allow spaces |
global $CFG, $DB, $USER; |
||||
$select .= " AND concept NOT LIKE '% %'"; |
|
||||
} |
srand( (double)microtime() * 1000000); |
||||
|
|
||||
$sql = "SELECT ge.id,attachment FROM $table WHERE $select"; |
if ($game->glossaryid2 == 0) { |
||||
if( ($recs=$DB->get_records_sql( $sql)) == false){ |
print_error( get_string( 'must_select_glossary', 'game')); |
||||
$a->name = "'".$DB->get_field('glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
} |
||||
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
$select = "ge.glossaryid={$game->glossaryid2}"; |
||||
return false; |
$table = '{glossary_entries} ge'; |
||||
} |
if ($game->glossarycategoryid2) { |
||||
$ids = array(); |
$table .= ",{glossary_entries_categories} gec"; |
||||
$keys = array(); |
$select .= " AND gec.entryid = ge.id AND gec.categoryid = {$game->glossarycategoryid2}"; |
||||
$fs = get_file_storage(); |
} |
||||
$cmg = get_coursemodule_from_instance('glossary', $game->glossaryid2, $game->course); |
if ($game->param7 == 0) { |
||||
$context = game_get_context_module_instance( $cmg->id); |
// Allow spaces. |
||||
foreach( $recs as $rec){ |
$select .= " AND concept NOT LIKE '% %'"; |
||||
$files = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $rec->id, "timemodified", false); |
} |
||||
if( $files) |
|
||||
{ |
$sql = "SELECT ge.id,attachment FROM $table WHERE $select"; |
||||
foreach( $files as $key => $file) |
if (($recs = $DB->get_records_sql( $sql)) == false) { |
||||
{ |
$a->name = "'".$DB->get_field('glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
||||
$s = strtoupper( $file->get_filename()); |
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
||||
$s = substr( $s, -4); |
return false; |
||||
if( $s == '.GIF' or $s == '.JPG' or $s == '.PNG'){ |
} |
||||
$ids[] = $rec->id; |
$ids = array(); |
||||
$keys[] = $file->get_pathnamehash(); |
$keys = array(); |
||||
} |
$fs = get_file_storage(); |
||||
} |
$cmg = get_coursemodule_from_instance('glossary', $game->glossaryid2, $game->course); |
||||
} |
$context = game_get_context_module_instance( $cmg->id); |
||||
} |
foreach ($recs as $rec) { |
||||
if( count( $ids) == 0){ |
$files = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $rec->id, "timemodified", false); |
||||
$a->name = "'".$DB->get_field( 'glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
if ($files) { |
||||
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
foreach ($files as $key => $file) { |
||||
return false; |
$s = strtoupper( $file->get_filename()); |
||||
} |
$s = substr( $s, -4); |
||||
|
if ($s == '.GIF' or $s == '.JPG' or $s == '.PNG') { |
||||
//Have to select randomly one glossaryentry |
$ids[] = $rec->id; |
||||
$poss = array(); |
$keys[] = $file->get_pathnamehash(); |
||||
for($i=0;$i<count($ids);$i++){ |
} |
||||
$poss[] = $i; |
} |
||||
} |
} |
||||
shuffle( $poss); |
} |
||||
$min_num = 0; |
if (count( $ids) == 0) { |
||||
$attachement = ''; |
$a->name = "'".$DB->get_field( 'glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
||||
for($i=0;$i<count($ids);$i++){ |
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
||||
$pos = $poss[ $i]; |
return false; |
||||
$tempid = $ids[ $pos]; |
} |
||||
$a = array( 'gameid' => $game->id, 'userid' => $USER->id, 'questionid' => 0, 'glossaryentryid' => $tempid); |
|
||||
if(($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions r')) != false){ |
// Have to select randomly one glossaryentry. |
||||
if( ($rec2->r < $min_num) or ($min_num == 0)){ |
$poss = array(); |
||||
$min_num = $rec2->r; |
for ($i = 0; $i < count($ids); $i++) { |
||||
$glossaryentryid = $tempid; |
$poss[] = $i; |
||||
$attachement = $keys[ $pos]; |
} |
||||
} |
shuffle( $poss); |
||||
} |
$minnum = 0; |
||||
else{ |
$attachement = ''; |
||||
$glossaryentryid = $tempid; |
for ($i = 0; $i < count($ids); $i++) { |
||||
$attachement = $keys[ $pos]; |
$pos = $poss[ $i]; |
||||
break; |
$tempid = $ids[ $pos]; |
||||
} |
$a = array( 'gameid' => $game->id, 'userid' => $USER->id, 'questionid' => 0, 'glossaryentryid' => $tempid); |
||||
} |
if (($rec2 = $DB->get_record('game_repetitions', $a, 'id,repetitions r')) != false) { |
||||
|
if (($rec2->r < $minnum) or ($minnum == 0)) { |
||||
$sql = 'SELECT id, concept as answertext, definition as questiontext, id as glossaryentryid, 0 as questionid, glossaryid, attachment'. |
$minnum = $rec2->r; |
||||
' FROM {glossary_entries} WHERE id = '.$glossaryentryid; |
$glossaryentryid = $tempid; |
||||
if( ($rec = $DB->get_record_sql( $sql)) == false) |
$attachement = $keys[ $pos]; |
||||
return false; |
} |
||||
|
} else { |
||||
$query = new stdClass(); |
$glossaryentryid = $tempid; |
||||
$query->attemptid = $attempt->id; |
$attachement = $keys[ $pos]; |
||||
$query->gamekind = $game->gamekind; |
break; |
||||
$query->gameid = $game->id; |
} |
||||
$query->userid = $USER->id; |
} |
||||
|
|
||||
$query->col = 0; |
$sql = 'SELECT id, concept as answertext, definition as questiontext,'. |
||||
$query->sourcemodule = 'glossary'; |
' id as glossaryentryid, 0 as questionid, glossaryid, attachment'. |
||||
$query->questionid = 0; |
' FROM {glossary_entries} WHERE id = '.$glossaryentryid; |
||||
$query->glossaryentryid = $rec->glossaryentryid; |
if (($rec = $DB->get_record_sql( $sql)) == false) { |
||||
$query->attachment = $attachement; |
return false; |
||||
$query->questiontext = $rec->questiontext; |
} |
||||
$query->answertext = $rec->answertext; |
$query = new stdClass(); |
||||
$query->score = 0; |
$query->attemptid = $attempt->id; |
||||
if( ($query->id = $DB->insert_record( 'game_queries', $query)) == 0){ |
$query->gamekind = $game->gamekind; |
||||
print_error( 'Error inserting in game_queries'); |
$query->gameid = $game->id; |
||||
} |
$query->userid = $USER->id; |
||||
$newrec = new stdClass(); |
|
||||
$newrec->id = $attempt->id; |
$query->col = 0; |
||||
$newrec->correct = 0; |
$query->sourcemodule = 'glossary'; |
||||
if( !game_insert_record( 'game_hiddenpicture', $newrec)){ |
$query->questionid = 0; |
||||
print_error( 'Error inserting in game_hiddenpicture'); |
$query->glossaryentryid = $rec->glossaryentryid; |
||||
} |
$query->attachment = $attachement; |
||||
|
$query->questiontext = $rec->questiontext; |
||||
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
$query->answertext = $rec->answertext; |
||||
|
$query->score = 0; |
||||
return $newrec; |
if (($query->id = $DB->insert_record( 'game_queries', $query)) == 0) { |
||||
} |
print_error( 'Error inserting in game_queries'); |
||||
|
} |
||||
function game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, $showsolution, $context) |
$newrec = new stdClass(); |
||||
{ |
$newrec->id = $attempt->id; |
||||
if( $game->toptext != ''){ |
$newrec->correct = 0; |
||||
echo $game->toptext.'<br>'; |
if (!game_insert_record( 'game_hiddenpicture', $newrec)) { |
||||
} |
print_error( 'Error inserting in game_hiddenpicture'); |
||||
|
} |
||||
//Show picture |
|
||||
$offsetquestions = game_sudoku_compute_offsetquestions( $game->sourcemodule, $attempt, $numbers, $correctquestions); |
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
||||
unset( $offsetquestions[ 0]); |
|
||||
|
return $newrec; |
||||
game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, $offsetquestions, $correctquestions, $id, $attempt, $showsolution); |
} |
||||
|
|
||||
//Show questions |
function game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, $showsolution, $context) { |
||||
$onlyshow = false; |
if ($game->toptext != '') { |
||||
$showsolution = false; |
echo $game->toptext.'<br>'; |
||||
|
} |
||||
switch( $game->sourcemodule) |
|
||||
{ |
// Show picture. |
||||
case 'quiz': |
$offsetquestions = game_sudoku_compute_offsetquestions( $game->sourcemodule, $attempt, $numbers, $correctquestions); |
||||
case 'question': |
unset( $offsetquestions[ 0]); |
||||
game_sudoku_showquestions_quiz( $id, $game, $attempt, $hiddenpicture, $offsetquestions, $numbers, $correctquestions, $onlyshow, $showsolution, $context); |
|
||||
break; |
game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, |
||||
case 'glossary': |
$offsetquestions, $correctquestions, $id, $attempt, $showsolution); |
||||
game_sudoku_showquestions_glossary( $id, $game, $attempt, $hiddenpicture, $offsetquestions, $numbers, $correctquestions, $onlyshow, $showsolution); |
|
||||
break; |
// Show questions. |
||||
} |
$onlyshow = false; |
||||
|
$showsolution = false; |
||||
if( $game->bottomtext != ''){ |
|
||||
echo '<br><br>'.$game->bottomtext; |
switch ($game->sourcemodule) { |
||||
} |
case 'quiz': |
||||
} |
case 'question': |
||||
|
game_sudoku_showquestions_quiz( $id, $game, $attempt, $hiddenpicture, $offsetquestions, |
||||
function game_hidden_picture_computescore( $game, $hiddenpicture){ |
$numbers, $correctquestions, $onlyshow, $showsolution, $context); |
||||
$correct = $hiddenpicture->correct; |
break; |
||||
if( $hiddenpicture->found){ |
case 'glossary': |
||||
$correct++; |
game_sudoku_showquestions_glossary( $id, $game, $attempt, $hiddenpicture, |
||||
} |
$offsetquestions, $numbers, $correctquestions, $onlyshow, $showsolution); |
||||
$remaining = $game->param1 * $game->param2 - $hiddenpicture->correct; |
break; |
||||
$div2 = $correct + $hiddenpicture->wrong + $remaining; |
} |
||||
if( $hiddenpicture->found){ |
|
||||
$percent = ($correct + $remaining) / $div2; |
if ($game->bottomtext != '') { |
||||
}else{ |
echo '<br><br>'.$game->bottomtext; |
||||
$percent = $correct / $div2; |
} |
||||
} |
} |
||||
|
|
||||
return $percent; |
function game_hidden_picture_computescore( $game, $hiddenpicture) { |
||||
} |
$correct = $hiddenpicture->correct; |
||||
|
if ($hiddenpicture->found) { |
||||
function game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, $offsetquestions, $correctquestions){ |
$correct++; |
||||
global $DB; |
} |
||||
|
$remaining = $game->param1 * $game->param2 - $hiddenpicture->correct; |
||||
$foundcells=''; |
$div2 = $correct + $hiddenpicture->wrong + $remaining; |
||||
foreach( $correctquestions as $key => $val){ |
if ($hiddenpicture->found) { |
||||
$foundcells .= ','.$key; |
$percent = ($correct + $remaining) / $div2; |
||||
} |
} else { |
||||
$cells=''; |
$percent = $correct / $div2; |
||||
foreach( $offsetquestions as $key => $val){ |
} |
||||
if( $key != 0){ |
|
||||
$cells .= ','.$key; |
return $percent; |
||||
} |
} |
||||
} |
|
||||
|
function game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, |
||||
$query = $DB->get_record_select( 'game_queries', "attemptid=$hiddenpicture->id AND col=0", null, 'id,glossaryentryid,attachment,questiontext'); |
$offsetquestions, $correctquestions) { |
||||
|
global $DB; |
||||
//Grade |
|
||||
echo "<br/>".get_string( 'grade', 'game').' : '.round( $attempt->score * 100).' %'; |
$foundcells = ''; |
||||
|
foreach ($correctquestions as $key => $val) { |
||||
game_hiddenpicture_showquestion_glossary( $game, $id, $query); |
$foundcells .= ','.$key; |
||||
|
} |
||||
$cells = substr( $cells, 1); |
$cells = ''; |
||||
$foundcells = substr( $foundcells, 1); |
foreach ($offsetquestions as $key => $val) { |
||||
game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, true); |
if ($key != 0) { |
||||
} |
$cells .= ','.$key; |
||||
|
} |
||||
function game_hiddenpicture_showquestion_glossary( $game, $id, $query) |
} |
||||
{ |
|
||||
global $CFG, $DB; |
$query = $DB->get_record_select( 'game_queries', "attemptid=$hiddenpicture->id AND col=0", |
||||
|
null, 'id,glossaryentryid,attachment,questiontext'); |
||||
$entry = $DB->get_record( 'glossary_entries', array( 'id' => $query->glossaryentryid)); |
|
||||
|
// Grade. |
||||
/// Start the form |
echo "<br/>".get_string( 'grade', 'game').' : '.round( $attempt->score * 100).' %'; |
||||
echo '<br>'; |
|
||||
echo "<form id=\"responseform\" method=\"post\" action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; |
game_hiddenpicture_showquestion_glossary( $game, $id, $query); |
||||
echo "<center><input type=\"submit\" name=\"finishattempt\" value=\"".get_string('hiddenpicture_mainsubmit', 'game')."\"></center>\n"; |
|
||||
|
$cells = substr( $cells, 1); |
||||
// Add a hidden field with the queryid |
$foundcells = substr( $foundcells, 1); |
||||
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; |
game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, true); |
||||
echo '<input type="hidden" name="action" value="hiddenpicturecheckg" />'; |
} |
||||
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; |
|
||||
|
function game_hiddenpicture_showquestion_glossary( $game, $id, $query) { |
||||
// Add a hidden field with glossaryentryid |
global $CFG, $DB; |
||||
echo '<input type="hidden" name="glossaryentryid" value="'.$query->glossaryentryid."\" />\n"; |
|
||||
|
$entry = $DB->get_record( 'glossary_entries', array( 'id' => $query->glossaryentryid)); |
||||
$temp = $game->glossaryid; |
|
||||
$game->glossaryid = $game->glossaryid2; |
// Start the form. |
||||
echo game_show_query( $game, $query, $entry->definition); |
echo '<br>'; |
||||
$game->glossaryid = $temp; |
echo "<form id=\"responseform\" method=\"post\" ". |
||||
|
"action=\"{$CFG->wwwroot}/mod/game/attempt.php\" onclick=\"this.autocomplete='off'\">\n"; |
||||
echo get_string( 'answer').': '; |
echo "<center><input type=\"submit\" name=\"finishattempt\" ". |
||||
echo "<input type=\"text\" name=\"answer\" size=30 /><br>"; |
"value=\"".get_string('hiddenpicture_mainsubmit', 'game')."\"></center>\n"; |
||||
|
|
||||
echo "</form><br>\n"; |
// Add a hidden field with the queryid. |
||||
} |
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; |
||||
|
echo '<input type="hidden" name="action" value="hiddenpicturecheckg" />'; |
||||
function game_hiddenpicture_check_questions( $id, $game, &$attempt, &$hiddenpicture, $finishattempt) |
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; |
||||
{ |
|
||||
global $QTYPES, $DB; |
// Add a hidden field with glossaryentryid. |
||||
|
echo '<input type="hidden" name="glossaryentryid" value="'.$query->glossaryentryid."\" />\n"; |
||||
$responses = data_submitted(); |
|
||||
|
$temp = $game->glossaryid; |
||||
$offsetquestions = game_sudoku_compute_offsetquestions( $game->sourcemodule, $attempt, $numbers, $correctquestions); |
$game->glossaryid = $game->glossaryid2; |
||||
|
echo game_show_query( $game, $query, $entry->definition); |
||||
$questionlist = game_sudoku_getquestionlist( $offsetquestions); |
$game->glossaryid = $temp; |
||||
|
|
||||
$questions = game_sudoku_getquestions( $questionlist); |
echo get_string( 'answer').': '; |
||||
|
echo "<input type=\"text\" name=\"answer\" size=30 /><br>"; |
||||
$actions = question_extract_responses($questions, $responses, QUESTION_EVENTSUBMIT); |
|
||||
|
echo "</form><br>\n"; |
||||
$correct = $wrong = 0; |
} |
||||
foreach($questions as $question) { |
|
||||
if( !array_key_exists( $question->id, $actions)){ |
function game_hiddenpicture_check_questions( $id, $game, &$attempt, &$hiddenpicture, $finishattempt) { |
||||
//no answered |
global $QTYPES, $DB; |
||||
continue; |
|
||||
} |
$responses = data_submitted(); |
||||
unset( $state); |
|
||||
unset( $cmoptions); |
$offsetquestions = game_sudoku_compute_offsetquestions( $game->sourcemodule, $attempt, $numbers, $correctquestions); |
||||
$question->maxgrade = 100; |
|
||||
$state->responses = $actions[ $question->id]->responses; |
$questionlist = game_sudoku_getquestionlist( $offsetquestions); |
||||
$state->event = QUESTION_EVENTGRADE; |
|
||||
|
$questions = game_sudoku_getquestions( $questionlist); |
||||
$cmoptions = array(); |
|
||||
$QTYPES[$question->qtype]->grade_responses( $question, $state, $cmoptions); |
$actions = question_extract_responses($questions, $responses, QUESTION_EVENTSUBMIT); |
||||
|
|
||||
unset( $query); |
$correct = $wrong = 0; |
||||
|
foreach ($questions as $question) { |
||||
$select = "attemptid=$attempt->id"; |
if (!array_key_exists( $question->id, $actions)) { |
||||
$select .= " AND questionid=$question->id"; |
// No answered. |
||||
if( ($query->id = $DB->get_field_select( 'game_queries', 'id', $select)) == 0){ |
continue; |
||||
print_error("problem game_hiddenpicture_check_questions (select=$select)"); |
} |
||||
} |
unset( $state); |
||||
|
unset( $cmoptions); |
||||
$answertext = $state->responses[ '']; |
$question->maxgrade = 100; |
||||
if( $answertext != ''){ |
$state->responses = $actions[ $question->id]->responses; |
||||
$grade = $state->raw_grade; |
$state->event = QUESTION_EVENTGRADE; |
||||
if( $grade < 50){ |
|
||||
//wrong answer |
$cmoptions = array(); |
||||
game_update_queries( $game, $attempt, $query, $grade/100, $answertext); |
$QTYPES[$question->qtype]->grade_responses( $question, $state, $cmoptions); |
||||
$wrong++; |
|
||||
}else{ |
unset( $query); |
||||
//correct answer |
|
||||
game_update_queries( $game, $attempt, $query, 1, $answertext); |
$select = "attemptid=$attempt->id"; |
||||
$correct++; |
$select .= " AND questionid=$question->id"; |
||||
} |
if (($query->id = $DB->get_field_select( 'game_queries', 'id', $select)) == 0) { |
||||
} |
print_error("problem game_hiddenpicture_check_questions (select=$select)"); |
||||
} |
} |
||||
|
|
||||
$hiddenpicture->correct += $correct; |
$answertext = $state->responses[ '']; |
||||
$hiddenpicture->wrong += $wrong; |
if ($answertext != '') { |
||||
|
$grade = $state->raw_grade; |
||||
if( !$DB->update_record( 'game_hiddenpicture', $hiddenpicture)){ |
if ($grade < 50) { |
||||
print_error( 'game_hiddenpicture_check_questions: error updating in game_hiddenpicture'); |
// Wrong answer. |
||||
} |
game_update_queries( $game, $attempt, $query, $grade / 100, $answertext); |
||||
|
$wrong++; |
||||
$attempt->score = game_hidden_picture_computescore( $game, $hiddenpicture); |
} else { |
||||
if( !$DB->update_record( 'game_attempts', $attempt)){ |
// Correct answer. |
||||
print_error( 'game_hiddenpicture_check_questions: error updating in game_attempt'); |
game_update_queries( $game, $attempt, $query, 1, $answertext); |
||||
} |
$correct++; |
||||
|
} |
||||
game_sudoku_check_last( $id, $game, $attempt, $hiddenpicture, $finishattempt); |
} |
||||
|
} |
||||
return true; |
|
||||
} |
$hiddenpicture->correct += $correct; |
||||
|
$hiddenpicture->wrong += $wrong; |
||||
function game_hiddenpicture_check_mainquestion( $id, $game, &$attempt, &$hiddenpicture, $finishattempt, $context) |
|
||||
{ |
if (!$DB->update_record( 'game_hiddenpicture', $hiddenpicture)) { |
||||
global $QTYPES, $CFG, $DB; |
print_error( 'game_hiddenpicture_check_questions: error updating in game_hiddenpicture'); |
||||
|
} |
||||
$responses = data_submitted(); |
|
||||
|
$attempt->score = game_hidden_picture_computescore( $game, $hiddenpicture); |
||||
$glossaryentryid = $responses->glossaryentryid; |
if (!$DB->update_record( 'game_attempts', $attempt)) { |
||||
$queryid = $responses->queryid; |
print_error( 'game_hiddenpicture_check_questions: error updating in game_attempt'); |
||||
|
} |
||||
// Load the glossary entry |
|
||||
if (!($entry = $DB->get_record( 'glossary_entries', array( 'id' => $glossaryentryid)))) { |
game_sudoku_check_last( $id, $game, $attempt, $hiddenpicture, $finishattempt); |
||||
print_error( get_string( 'noglossaryentriesfound', 'game')); |
|
||||
} |
return true; |
||||
$answer = $responses->answer; |
} |
||||
$correct = false; |
|
||||
if( $answer != ''){ |
function game_hiddenpicture_check_mainquestion( $id, $game, &$attempt, &$hiddenpicture, $finishattempt, $context) { |
||||
if( game_upper( $entry->concept) == game_upper( $answer)){ |
global $QTYPES, $CFG, $DB; |
||||
$correct = true; |
|
||||
} |
$responses = data_submitted(); |
||||
} |
|
||||
|
$glossaryentryid = $responses->glossaryentryid; |
||||
// Load the query |
$queryid = $responses->queryid; |
||||
if (!($query = $DB->get_record( 'game_queries', array( 'id' => $queryid)))) { |
|
||||
print_error( "The query $queryid not found"); |
// Load the glossary entry. |
||||
} |
if (!($entry = $DB->get_record( 'glossary_entries', array( 'id' => $glossaryentryid)))) { |
||||
|
print_error( get_string( 'noglossaryentriesfound', 'game')); |
||||
game_update_queries( $game, $attempt, $query, $correct, $answer); |
} |
||||
|
$answer = $responses->answer; |
||||
if( $correct){ |
$correct = false; |
||||
$hiddenpicture->found = 1; |
if ($answer != '') { |
||||
}else{ |
if (game_upper( $entry->concept) == game_upper( $answer)) { |
||||
$hiddenpicture->wrong++; |
$correct = true; |
||||
} |
} |
||||
if( !$DB->update_record( 'game_hiddenpicture', $hiddenpicture)){ |
} |
||||
print_error( 'game_hiddenpicture_check_mainquestion: error updating in game_hiddenpicture'); |
|
||||
} |
// Load the query. |
||||
|
if (!($query = $DB->get_record( 'game_queries', array( 'id' => $queryid)))) { |
||||
$score = game_hidden_picture_computescore( $game, $hiddenpicture); |
print_error( "The query $queryid not found"); |
||||
game_updateattempts( $game, $attempt, $score, $correct); |
} |
||||
|
|
||||
if( $correct == false){ |
game_update_queries( $game, $attempt, $query, $correct, $answer); |
||||
game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
|
||||
return true; |
if ($correct) { |
||||
} |
$hiddenpicture->found = 1; |
||||
|
} else { |
||||
//Finish the game |
$hiddenpicture->wrong++; |
||||
$query = $DB->get_record_select( 'game_queries', "attemptid=$hiddenpicture->id AND col=0", null, 'id,glossaryentryid,attachment,questiontext'); |
} |
||||
game_showpicture( $id, $game, $attempt, $query, '', '', false); |
if (!$DB->update_record( 'game_hiddenpicture', $hiddenpicture)) { |
||||
echo '<p><BR/><font size="5" color="green">'.get_string( 'win', 'game').'</font><BR/><BR/></p>'; |
print_error( 'game_hiddenpicture_check_mainquestion: error updating in game_hiddenpicture'); |
||||
global $CFG; |
} |
||||
|
|
||||
echo '<br/>'; |
$score = game_hidden_picture_computescore( $game, $hiddenpicture); |
||||
|
game_updateattempts( $game, $attempt, $score, $correct); |
||||
echo "<a href=\"$CFG->wwwroot/mod/game/attempt.php?id=$id\">"; |
|
||||
echo get_string( 'nextgame', 'game').'</a> '; |
if ($correct == false) { |
||||
|
game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
||||
if (! $cm = $DB->get_record( 'course_modules', array( 'id' => $id))) { |
return true; |
||||
print_error( "Course Module ID was incorrect id=$id"); |
} |
||||
} |
|
||||
|
// Finish the game. |
||||
echo "<a href=\"{$CFG->wwwroot}/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> '; |
$query = $DB->get_record_select( 'game_queries', "attemptid=$hiddenpicture->id AND col=0", |
||||
|
null, 'id,glossaryentryid,attachment,questiontext'); |
||||
return false; |
game_showpicture( $id, $game, $attempt, $query, '', '', false); |
||||
} |
echo '<p><br/><font size="5" color="green">'.get_string( 'win', 'game').'</font><BR/><BR/></p>'; |
||||
|
global $CFG; |
||||
function game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, $usemap) |
|
||||
{ |
echo '<br/>'; |
||||
global $CFG; |
|
||||
|
echo "<a href=\"$CFG->wwwroot/mod/game/attempt.php?id=$id\">"; |
||||
$filenamenumbers = str_replace( "\\", '/', $CFG->dirroot)."/mod/game/hiddenpicture/numbers.png"; |
echo get_string( 'nextgame', 'game').'</a> '; |
||||
if( $usemap){ |
|
||||
$cols = $game->param1; |
if (! $cm = $DB->get_record( 'course_modules', array( 'id' => $id))) { |
||||
$rows = $game->param2; |
print_error( "Course Module ID was incorrect id=$id"); |
||||
}else{ |
} |
||||
$cols = $rows = 0; |
|
||||
} |
echo "<a href=\"{$CFG->wwwroot}/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> '; |
||||
$params = "id=$id&id2=$attempt->id&f=$foundcells&cols=$cols&rows=$rows&cells=$cells&p={$query->attachment}&n=$filenamenumbers"; |
|
||||
$imagesrc = "hiddenpicture/picture.php?$params"; |
return false; |
||||
|
} |
||||
$fs = get_file_storage(); |
|
||||
$file = get_file_storage()->get_file_by_hash( $query->attachment); |
function game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, $usemap) { |
||||
$image = $file->get_imageinfo(); |
global $CFG; |
||||
if( $game->param4 > 10){ |
|
||||
$width = $game->param4; |
$filenamenumbers = str_replace( "\\", '/', $CFG->dirroot)."/mod/game/hiddenpicture/numbers.png"; |
||||
$height = $image[ 'height'] * $width / $image[ 'width']; |
if ($usemap) { |
||||
}else if( $game->param5 > 10){ |
$cols = $game->param1; |
||||
$height = $game->param5; |
$rows = $game->param2; |
||||
$width = $image[ 'width'] * $height / $image[ 'height']; |
} else { |
||||
}else |
$cols = $rows = 0; |
||||
{ |
} |
||||
$width = $image[ 'width']; |
$params = "id=$id&id2=$attempt->id&f=$foundcells&cols=$cols&rows=$rows&cells=$cells&p={$query->attachment}&n=$filenamenumbers"; |
||||
$height = $image[ 'height']; |
$imagesrc = "hiddenpicture/picture.php?$params"; |
||||
} |
|
||||
|
$fs = get_file_storage(); |
||||
echo "<IMG SRC=\"$imagesrc\" width=$width "; |
$file = get_file_storage()->get_file_by_hash( $query->attachment); |
||||
if( $usemap){ |
$image = $file->get_imageinfo(); |
||||
echo " USEMAP=\"#mapname\" "; |
if ($game->param4 > 10) { |
||||
} |
$width = $game->param4; |
||||
echo " BORDER=\"1\">\r\n"; |
$height = $image[ 'height'] * $width / $image[ 'width']; |
||||
|
} else if ( $game->param5 > 10) { |
||||
if( $usemap){ |
$height = $game->param5; |
||||
echo "<MAP NAME=\"mapname\">\r\n"; |
$width = $image[ 'width'] * $height / $image[ 'height']; |
||||
$pos=0; |
} else { |
||||
for($row=0; $row < $rows; $row++){ |
$width = $image[ 'width']; |
||||
for( $col=0; $col < $cols; $col++){ |
$height = $image[ 'height']; |
||||
$pos++; |
} |
||||
$x1 = $col * $width / $cols; |
|
||||
$y1 = $row * $height / $rows; |
echo "<IMG SRC=\"$imagesrc\" width=$width "; |
||||
$x2 = $x1 + $width / $cols; |
if ($usemap) { |
||||
$y2 = $y1 + $height / $rows; |
echo " USEMAP=\"#mapname\" "; |
||||
$q = "a$pos"; |
} |
||||
echo "<AREA SHAPE=\"rect\" COORDS=\"$x1,$y1,$x2,$y2\" HREF=\"#$q\" ALT=\"$pos\">\r\n"; |
echo " BORDER=\"1\">\r\n"; |
||||
} |
|
||||
} |
if ($usemap) { |
||||
echo "</MAP>"; |
echo "<MAP NAME=\"mapname\">\r\n"; |
||||
} |
$pos = 0; |
||||
} |
for ($row = 0; $row < $rows; $row++) { |
||||
|
for ($col = 0; $col < $cols; $col++) { |
||||
|
$pos++; |
||||
|
$x1 = $col * $width / $cols; |
||||
|
$y1 = $row * $height / $rows; |
||||
|
$x2 = $x1 + $width / $cols; |
||||
|
$y2 = $y1 + $height / $rows; |
||||
|
$q = "a$pos"; |
||||
|
echo "<AREA SHAPE=\"rect\" COORDS=\"$x1,$y1,$x2,$y2\" HREF=\"#$q\" ALT=\"$pos\">\r\n"; |
||||
|
} |
||||
|
} |
||||
|
echo "</MAP>"; |
||||
|
} |
||||
|
} |
||||
|
Loading…
Reference in new issue