Vasilis Daloukas
9 years ago
11 changed files with 5332 additions and 3557 deletions
@ -1,229 +1,220 @@ |
|||
<?PHP |
|||
|
|||
class CryptexDB extends CrossDB |
|||
{ |
|||
function savecryptex( $game, &$crossm, $crossd, $id, $letters) |
|||
{ |
|||
global $USER; |
|||
|
|||
CrossDB::delete_records( $id); |
|||
|
|||
if( (CrossDB::savecross( $game, $crossm, $crossd, $id)) == false){ |
|||
return false; |
|||
} |
|||
|
|||
$crossm->id = $id; |
|||
|
|||
$newrec = new stdClass(); |
|||
$newrec->id = $id; |
|||
$newrec->letters = $letters; |
|||
|
|||
if (!($cryptexid = game_insert_record( "game_cryptex", $newrec))){ |
|||
print_error( 'Insert page: new page game_cryptex not inserted'); |
|||
} |
|||
|
|||
return $newrec; |
|||
} |
|||
|
|||
|
|||
function computeletters( $crossm, $crossd) |
|||
{ |
|||
$letters = ''; |
|||
$cols = $crossm->cols + 1; |
|||
$letters = str_repeat('.', $crossm->cols).'#'; |
|||
$letters = str_repeat($letters, $crossm->rows) ; |
|||
|
|||
$freqs1 = array(); |
|||
$count1 = $count2 = 0; |
|||
foreach( $crossd as $rec) |
|||
{ |
|||
$pos = $rec->col - 1 + ($rec->row-1) * $cols; |
|||
$s = $rec->answertext; |
|||
$len = game_strlen( $s); |
|||
|
|||
$a = array(); |
|||
for( $i=0; $i < $len; $i++){ |
|||
$a[] = game_substr( $s, $i, 1); |
|||
} |
|||
|
|||
for( $i=0; $i < $len; $i++){ |
|||
$this->setchar( $letters, $pos, $a[ $i]); |
|||
$pos += ( $rec->horizontal ? 1 : $cols); |
|||
|
|||
$freqs1[ ++$count1] = $a[ $i]; |
|||
if( $i+1 < $len){ |
|||
$freqs2[ ++$count2] = $a[ $i].$a[ $i+1]; |
|||
} |
|||
} |
|||
} |
|||
|
|||
$len = game_strlen( $letters); |
|||
$spaces = 0; |
|||
for( $i=0; $i < $len; $i++){ |
|||
if( game_substr( $letters, $i, 1) == '.'){ |
|||
$spaces++; |
|||
} |
|||
} |
|||
|
|||
$step = 1; |
|||
while( $spaces) |
|||
{ |
|||
if( $step == 1){ |
|||
$step = 2; |
|||
$i = array_rand( $freqs1); |
|||
$this->insertchar( $letters, $crossm->cols, $crossm->rows, $freqs1[ $i], $spaces); |
|||
}else |
|||
{ |
|||
$step=1; |
|||
$i = array_rand( $freqs2); |
|||
$this->insertchars( $letters, $crossm->cols, $crossm->rows, $freqs2[ $i], $spaces); |
|||
} |
|||
} |
|||
|
|||
$ret_letters = ""; |
|||
for( $row=0; $row < $crossm->rows; $row++){ |
|||
$ret_letters .= game_substr( $letters, $cols * $row, ($cols-1)); |
|||
} |
|||
|
|||
|
|||
return $ret_letters; |
|||
} |
|||
|
|||
function displaycryptex( $cols, $rows, $letters, $mask, $showsolution, $textdir) |
|||
{ |
|||
echo "<table border=1 $textdir>"; |
|||
for( $row=0; $row < $rows; $row++) |
|||
{ |
|||
echo "<tr>"; |
|||
for( $col=0; $col < $cols; $col++){ |
|||
$pos = $cols * $row+$col; |
|||
$c = game_substr( $letters, $pos, 1); |
|||
$m = game_substr( $mask, $pos, 1); |
|||
|
|||
if( $showsolution and $m > '0'){ |
|||
echo "<td align=center><b><FONT color=red>".$c."</font></td>"; |
|||
}else if( $m == '1'){ |
|||
echo "<td align=center><b><FONT color=red>".$c."</font></td>"; |
|||
}else |
|||
{ |
|||
echo "<td align=center>".$c."</td>"; |
|||
} |
|||
} |
|||
echo "</tr>\r\n"; |
|||
} |
|||
echo "</table>"; |
|||
} |
|||
|
|||
function insertchar( &$letters, $cols, $rows, $char, &$spaces) |
|||
{ |
|||
$len = game_strlen( $letters); |
|||
for( $i=0; $i < $len; $i++){ |
|||
if( game_substr( $letters, $i, 1) == '.'){ |
|||
$this->setchar( $letters, $i, $char); |
|||
$spaces--; |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
|
|||
function insertchars( &$letters, $cols, $rows, $char, &$spaces) |
|||
{ |
|||
$len = game_strlen( $letters); |
|||
for( $i=0; $i < $len; $i++){ |
|||
if( game_substr( $letters, $i, 1) == '.' and game_substr( $letters, $i+1, 1) == '.' ){ |
|||
$this->setchar( $letters, $i, game_substr( $char, 0, 1)); |
|||
$this->setchar( $letters, $i+1, game_substr( $char, 1, 1)); |
|||
$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)); |
|||
$this->setchar( $letters, $i + $cols+1, game_substr( $char, 1, 1)); |
|||
$spaces-=2; |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
function gethash( $word) |
|||
{ |
|||
$x = 37; |
|||
$len = count( game_strlen( $word)); |
|||
|
|||
for($i=0; $i < $len; $i++){ |
|||
$x = $x xor ord( game_substr( $word, $i, 1)); |
|||
} |
|||
|
|||
return $x; |
|||
} |
|||
|
|||
function loadcryptex( $crossm, &$mask, &$corrects, &$language) |
|||
{ |
|||
global $DB; |
|||
|
|||
$questions = array(); |
|||
$corrects = array(); |
|||
|
|||
$mask = str_repeat( '0', $crossm->cols * $crossm->rows); |
|||
|
|||
if ($recs = $DB->get_records( 'game_queries', array( 'attemptid' => $crossm->id))) |
|||
{ |
|||
foreach ($recs as $rec) |
|||
{ |
|||
if( $rec->questiontext == ''){ |
|||
$rec->questiontext = ' '; |
|||
} |
|||
$key = $this->gethash( $rec->questiontext).'-'.$rec->answertext.'-'.$rec->id; |
|||
$questions[ $key] = $rec; |
|||
|
|||
$word = $rec->answertext; |
|||
$pos = $crossm->cols * ($rec->row-1)+($rec->col-1); |
|||
$len = game_strlen( $word); |
|||
$found = ($rec->answertext == $rec->studentanswer); |
|||
|
|||
for( $i=0; $i < $len; $i++) |
|||
{ |
|||
$c = ( $found ? '1' : '2'); |
|||
|
|||
if( game_substr( $mask, $pos, 1) != '1'){ |
|||
game_setchar( $mask, $pos, $c); |
|||
} |
|||
|
|||
$pos += ($rec->horizontal ? 1 : $crossm->cols); |
|||
} |
|||
|
|||
if( $found){ |
|||
$corrects[ $rec->id] = 1; |
|||
} |
|||
|
|||
if( $language == ''){ |
|||
$language = game_detectlanguage( $rec->answertext); |
|||
} |
|||
} |
|||
ksort( $questions); |
|||
} |
|||
|
|||
return $questions; |
|||
} |
|||
|
|||
|
|||
function setwords( $answers, $maxcols, $reps) |
|||
{ |
|||
return Cross::setwords( $answers, $maxcols, $reps); |
|||
} |
|||
|
|||
function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords) |
|||
{ |
|||
if( !cross::computedata( $crossm, $crossd, $letters, $minwords, $maxwords)){ |
|||
return false; |
|||
} |
|||
|
|||
$letters = $this->computeletters( $crossm, $crossd); |
|||
|
|||
return true; |
|||
} |
|||
} |
|||
|
|||
|
|||
<?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/>. |
|||
|
|||
class CryptexDB extends CrossDB { |
|||
public function savecryptex( $game, &$crossm, $crossd, $id, $letters) { |
|||
global $USER; |
|||
|
|||
CrossDB::delete_records( $id); |
|||
|
|||
if ((CrossDB::savecross( $game, $crossm, $crossd, $id)) == false) { |
|||
return false; |
|||
} |
|||
|
|||
$crossm->id = $id; |
|||
|
|||
$newrec = new stdClass(); |
|||
$newrec->id = $id; |
|||
$newrec->letters = $letters; |
|||
|
|||
if (!($cryptexid = game_insert_record( "game_cryptex", $newrec))) { |
|||
print_error( 'Insert page: new page game_cryptex not inserted'); |
|||
} |
|||
|
|||
return $newrec; |
|||
} |
|||
|
|||
public function computeletters( $crossm, $crossd) { |
|||
$letters = ''; |
|||
$cols = $crossm->cols + 1; |
|||
$letters = str_repeat('.', $crossm->cols).'#'; |
|||
$letters = str_repeat($letters, $crossm->rows); |
|||
|
|||
$freqs1 = array(); |
|||
$count1 = $count2 = 0; |
|||
foreach ($crossd as $rec) { |
|||
$pos = $rec->col - 1 + ($rec->row - 1) * $cols; |
|||
$s = $rec->answertext; |
|||
$len = game_strlen( $s); |
|||
|
|||
$a = array(); |
|||
for ($i = 0; $i < $len; $i++) { |
|||
$a[] = game_substr( $s, $i, 1); |
|||
} |
|||
|
|||
for ($i = 0; $i < $len; $i++) { |
|||
$this->setchar( $letters, $pos, $a[ $i]); |
|||
$pos += ( $rec->horizontal ? 1 : $cols); |
|||
|
|||
$freqs1[ ++$count1] = $a[ $i]; |
|||
if ($i + 1 < $len) { |
|||
$freqs2[ ++$count2] = $a[ $i].$a[ $i + 1]; |
|||
} |
|||
} |
|||
} |
|||
|
|||
$len = game_strlen( $letters); |
|||
$spaces = 0; |
|||
for ($i = 0; $i < $len; $i++) { |
|||
if (game_substr( $letters, $i, 1) == '.') { |
|||
$spaces++; |
|||
} |
|||
} |
|||
|
|||
$step = 1; |
|||
while ($spaces) { |
|||
if ($step == 1) { |
|||
$step = 2; |
|||
$i = array_rand( $freqs1); |
|||
$this->insertchar( $letters, $crossm->cols, $crossm->rows, $freqs1[ $i], $spaces); |
|||
} else { |
|||
$step = 1; |
|||
$i = array_rand( $freqs2); |
|||
$this->insertchars( $letters, $crossm->cols, $crossm->rows, $freqs2[ $i], $spaces); |
|||
} |
|||
} |
|||
|
|||
$retletters = ""; |
|||
for ($row = 0; $row < $crossm->rows; $row++) { |
|||
$retletters .= game_substr( $letters, $cols * $row, ($cols - 1)); |
|||
} |
|||
|
|||
return $retletters; |
|||
} |
|||
|
|||
public function displaycryptex( $cols, $rows, $letters, $mask, $showsolution, $textdir) { |
|||
echo "<table border=1 $textdir>"; |
|||
for ($row = 0; $row < $rows; $row++) { |
|||
echo "<tr>"; |
|||
for ($col = 0; $col < $cols; $col++) { |
|||
$pos = $cols * $row + $col; |
|||
$c = game_substr( $letters, $pos, 1); |
|||
$m = game_substr( $mask, $pos, 1); |
|||
|
|||
if ($showsolution and $m > '0') { |
|||
echo "<td align=center><b><FONT color=red>".$c."</font></td>"; |
|||
} else if ( $m == '1') { |
|||
echo "<td align=center><b><FONT color=red>".$c."</font></td>"; |
|||
} else { |
|||
echo "<td align=center>".$c."</td>"; |
|||
} |
|||
} |
|||
echo "</tr>\r\n"; |
|||
} |
|||
echo "</table>"; |
|||
} |
|||
|
|||
public function insertchar( &$letters, $cols, $rows, $char, &$spaces) { |
|||
$len = game_strlen( $letters); |
|||
for ($i = 0; $i < $len; $i++) { |
|||
if (game_substr( $letters, $i, 1) == '.') { |
|||
$this->setchar( $letters, $i, $char); |
|||
$spaces--; |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public function insertchars( &$letters, $cols, $rows, $char, &$spaces) { |
|||
$len = game_strlen( $letters); |
|||
for ($i = 0; $i < $len; $i++) { |
|||
if (game_substr( $letters, $i, 1) == '.' and game_substr( $letters, $i + 1, 1) == '.' ) { |
|||
$this->setchar( $letters, $i, game_substr( $char, 0, 1)); |
|||
$this->setchar( $letters, $i + 1, game_substr( $char, 1, 1)); |
|||
$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)); |
|||
$this->setchar( $letters, $i + $cols + 1, game_substr( $char, 1, 1)); |
|||
$spaces -= 2; |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public function gethash( $word) { |
|||
$x = 37; |
|||
$len = count( game_strlen( $word)); |
|||
|
|||
for ($i = 0; $i < $len; $i++) { |
|||
$x = $x xor ord( game_substr( $word, $i, 1)); |
|||
} |
|||
|
|||
return $x; |
|||
} |
|||
|
|||
public function loadcryptex( $crossm, &$mask, &$corrects, &$language) { |
|||
global $DB; |
|||
|
|||
$questions = array(); |
|||
$corrects = array(); |
|||
|
|||
$mask = str_repeat( '0', $crossm->cols * $crossm->rows); |
|||
|
|||
if ($recs = $DB->get_records( 'game_queries', array( 'attemptid' => $crossm->id))) { |
|||
foreach ($recs as $rec) { |
|||
if ($rec->questiontext == '') { |
|||
$rec->questiontext = ' '; |
|||
} |
|||
$key = $this->gethash( $rec->questiontext).'-'.$rec->answertext.'-'.$rec->id; |
|||
$questions[ $key] = $rec; |
|||
|
|||
$word = $rec->answertext; |
|||
$pos = $crossm->cols * ($rec->row - 1) + ($rec->col - 1); |
|||
$len = game_strlen( $word); |
|||
$found = ($rec->answertext == $rec->studentanswer); |
|||
|
|||
for ($i = 0; $i < $len; $i++) { |
|||
$c = ( $found ? '1' : '2'); |
|||
|
|||
if (game_substr( $mask, $pos, 1) != '1') { |
|||
game_setchar( $mask, $pos, $c); |
|||
} |
|||
|
|||
$pos += ($rec->horizontal ? 1 : $crossm->cols); |
|||
} |
|||
|
|||
if ($found) { |
|||
$corrects[ $rec->id] = 1; |
|||
} |
|||
|
|||
if ($language == '') { |
|||
$language = game_detectlanguage( $rec->answertext); |
|||
} |
|||
} |
|||
ksort( $questions); |
|||
} |
|||
|
|||
return $questions; |
|||
} |
|||
|
|||
public function setwords( $answers, $maxcols, $reps) { |
|||
return Cross::setwords( $answers, $maxcols, $reps); |
|||
} |
|||
|
|||
public function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords) { |
|||
if (!cross::computedata( $crossm, $crossd, $letters, $minwords, $maxwords)) { |
|||
return false; |
|||
} |
|||
|
|||
$letters = $this->computeletters( $crossm, $crossd); |
|||
|
|||
return true; |
|||
} |
|||
} |
|||
|
@ -1,8 +1,21 @@ |
|||
<?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"); |
|||
|
|||
|
|||
execute_sql("truncate TABLE {game_snakes_database}"); |
|||
|
|||
require( "importsnakes.php"); |
|||
|
@ -1,53 +1,63 @@ |
|||
<?php // $Id: importsnakes.php,v 1.5 2012/07/25 11:16:05 bdaloukas Exp $
|
|||
|
|||
game_importsnakes(); |
|||
|
|||
function game_importsnakes() |
|||
{ |
|||
global $DB; |
|||
|
|||
if( $DB->count_records( 'game_snakes_database') != 0){ |
|||
return; |
|||
} |
|||
|
|||
$newrec = new stdClass(); |
|||
$newrec->name = '8x8 - 4 Snakes - 4 Ladders'; |
|||
$newrec->cols = 8; |
|||
$newrec->rows = 8; |
|||
$newrec->fileboard = 'fidaki.jpg'; |
|||
$newrec->direction = 1; |
|||
$newrec->headerx = 4; |
|||
$newrec->headery = 4; |
|||
$newrec->footerx = 4; |
|||
$newrec->footery = 4; |
|||
$newrec->width = 487; |
|||
$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 = '6x6 - 3 Snakes - 3 Ladders'; |
|||
$newrec->cols = 6; |
|||
$newrec->rows = 6; |
|||
$newrec->fileboard = 'fidaki2.jpg'; |
|||
$newrec->direction = 1; |
|||
$newrec->headerx = 8; |
|||
$newrec->headery = 8; |
|||
$newrec->footerx = 8; |
|||
$newrec->footery = 8; |
|||
$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_object( $newrec); |
|||
print_error( "Can't insert to table game_snakes_database"); |
|||
} |
|||
} |
|||
<?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/>. |
|||
|
|||
game_importsnakes(); |
|||
|
|||
function game_importsnakes() { |
|||
global $DB; |
|||
|
|||
if ($DB->count_records( 'game_snakes_database') != 0) { |
|||
return; |
|||
} |
|||
|
|||
$newrec = new stdClass(); |
|||
$newrec->name = '8x8 - 4 Snakes - 4 Ladders'; |
|||
$newrec->cols = 8; |
|||
$newrec->rows = 8; |
|||
$newrec->fileboard = 'fidaki.jpg'; |
|||
$newrec->direction = 1; |
|||
$newrec->headerx = 4; |
|||
$newrec->headery = 4; |
|||
$newrec->footerx = 4; |
|||
$newrec->footery = 4; |
|||
$newrec->width = 487; |
|||
$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 = '6x6 - 3 Snakes - 3 Ladders'; |
|||
$newrec->cols = 6; |
|||
$newrec->rows = 6; |
|||
$newrec->fileboard = 'fidaki2.jpg'; |
|||
$newrec->direction = 1; |
|||
$newrec->headerx = 8; |
|||
$newrec->headery = 8; |
|||
$newrec->footerx = 8; |
|||
$newrec->footery = 8; |
|||
$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'); |
|||
|
|||
$id = required_param('id', PARAM_INT); // Course Module ID |
|||
$attemptid = required_param('id2', PARAM_INT); // Course Module ID |
|||
$id = required_param('id', PARAM_INT); // Course Module ID. |
|||
$attemptid = required_param('id2', PARAM_INT); // Course Module ID. |
|||
|
|||
$foundcells = required_param('f', PARAM_SEQUENCE); //CSV |
|||
$cells = required_param('cells', PARAM_SEQUENCE); //CSV |
|||
$foundcells = required_param('f', PARAM_SEQUENCE); // CSV. |
|||
$cells = required_param('cells', PARAM_SEQUENCE); // CSV. |
|||
$filehash = required_param('p', PARAM_PATH); |
|||
$cols = required_param('cols', 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); |
|||
|
|||
function create_image( $id, $attemptid, $foundcells, $cells, $filehash, $cols, $rows, $filenamenumbers) |
|||
{ |
|||
function create_image( $id, $attemptid, $foundcells, $cells, $filehash, $cols, $rows, $filenamenumbers) { |
|||
global $CFG; |
|||
|
|||
|
|||
$a = explode( ',', $foundcells); |
|||
$found = array(); |
|||
foreach( $a as $s){ |
|||
foreach ($a as $s) { |
|||
$found[ $s] = 1; |
|||
} |
|||
|
|||
|
|||
$a = explode( ',', $cells); |
|||
$cells = array(); |
|||
foreach( $a as $s){ |
|||
foreach ($a as $s) { |
|||
$cells[ $s] = 1; |
|||
} |
|||
|
|||
$file = get_file_storage()->get_file_by_hash( $filehash); |
|||
$image = $file->get_imageinfo(); |
|||
|
|||
if( $image === false){ |
|||
if ($image === false) { |
|||
die("Aknown filehash $filehash"); |
|||
return false; |
|||
} |
|||
$img_handle = imagecreatefromstring($file->get_content()); |
|||
$imghandle = imagecreatefromstring($file->get_content()); |
|||
|
|||
$mime = $image[ 'mimetype']; |
|||
|
|||
$img_numbers = imageCreateFromPNG( $filenamenumbers); |
|||
$size_numbers = getimagesize ($filenamenumbers); |
|||
|
|||
Header ("Content-type: $mime"); |
|||
|
|||
$color = ImageColorAllocate ($img_handle, 100, 100, 100); |
|||
$imgnumbers = imagecreatefrompng( $filenamenumbers); |
|||
$sizenumbers = getimagesize ($filenamenumbers); |
|||
|
|||
header("Content-type: $mime"); |
|||
|
|||
$color = imagecolorallocate( $imghandle, 100, 100, 100); |
|||
|
|||
$width = $image[ 'width']; |
|||
$height = $image[ 'height']; |
|||
$pos = 0; |
|||
|
|||
|
|||
$font = 1; |
|||
|
|||
for($y = 0; $y < $rows; $y++){ |
|||
for( $x=0; $x < $cols; $x++){ |
|||
for ($y = 0; $y < $rows; $y++) { |
|||
for ($x = 0; $x < $cols; $x++) { |
|||
$pos++; |
|||
if( !array_key_exists( $pos, $found)){ |
|||
if (!array_key_exists( $pos, $found)) { |
|||
$x1 = $x * $width / $cols; |
|||
$y1 = $y * $height / $rows; |
|||
imagefilledrectangle( $img_handle, $x1, $y1, $x1 + $width / $cols, $y1 + $height / $rows, $color); |
|||
|
|||
if( array_key_exists( $pos, $cells)){ |
|||
shownumber( $img_handle, $img_numbers, $pos, $x1 , $y1, $width / $cols, $height / $rows, $size_numbers); |
|||
imagefilledrectangle( $imghandle, $x1, $y1, $x1 + $width / $cols, $y1 + $height / $rows, $color); |
|||
|
|||
if (array_key_exists( $pos, $cells)) { |
|||
shownumber( $imghandle, $imgnumbers, $pos, $x1 , $y1, $width / $cols, $height / $rows, $sizenumbers); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
switch( $mime){ |
|||
case 'image/png': |
|||
ImagePng ($img_handle); |
|||
break; |
|||
case 'image/jpeg': |
|||
ImageJpeg ($img_handle); |
|||
break; |
|||
case 'image/gif': |
|||
ImageGif ($img_handle); |
|||
break; |
|||
default: |
|||
die('Aknown mime type $mime'); |
|||
return false; |
|||
switch ($mime) { |
|||
case 'image/png': |
|||
imagepng ($imghandle); |
|||
break; |
|||
case 'image/jpeg': |
|||
imagejpeg ($imghandle); |
|||
break; |
|||
case 'image/gif': |
|||
imagegif ($imghandle); |
|||
break; |
|||
default: |
|||
die('Aknown mime type $mime'); |
|||
return false; |
|||
} |
|||
|
|||
ImageDestroy ($img_handle); |
|||
} |
|||
|
|||
function shownumber( $img_handle, $img_numbers, $number, $x1 , $y1, $width, $height, $size_numbers){ |
|||
if( $number < 10){ |
|||
$width_number = $size_numbers[ 0] / 10; |
|||
$dstX = $x1 + $width / 3; |
|||
$dstY = $y1 + $height / 3; |
|||
$srcX = $number * $size_numbers[ 0] / 10; |
|||
$srcW = $size_numbers[ 0]/10; |
|||
$srcH = $size_numbers[ 1]; |
|||
$dstW = $width / 10; |
|||
$dstH = $dstW * $srcH / $srcW; |
|||
imagecopyresized( $img_handle, $img_numbers, $dstX, $dstY, $srcX, 0, $dstW, $dstH, $srcW, $srcH); |
|||
}else |
|||
{ |
|||
imagedestroy ($imghandle); |
|||
} |
|||
|
|||
function shownumber( $imghandle, $imgnumbers, $number, $x1 , $y1, $width, $height, $sizenumbers) { |
|||
if ($number < 10) { |
|||
$widthnumber = $sizenumbers[ 0] / 10; |
|||
$dstx = $x1 + $width / 3; |
|||
$dsty = $y1 + $height / 3; |
|||
$srcx = $number * $sizenumbers[ 0] / 10; |
|||
$srcw = $sizenumbers[ 0] / 10; |
|||
$srch = $sizenumbers[ 1]; |
|||
$dstw = $width / 10; |
|||
$dsth = $dstw * $srch / $srcw; |
|||
imagecopyresized( $imghandle, $imgnumbers, $dstx, $dsty, $srcx, 0, $dstw, $dsth, $srcw, $srchh); |
|||
} 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); |
|||
} |
|||
} |
|||
|
@ -1,486 +1,498 @@ |
|||
<?php // $Id: play.php,v 1.19 2012/08/15 09:26:55 bdaloukas Exp $
|
|||
|
|||
// This file plays the game Hidden Picture |
|||
|
|||
function game_hiddenpicture_continue( $id, $game, $attempt, $hiddenpicture, $context) |
|||
{ |
|||
global $DB, $USER; |
|||
|
|||
if( $attempt != false and $hiddenpicture != false){ |
|||
//Continue a previous attempt |
|||
return game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
|||
} |
|||
|
|||
if( $attempt == false){ |
|||
//Start a new attempt |
|||
$attempt = game_addattempt( $game); |
|||
} |
|||
|
|||
$cols = $game->param1; |
|||
$rows = $game->param2; |
|||
if( $cols == 0){ |
|||
print_error( get_string( 'hiddenpicture_nocols', 'game')); |
|||
} |
|||
if( $rows == 0){ |
|||
print_error( get_string( 'hiddenpicture_norows', 'game')); |
|||
} |
|||
|
|||
//new attempt |
|||
$n = $game->param1 * $game->param2; |
|||
$recs = game_questions_selectrandom( $game, CONST_GAME_TRIES_REPETITION*$n); |
|||
$selected_recs = game_select_from_repetitions( $game, $recs, $n); |
|||
|
|||
$newrec = game_hiddenpicture_selectglossaryentry( $game, $attempt); |
|||
|
|||
if( $recs === false){ |
|||
print_error( get_string( 'no_questions', 'game')); |
|||
} |
|||
|
|||
$positions = array(); |
|||
$pos=1; |
|||
for($col=0; $col < $cols; $col++){ |
|||
for( $row=0; $row < $rows; $row++){ |
|||
$positions[] = $pos++; |
|||
} |
|||
} |
|||
$i = 0; |
|||
$field = ($game->sourcemodule == 'glossary' ? 'glossaryentryid' : 'questionid'); |
|||
foreach( $recs as $rec) |
|||
{ |
|||
if( $game->sourcemodule == 'glossary') |
|||
$key = $rec->glossaryentryid; |
|||
else |
|||
$key = $rec->questionid; |
|||
|
|||
if( !array_key_exists( $key, $selected_recs)) |
|||
continue; |
|||
|
|||
$query = new stdClass(); |
|||
$query->attemptid = $newrec->id; |
|||
$query->gamekind = $game->gamekind; |
|||
$query->gameid = $game->id; |
|||
$query->userid = $USER->id; |
|||
|
|||
$pos = array_rand( $positions); |
|||
$query->col = $positions[ $pos]; |
|||
unset( $positions[ $pos]); |
|||
|
|||
$query->sourcemodule = $game->sourcemodule; |
|||
$query->questionid = $rec->questionid; |
|||
$query->glossaryentryid = $rec->glossaryentryid; |
|||
$query->score = 0; |
|||
if( ($query->id = $DB->insert_record( 'game_queries', $query)) == 0){ |
|||
print_error( 'error inserting in game_queries'); |
|||
} |
|||
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
|||
} |
|||
|
|||
//The score is zero |
|||
game_updateattempts( $game, $attempt, 0, 0); |
|||
|
|||
game_hiddenpicture_play( $id, $game, $attempt, $newrec, false, $context); |
|||
} |
|||
|
|||
//Create the game_hiddenpicture record |
|||
function game_hiddenpicture_selectglossaryentry( $game, $attempt){ |
|||
global $CFG, $DB, $USER; |
|||
|
|||
srand( (double)microtime()*1000000); |
|||
|
|||
if( $game->glossaryid2 == 0){ |
|||
print_error( get_string( 'must_select_glossary', 'game')); |
|||
} |
|||
$select = "ge.glossaryid={$game->glossaryid2}"; |
|||
$table = '{glossary_entries} ge'; |
|||
if( $game->glossarycategoryid2){ |
|||
$table .= ",{glossary_entries_categories} gec"; |
|||
$select .= " AND gec.entryid = ge.id AND gec.categoryid = {$game->glossarycategoryid2}"; |
|||
} |
|||
if( $game->param7 == 0){ |
|||
//Allow spaces |
|||
$select .= " AND concept NOT LIKE '% %'"; |
|||
} |
|||
|
|||
$sql = "SELECT ge.id,attachment FROM $table WHERE $select"; |
|||
if( ($recs=$DB->get_records_sql( $sql)) == false){ |
|||
$a->name = "'".$DB->get_field('glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
|||
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
|||
return false; |
|||
} |
|||
$ids = array(); |
|||
$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){ |
|||
$files = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $rec->id, "timemodified", false); |
|||
if( $files) |
|||
{ |
|||
foreach( $files as $key => $file) |
|||
{ |
|||
$s = strtoupper( $file->get_filename()); |
|||
$s = substr( $s, -4); |
|||
if( $s == '.GIF' or $s == '.JPG' or $s == '.PNG'){ |
|||
$ids[] = $rec->id; |
|||
$keys[] = $file->get_pathnamehash(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
if( count( $ids) == 0){ |
|||
$a->name = "'".$DB->get_field( 'glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
|||
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
|||
return false; |
|||
} |
|||
|
|||
//Have to select randomly one glossaryentry |
|||
$poss = array(); |
|||
for($i=0;$i<count($ids);$i++){ |
|||
$poss[] = $i; |
|||
} |
|||
shuffle( $poss); |
|||
$min_num = 0; |
|||
$attachement = ''; |
|||
for($i=0;$i<count($ids);$i++){ |
|||
$pos = $poss[ $i]; |
|||
$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 < $min_num) or ($min_num == 0)){ |
|||
$min_num = $rec2->r; |
|||
$glossaryentryid = $tempid; |
|||
$attachement = $keys[ $pos]; |
|||
} |
|||
} |
|||
else{ |
|||
$glossaryentryid = $tempid; |
|||
$attachement = $keys[ $pos]; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
$sql = 'SELECT id, concept as answertext, definition as questiontext, id as glossaryentryid, 0 as questionid, glossaryid, attachment'. |
|||
' FROM {glossary_entries} WHERE id = '.$glossaryentryid; |
|||
if( ($rec = $DB->get_record_sql( $sql)) == false) |
|||
return false; |
|||
|
|||
$query = new stdClass(); |
|||
$query->attemptid = $attempt->id; |
|||
$query->gamekind = $game->gamekind; |
|||
$query->gameid = $game->id; |
|||
$query->userid = $USER->id; |
|||
|
|||
$query->col = 0; |
|||
$query->sourcemodule = 'glossary'; |
|||
$query->questionid = 0; |
|||
$query->glossaryentryid = $rec->glossaryentryid; |
|||
$query->attachment = $attachement; |
|||
$query->questiontext = $rec->questiontext; |
|||
$query->answertext = $rec->answertext; |
|||
$query->score = 0; |
|||
if( ($query->id = $DB->insert_record( 'game_queries', $query)) == 0){ |
|||
print_error( 'Error inserting in game_queries'); |
|||
} |
|||
$newrec = new stdClass(); |
|||
$newrec->id = $attempt->id; |
|||
$newrec->correct = 0; |
|||
if( !game_insert_record( 'game_hiddenpicture', $newrec)){ |
|||
print_error( 'Error inserting in game_hiddenpicture'); |
|||
} |
|||
|
|||
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
|||
|
|||
return $newrec; |
|||
} |
|||
|
|||
function game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, $showsolution, $context) |
|||
{ |
|||
if( $game->toptext != ''){ |
|||
echo $game->toptext.'<br>'; |
|||
} |
|||
|
|||
//Show picture |
|||
$offsetquestions = game_sudoku_compute_offsetquestions( $game->sourcemodule, $attempt, $numbers, $correctquestions); |
|||
unset( $offsetquestions[ 0]); |
|||
|
|||
game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, $offsetquestions, $correctquestions, $id, $attempt, $showsolution); |
|||
|
|||
//Show questions |
|||
$onlyshow = false; |
|||
$showsolution = false; |
|||
|
|||
switch( $game->sourcemodule) |
|||
{ |
|||
case 'quiz': |
|||
case 'question': |
|||
game_sudoku_showquestions_quiz( $id, $game, $attempt, $hiddenpicture, $offsetquestions, $numbers, $correctquestions, $onlyshow, $showsolution, $context); |
|||
break; |
|||
case 'glossary': |
|||
game_sudoku_showquestions_glossary( $id, $game, $attempt, $hiddenpicture, $offsetquestions, $numbers, $correctquestions, $onlyshow, $showsolution); |
|||
break; |
|||
} |
|||
|
|||
if( $game->bottomtext != ''){ |
|||
echo '<br><br>'.$game->bottomtext; |
|||
} |
|||
} |
|||
|
|||
function game_hidden_picture_computescore( $game, $hiddenpicture){ |
|||
$correct = $hiddenpicture->correct; |
|||
if( $hiddenpicture->found){ |
|||
$correct++; |
|||
} |
|||
$remaining = $game->param1 * $game->param2 - $hiddenpicture->correct; |
|||
$div2 = $correct + $hiddenpicture->wrong + $remaining; |
|||
if( $hiddenpicture->found){ |
|||
$percent = ($correct + $remaining) / $div2; |
|||
}else{ |
|||
$percent = $correct / $div2; |
|||
} |
|||
|
|||
return $percent; |
|||
} |
|||
|
|||
function game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, $offsetquestions, $correctquestions){ |
|||
global $DB; |
|||
|
|||
$foundcells=''; |
|||
foreach( $correctquestions as $key => $val){ |
|||
$foundcells .= ','.$key; |
|||
} |
|||
$cells=''; |
|||
foreach( $offsetquestions as $key => $val){ |
|||
if( $key != 0){ |
|||
$cells .= ','.$key; |
|||
} |
|||
} |
|||
|
|||
$query = $DB->get_record_select( 'game_queries', "attemptid=$hiddenpicture->id AND col=0", null, 'id,glossaryentryid,attachment,questiontext'); |
|||
|
|||
//Grade |
|||
echo "<br/>".get_string( 'grade', 'game').' : '.round( $attempt->score * 100).' %'; |
|||
|
|||
game_hiddenpicture_showquestion_glossary( $game, $id, $query); |
|||
|
|||
$cells = substr( $cells, 1); |
|||
$foundcells = substr( $foundcells, 1); |
|||
game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, true); |
|||
} |
|||
|
|||
function game_hiddenpicture_showquestion_glossary( $game, $id, $query) |
|||
{ |
|||
global $CFG, $DB; |
|||
|
|||
$entry = $DB->get_record( 'glossary_entries', array( 'id' => $query->glossaryentryid)); |
|||
|
|||
/// Start the form |
|||
echo '<br>'; |
|||
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('hiddenpicture_mainsubmit', 'game')."\"></center>\n"; |
|||
|
|||
// Add a hidden field with the queryid |
|||
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; |
|||
echo '<input type="hidden" name="action" value="hiddenpicturecheckg" />'; |
|||
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; |
|||
|
|||
// Add a hidden field with glossaryentryid |
|||
echo '<input type="hidden" name="glossaryentryid" value="'.$query->glossaryentryid."\" />\n"; |
|||
|
|||
$temp = $game->glossaryid; |
|||
$game->glossaryid = $game->glossaryid2; |
|||
echo game_show_query( $game, $query, $entry->definition); |
|||
$game->glossaryid = $temp; |
|||
|
|||
echo get_string( 'answer').': '; |
|||
echo "<input type=\"text\" name=\"answer\" size=30 /><br>"; |
|||
|
|||
echo "</form><br>\n"; |
|||
} |
|||
|
|||
function game_hiddenpicture_check_questions( $id, $game, &$attempt, &$hiddenpicture, $finishattempt) |
|||
{ |
|||
global $QTYPES, $DB; |
|||
|
|||
$responses = data_submitted(); |
|||
|
|||
$offsetquestions = game_sudoku_compute_offsetquestions( $game->sourcemodule, $attempt, $numbers, $correctquestions); |
|||
|
|||
$questionlist = game_sudoku_getquestionlist( $offsetquestions); |
|||
|
|||
$questions = game_sudoku_getquestions( $questionlist); |
|||
|
|||
$actions = question_extract_responses($questions, $responses, QUESTION_EVENTSUBMIT); |
|||
|
|||
$correct = $wrong = 0; |
|||
foreach($questions as $question) { |
|||
if( !array_key_exists( $question->id, $actions)){ |
|||
//no answered |
|||
continue; |
|||
} |
|||
unset( $state); |
|||
unset( $cmoptions); |
|||
$question->maxgrade = 100; |
|||
$state->responses = $actions[ $question->id]->responses; |
|||
$state->event = QUESTION_EVENTGRADE; |
|||
|
|||
$cmoptions = array(); |
|||
$QTYPES[$question->qtype]->grade_responses( $question, $state, $cmoptions); |
|||
|
|||
unset( $query); |
|||
|
|||
$select = "attemptid=$attempt->id"; |
|||
$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)"); |
|||
} |
|||
|
|||
$answertext = $state->responses[ '']; |
|||
if( $answertext != ''){ |
|||
$grade = $state->raw_grade; |
|||
if( $grade < 50){ |
|||
//wrong answer |
|||
game_update_queries( $game, $attempt, $query, $grade/100, $answertext); |
|||
$wrong++; |
|||
}else{ |
|||
//correct answer |
|||
game_update_queries( $game, $attempt, $query, 1, $answertext); |
|||
$correct++; |
|||
} |
|||
} |
|||
} |
|||
|
|||
$hiddenpicture->correct += $correct; |
|||
$hiddenpicture->wrong += $wrong; |
|||
|
|||
if( !$DB->update_record( 'game_hiddenpicture', $hiddenpicture)){ |
|||
print_error( 'game_hiddenpicture_check_questions: error updating in game_hiddenpicture'); |
|||
} |
|||
|
|||
$attempt->score = game_hidden_picture_computescore( $game, $hiddenpicture); |
|||
if( !$DB->update_record( 'game_attempts', $attempt)){ |
|||
print_error( 'game_hiddenpicture_check_questions: error updating in game_attempt'); |
|||
} |
|||
|
|||
game_sudoku_check_last( $id, $game, $attempt, $hiddenpicture, $finishattempt); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
function game_hiddenpicture_check_mainquestion( $id, $game, &$attempt, &$hiddenpicture, $finishattempt, $context) |
|||
{ |
|||
global $QTYPES, $CFG, $DB; |
|||
|
|||
$responses = data_submitted(); |
|||
|
|||
$glossaryentryid = $responses->glossaryentryid; |
|||
$queryid = $responses->queryid; |
|||
|
|||
// Load the glossary entry |
|||
if (!($entry = $DB->get_record( 'glossary_entries', array( 'id' => $glossaryentryid)))) { |
|||
print_error( get_string( 'noglossaryentriesfound', 'game')); |
|||
} |
|||
$answer = $responses->answer; |
|||
$correct = false; |
|||
if( $answer != ''){ |
|||
if( game_upper( $entry->concept) == game_upper( $answer)){ |
|||
$correct = true; |
|||
} |
|||
} |
|||
|
|||
// Load the query |
|||
if (!($query = $DB->get_record( 'game_queries', array( 'id' => $queryid)))) { |
|||
print_error( "The query $queryid not found"); |
|||
} |
|||
|
|||
game_update_queries( $game, $attempt, $query, $correct, $answer); |
|||
|
|||
if( $correct){ |
|||
$hiddenpicture->found = 1; |
|||
}else{ |
|||
$hiddenpicture->wrong++; |
|||
} |
|||
if( !$DB->update_record( 'game_hiddenpicture', $hiddenpicture)){ |
|||
print_error( 'game_hiddenpicture_check_mainquestion: error updating in game_hiddenpicture'); |
|||
} |
|||
|
|||
$score = game_hidden_picture_computescore( $game, $hiddenpicture); |
|||
game_updateattempts( $game, $attempt, $score, $correct); |
|||
|
|||
if( $correct == false){ |
|||
game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
|||
return true; |
|||
} |
|||
|
|||
//Finish the game |
|||
$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); |
|||
echo '<p><BR/><font size="5" color="green">'.get_string( 'win', 'game').'</font><BR/><BR/></p>'; |
|||
global $CFG; |
|||
|
|||
echo '<br/>'; |
|||
|
|||
echo "<a href=\"$CFG->wwwroot/mod/game/attempt.php?id=$id\">"; |
|||
echo get_string( 'nextgame', 'game').'</a> '; |
|||
|
|||
if (! $cm = $DB->get_record( 'course_modules', array( 'id' => $id))) { |
|||
print_error( "Course Module ID was incorrect id=$id"); |
|||
} |
|||
|
|||
echo "<a href=\"{$CFG->wwwroot}/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> '; |
|||
|
|||
return false; |
|||
} |
|||
|
|||
function game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, $usemap) |
|||
{ |
|||
global $CFG; |
|||
|
|||
$filenamenumbers = str_replace( "\\", '/', $CFG->dirroot)."/mod/game/hiddenpicture/numbers.png"; |
|||
if( $usemap){ |
|||
$cols = $game->param1; |
|||
$rows = $game->param2; |
|||
}else{ |
|||
$cols = $rows = 0; |
|||
} |
|||
$params = "id=$id&id2=$attempt->id&f=$foundcells&cols=$cols&rows=$rows&cells=$cells&p={$query->attachment}&n=$filenamenumbers"; |
|||
$imagesrc = "hiddenpicture/picture.php?$params"; |
|||
|
|||
$fs = get_file_storage(); |
|||
$file = get_file_storage()->get_file_by_hash( $query->attachment); |
|||
$image = $file->get_imageinfo(); |
|||
if( $game->param4 > 10){ |
|||
$width = $game->param4; |
|||
$height = $image[ 'height'] * $width / $image[ 'width']; |
|||
}else if( $game->param5 > 10){ |
|||
$height = $game->param5; |
|||
$width = $image[ 'width'] * $height / $image[ 'height']; |
|||
}else |
|||
{ |
|||
$width = $image[ 'width']; |
|||
$height = $image[ 'height']; |
|||
} |
|||
|
|||
echo "<IMG SRC=\"$imagesrc\" width=$width "; |
|||
if( $usemap){ |
|||
echo " USEMAP=\"#mapname\" "; |
|||
} |
|||
echo " BORDER=\"1\">\r\n"; |
|||
|
|||
if( $usemap){ |
|||
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>"; |
|||
} |
|||
} |
|||
|
|||
<?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 Hidden Picture. |
|||
|
|||
function game_hiddenpicture_continue( $id, $game, $attempt, $hiddenpicture, $context) { |
|||
global $DB, $USER; |
|||
|
|||
if ($attempt != false and $hiddenpicture != false) { |
|||
// Continue a previous attempt. |
|||
return game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
|||
} |
|||
|
|||
if ($attempt == false) { |
|||
// Start a new attempt. |
|||
$attempt = game_addattempt( $game); |
|||
} |
|||
|
|||
$cols = $game->param1; |
|||
$rows = $game->param2; |
|||
if ($cols == 0) { |
|||
print_error( get_string( 'hiddenpicture_nocols', 'game')); |
|||
} |
|||
if ($rows == 0) { |
|||
print_error( get_string( 'hiddenpicture_norows', 'game')); |
|||
} |
|||
|
|||
// New attempt. |
|||
$n = $game->param1 * $game->param2; |
|||
$recs = game_questions_selectrandom( $game, CONST_GAME_TRIES_REPETITION * $n); |
|||
$selectedrecs = game_select_from_repetitions( $game, $recs, $n); |
|||
|
|||
$newrec = game_hiddenpicture_selectglossaryentry( $game, $attempt); |
|||
|
|||
if ($recs === false) { |
|||
print_error( get_string( 'no_questions', 'game')); |
|||
} |
|||
|
|||
$positions = array(); |
|||
$pos = 1; |
|||
for ($col = 0; $col < $cols; $col++) { |
|||
for ($row = 0; $row < $rows; $row++) { |
|||
$positions[] = $pos++; |
|||
} |
|||
} |
|||
$i = 0; |
|||
$field = ($game->sourcemodule == 'glossary' ? 'glossaryentryid' : 'questionid'); |
|||
foreach ($recs as $rec) { |
|||
if ($game->sourcemodule == 'glossary') { |
|||
$key = $rec->glossaryentryid; |
|||
} else { |
|||
$key = $rec->questionid; |
|||
} |
|||
|
|||
if (!array_key_exists( $key, $selectedrecs)) { |
|||
continue; |
|||
} |
|||
|
|||
$query = new stdClass(); |
|||
$query->attemptid = $newrec->id; |
|||
$query->gamekind = $game->gamekind; |
|||
$query->gameid = $game->id; |
|||
$query->userid = $USER->id; |
|||
|
|||
$pos = array_rand( $positions); |
|||
$query->col = $positions[ $pos]; |
|||
unset( $positions[ $pos]); |
|||
|
|||
$query->sourcemodule = $game->sourcemodule; |
|||
$query->questionid = $rec->questionid; |
|||
$query->glossaryentryid = $rec->glossaryentryid; |
|||
$query->score = 0; |
|||
if (($query->id = $DB->insert_record( 'game_queries', $query)) == 0) { |
|||
print_error( 'error inserting in game_queries'); |
|||
} |
|||
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
|||
} |
|||
|
|||
// The score is zero. |
|||
game_updateattempts( $game, $attempt, 0, 0); |
|||
|
|||
game_hiddenpicture_play( $id, $game, $attempt, $newrec, false, $context); |
|||
} |
|||
|
|||
// Create the game_hiddenpicture record. |
|||
function game_hiddenpicture_selectglossaryentry( $game, $attempt) { |
|||
global $CFG, $DB, $USER; |
|||
|
|||
srand( (double)microtime() * 1000000); |
|||
|
|||
if ($game->glossaryid2 == 0) { |
|||
print_error( get_string( 'must_select_glossary', 'game')); |
|||
} |
|||
$select = "ge.glossaryid={$game->glossaryid2}"; |
|||
$table = '{glossary_entries} ge'; |
|||
if ($game->glossarycategoryid2) { |
|||
$table .= ",{glossary_entries_categories} gec"; |
|||
$select .= " AND gec.entryid = ge.id AND gec.categoryid = {$game->glossarycategoryid2}"; |
|||
} |
|||
if ($game->param7 == 0) { |
|||
// Allow spaces. |
|||
$select .= " AND concept NOT LIKE '% %'"; |
|||
} |
|||
|
|||
$sql = "SELECT ge.id,attachment FROM $table WHERE $select"; |
|||
if (($recs = $DB->get_records_sql( $sql)) == false) { |
|||
$a->name = "'".$DB->get_field('glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
|||
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
|||
return false; |
|||
} |
|||
$ids = array(); |
|||
$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) { |
|||
$files = $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $rec->id, "timemodified", false); |
|||
if ($files) { |
|||
foreach ($files as $key => $file) { |
|||
$s = strtoupper( $file->get_filename()); |
|||
$s = substr( $s, -4); |
|||
if ($s == '.GIF' or $s == '.JPG' or $s == '.PNG') { |
|||
$ids[] = $rec->id; |
|||
$keys[] = $file->get_pathnamehash(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
if (count( $ids) == 0) { |
|||
$a->name = "'".$DB->get_field( 'glossary', 'name', array( 'id' => $game->glossaryid2))."'"; |
|||
print_error( get_string( 'hiddenpicture_nomainquestion', 'game', $a)); |
|||
return false; |
|||
} |
|||
|
|||
// Have to select randomly one glossaryentry. |
|||
$poss = array(); |
|||
for ($i = 0; $i < count($ids); $i++) { |
|||
$poss[] = $i; |
|||
} |
|||
shuffle( $poss); |
|||
$minnum = 0; |
|||
$attachement = ''; |
|||
for ($i = 0; $i < count($ids); $i++) { |
|||
$pos = $poss[ $i]; |
|||
$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)) { |
|||
$minnum = $rec2->r; |
|||
$glossaryentryid = $tempid; |
|||
$attachement = $keys[ $pos]; |
|||
} |
|||
} else { |
|||
$glossaryentryid = $tempid; |
|||
$attachement = $keys[ $pos]; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
$sql = 'SELECT id, concept as answertext, definition as questiontext,'. |
|||
' id as glossaryentryid, 0 as questionid, glossaryid, attachment'. |
|||
' FROM {glossary_entries} WHERE id = '.$glossaryentryid; |
|||
if (($rec = $DB->get_record_sql( $sql)) == false) { |
|||
return false; |
|||
} |
|||
$query = new stdClass(); |
|||
$query->attemptid = $attempt->id; |
|||
$query->gamekind = $game->gamekind; |
|||
$query->gameid = $game->id; |
|||
$query->userid = $USER->id; |
|||
|
|||
$query->col = 0; |
|||
$query->sourcemodule = 'glossary'; |
|||
$query->questionid = 0; |
|||
$query->glossaryentryid = $rec->glossaryentryid; |
|||
$query->attachment = $attachement; |
|||
$query->questiontext = $rec->questiontext; |
|||
$query->answertext = $rec->answertext; |
|||
$query->score = 0; |
|||
if (($query->id = $DB->insert_record( 'game_queries', $query)) == 0) { |
|||
print_error( 'Error inserting in game_queries'); |
|||
} |
|||
$newrec = new stdClass(); |
|||
$newrec->id = $attempt->id; |
|||
$newrec->correct = 0; |
|||
if (!game_insert_record( 'game_hiddenpicture', $newrec)) { |
|||
print_error( 'Error inserting in game_hiddenpicture'); |
|||
} |
|||
|
|||
game_update_repetitions($game->id, $USER->id, $query->questionid, $query->glossaryentryid); |
|||
|
|||
return $newrec; |
|||
} |
|||
|
|||
function game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, $showsolution, $context) { |
|||
if ($game->toptext != '') { |
|||
echo $game->toptext.'<br>'; |
|||
} |
|||
|
|||
// Show picture. |
|||
$offsetquestions = game_sudoku_compute_offsetquestions( $game->sourcemodule, $attempt, $numbers, $correctquestions); |
|||
unset( $offsetquestions[ 0]); |
|||
|
|||
game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, |
|||
$offsetquestions, $correctquestions, $id, $attempt, $showsolution); |
|||
|
|||
// Show questions. |
|||
$onlyshow = false; |
|||
$showsolution = false; |
|||
|
|||
switch ($game->sourcemodule) { |
|||
case 'quiz': |
|||
case 'question': |
|||
game_sudoku_showquestions_quiz( $id, $game, $attempt, $hiddenpicture, $offsetquestions, |
|||
$numbers, $correctquestions, $onlyshow, $showsolution, $context); |
|||
break; |
|||
case 'glossary': |
|||
game_sudoku_showquestions_glossary( $id, $game, $attempt, $hiddenpicture, |
|||
$offsetquestions, $numbers, $correctquestions, $onlyshow, $showsolution); |
|||
break; |
|||
} |
|||
|
|||
if ($game->bottomtext != '') { |
|||
echo '<br><br>'.$game->bottomtext; |
|||
} |
|||
} |
|||
|
|||
function game_hidden_picture_computescore( $game, $hiddenpicture) { |
|||
$correct = $hiddenpicture->correct; |
|||
if ($hiddenpicture->found) { |
|||
$correct++; |
|||
} |
|||
$remaining = $game->param1 * $game->param2 - $hiddenpicture->correct; |
|||
$div2 = $correct + $hiddenpicture->wrong + $remaining; |
|||
if ($hiddenpicture->found) { |
|||
$percent = ($correct + $remaining) / $div2; |
|||
} else { |
|||
$percent = $correct / $div2; |
|||
} |
|||
|
|||
return $percent; |
|||
} |
|||
|
|||
function game_hiddenpicture_showhiddenpicture( $id, $game, $attempt, $hiddenpicture, $showsolution, |
|||
$offsetquestions, $correctquestions) { |
|||
global $DB; |
|||
|
|||
$foundcells = ''; |
|||
foreach ($correctquestions as $key => $val) { |
|||
$foundcells .= ','.$key; |
|||
} |
|||
$cells = ''; |
|||
foreach ($offsetquestions as $key => $val) { |
|||
if ($key != 0) { |
|||
$cells .= ','.$key; |
|||
} |
|||
} |
|||
|
|||
$query = $DB->get_record_select( 'game_queries', "attemptid=$hiddenpicture->id AND col=0", |
|||
null, 'id,glossaryentryid,attachment,questiontext'); |
|||
|
|||
// Grade. |
|||
echo "<br/>".get_string( 'grade', 'game').' : '.round( $attempt->score * 100).' %'; |
|||
|
|||
game_hiddenpicture_showquestion_glossary( $game, $id, $query); |
|||
|
|||
$cells = substr( $cells, 1); |
|||
$foundcells = substr( $foundcells, 1); |
|||
game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, true); |
|||
} |
|||
|
|||
function game_hiddenpicture_showquestion_glossary( $game, $id, $query) { |
|||
global $CFG, $DB; |
|||
|
|||
$entry = $DB->get_record( 'glossary_entries', array( 'id' => $query->glossaryentryid)); |
|||
|
|||
// Start the form. |
|||
echo '<br>'; |
|||
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('hiddenpicture_mainsubmit', 'game')."\"></center>\n"; |
|||
|
|||
// Add a hidden field with the queryid. |
|||
echo '<input type="hidden" name="id" value="' . s($id) . "\" />\n"; |
|||
echo '<input type="hidden" name="action" value="hiddenpicturecheckg" />'; |
|||
echo '<input type="hidden" name="queryid" value="' . $query->id . "\" />\n"; |
|||
|
|||
// Add a hidden field with glossaryentryid. |
|||
echo '<input type="hidden" name="glossaryentryid" value="'.$query->glossaryentryid."\" />\n"; |
|||
|
|||
$temp = $game->glossaryid; |
|||
$game->glossaryid = $game->glossaryid2; |
|||
echo game_show_query( $game, $query, $entry->definition); |
|||
$game->glossaryid = $temp; |
|||
|
|||
echo get_string( 'answer').': '; |
|||
echo "<input type=\"text\" name=\"answer\" size=30 /><br>"; |
|||
|
|||
echo "</form><br>\n"; |
|||
} |
|||
|
|||
function game_hiddenpicture_check_questions( $id, $game, &$attempt, &$hiddenpicture, $finishattempt) { |
|||
global $QTYPES, $DB; |
|||
|
|||
$responses = data_submitted(); |
|||
|
|||
$offsetquestions = game_sudoku_compute_offsetquestions( $game->sourcemodule, $attempt, $numbers, $correctquestions); |
|||
|
|||
$questionlist = game_sudoku_getquestionlist( $offsetquestions); |
|||
|
|||
$questions = game_sudoku_getquestions( $questionlist); |
|||
|
|||
$actions = question_extract_responses($questions, $responses, QUESTION_EVENTSUBMIT); |
|||
|
|||
$correct = $wrong = 0; |
|||
foreach ($questions as $question) { |
|||
if (!array_key_exists( $question->id, $actions)) { |
|||
// No answered. |
|||
continue; |
|||
} |
|||
unset( $state); |
|||
unset( $cmoptions); |
|||
$question->maxgrade = 100; |
|||
$state->responses = $actions[ $question->id]->responses; |
|||
$state->event = QUESTION_EVENTGRADE; |
|||
|
|||
$cmoptions = array(); |
|||
$QTYPES[$question->qtype]->grade_responses( $question, $state, $cmoptions); |
|||
|
|||
unset( $query); |
|||
|
|||
$select = "attemptid=$attempt->id"; |
|||
$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)"); |
|||
} |
|||
|
|||
$answertext = $state->responses[ '']; |
|||
if ($answertext != '') { |
|||
$grade = $state->raw_grade; |
|||
if ($grade < 50) { |
|||
// Wrong answer. |
|||
game_update_queries( $game, $attempt, $query, $grade / 100, $answertext); |
|||
$wrong++; |
|||
} else { |
|||
// Correct answer. |
|||
game_update_queries( $game, $attempt, $query, 1, $answertext); |
|||
$correct++; |
|||
} |
|||
} |
|||
} |
|||
|
|||
$hiddenpicture->correct += $correct; |
|||
$hiddenpicture->wrong += $wrong; |
|||
|
|||
if (!$DB->update_record( 'game_hiddenpicture', $hiddenpicture)) { |
|||
print_error( 'game_hiddenpicture_check_questions: error updating in game_hiddenpicture'); |
|||
} |
|||
|
|||
$attempt->score = game_hidden_picture_computescore( $game, $hiddenpicture); |
|||
if (!$DB->update_record( 'game_attempts', $attempt)) { |
|||
print_error( 'game_hiddenpicture_check_questions: error updating in game_attempt'); |
|||
} |
|||
|
|||
game_sudoku_check_last( $id, $game, $attempt, $hiddenpicture, $finishattempt); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
function game_hiddenpicture_check_mainquestion( $id, $game, &$attempt, &$hiddenpicture, $finishattempt, $context) { |
|||
global $QTYPES, $CFG, $DB; |
|||
|
|||
$responses = data_submitted(); |
|||
|
|||
$glossaryentryid = $responses->glossaryentryid; |
|||
$queryid = $responses->queryid; |
|||
|
|||
// Load the glossary entry. |
|||
if (!($entry = $DB->get_record( 'glossary_entries', array( 'id' => $glossaryentryid)))) { |
|||
print_error( get_string( 'noglossaryentriesfound', 'game')); |
|||
} |
|||
$answer = $responses->answer; |
|||
$correct = false; |
|||
if ($answer != '') { |
|||
if (game_upper( $entry->concept) == game_upper( $answer)) { |
|||
$correct = true; |
|||
} |
|||
} |
|||
|
|||
// Load the query. |
|||
if (!($query = $DB->get_record( 'game_queries', array( 'id' => $queryid)))) { |
|||
print_error( "The query $queryid not found"); |
|||
} |
|||
|
|||
game_update_queries( $game, $attempt, $query, $correct, $answer); |
|||
|
|||
if ($correct) { |
|||
$hiddenpicture->found = 1; |
|||
} else { |
|||
$hiddenpicture->wrong++; |
|||
} |
|||
if (!$DB->update_record( 'game_hiddenpicture', $hiddenpicture)) { |
|||
print_error( 'game_hiddenpicture_check_mainquestion: error updating in game_hiddenpicture'); |
|||
} |
|||
|
|||
$score = game_hidden_picture_computescore( $game, $hiddenpicture); |
|||
game_updateattempts( $game, $attempt, $score, $correct); |
|||
|
|||
if ($correct == false) { |
|||
game_hiddenpicture_play( $id, $game, $attempt, $hiddenpicture, false, $context); |
|||
return true; |
|||
} |
|||
|
|||
// Finish the game. |
|||
$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); |
|||
echo '<p><br/><font size="5" color="green">'.get_string( 'win', 'game').'</font><BR/><BR/></p>'; |
|||
global $CFG; |
|||
|
|||
echo '<br/>'; |
|||
|
|||
echo "<a href=\"$CFG->wwwroot/mod/game/attempt.php?id=$id\">"; |
|||
echo get_string( 'nextgame', 'game').'</a> '; |
|||
|
|||
if (! $cm = $DB->get_record( 'course_modules', array( 'id' => $id))) { |
|||
print_error( "Course Module ID was incorrect id=$id"); |
|||
} |
|||
|
|||
echo "<a href=\"{$CFG->wwwroot}/course/view.php?id=$cm->course\">".get_string( 'finish', 'game').'</a> '; |
|||
|
|||
return false; |
|||
} |
|||
|
|||
function game_showpicture( $id, $game, $attempt, $query, $cells, $foundcells, $usemap) { |
|||
global $CFG; |
|||
|
|||
$filenamenumbers = str_replace( "\\", '/', $CFG->dirroot)."/mod/game/hiddenpicture/numbers.png"; |
|||
if ($usemap) { |
|||
$cols = $game->param1; |
|||
$rows = $game->param2; |
|||
} else { |
|||
$cols = $rows = 0; |
|||
} |
|||
$params = "id=$id&id2=$attempt->id&f=$foundcells&cols=$cols&rows=$rows&cells=$cells&p={$query->attachment}&n=$filenamenumbers"; |
|||
$imagesrc = "hiddenpicture/picture.php?$params"; |
|||
|
|||
$fs = get_file_storage(); |
|||
$file = get_file_storage()->get_file_by_hash( $query->attachment); |
|||
$image = $file->get_imageinfo(); |
|||
if ($game->param4 > 10) { |
|||
$width = $game->param4; |
|||
$height = $image[ 'height'] * $width / $image[ 'width']; |
|||
} else if ( $game->param5 > 10) { |
|||
$height = $game->param5; |
|||
$width = $image[ 'width'] * $height / $image[ 'height']; |
|||
} else { |
|||
$width = $image[ 'width']; |
|||
$height = $image[ 'height']; |
|||
} |
|||
|
|||
echo "<IMG SRC=\"$imagesrc\" width=$width "; |
|||
if ($usemap) { |
|||
echo " USEMAP=\"#mapname\" "; |
|||
} |
|||
echo " BORDER=\"1\">\r\n"; |
|||
|
|||
if ($usemap) { |
|||
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