Browse Source

Fix: PHP coding style problems

MOODLE_20_STABLE
bdaloukas 8 years ago
parent
commit
b0ffb2d355
  1. 2
      cross/crossdb_class.php
  2. 340
      cross/play.php
  3. 46
      cryptex/play.php
  4. 2
      db/access.php
  5. 2
      db/importsnakes.php
  6. 2
      db/importsudoku.php
  7. 5
      db/upgrade.php
  8. 2
      export.php
  9. 4
      export/html/snakes/css/game.css
  10. 6
      export/html/snakes/css/snakes.css
  11. 1
      export/html/snakes/css/subModal.css
  12. 32
      export/html/snakes/js/snakes-mod.js
  13. 4
      exporthtml.php
  14. 64
      exporthtml_hangman.php
  15. 31
      exporthtml_millionaire.php
  16. 137
      exporthtml_snakes.php

2
cross/crossdb_class.php

@ -18,7 +18,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
/** /*
* This class is a cross that can load and save to a table * This class is a cross that can load and save to a table
* *
* @author bdaloukas * @author bdaloukas

340
cross/play.php

@ -469,83 +469,98 @@ function WordEntryKeyPress(event)
// Helper functions // Helper functions
// Returns true if the string passed in contains any characters prone to evil. // Returns true if the string passed in contains any characters prone to evil.
function ContainsBadChars(theirWord) function ContainsBadChars(theirWord) {
{return false; return false;
for (var i = 0; i < theirWord.length; i++)
for (var i = 0; i < theirWord.length; i++) {
if (BadChars.indexOf(theirWord.charAt(i)) >= 0) return true; if (BadChars.indexOf(theirWord.charAt(i)) >= 0) return true;
}
return false; return false;
} }
// Pads a number out to three characters. // Pads a number out to three characters.
function PadNumber(number) function PadNumber(number) {
{ if (number < 10) }
if (number < 10)
return "00" + number; return "00" + number;
else if (number < 100) } else if (number < 100) {
return "0" + number; return "0" + number;
else } else {
return "" + number; return "" + number;
}
} }
// Returns the table cell at a particular pair of coordinates. // Returns the table cell at a particular pair of coordinates.
function CellAt(x, y) function CellAt(x, y) {
{
return document.getElementById("c" + PadNumber(x) + PadNumber(y)); return document.getElementById("c" + PadNumber(x) + PadNumber(y));
} }
// Deselects the current word, if there's a word selected. DOES not change the value of CurrentWord. // Deselects the current word, if there's a word selected. DOES not change the value of CurrentWord.
function DeselectCurrentWord() function DeselectCurrentWord() {
{ if (CurrentWord < 0) {
if (CurrentWord < 0) return; return;
}
var x, y, i; var x, y, i;
document.getElementById("answerbox").style.display = "none"; document.getElementById("answerbox").style.display = "none";
document.getElementById("answerbox2").style.display = "none"; document.getElementById("answerbox2").style.display = "none";
ChangeCurrentWordSelectedStyle(false); ChangeCurrentWordSelectedStyle( false);
CurrentWord = -1; CurrentWord = -1;
} }
// Changes the style of the cells in the current word. // Changes the style of the cells in the current word.
function ChangeWordStyle(WordNumber, NewStyle) function ChangeWordStyle(WordNumber, NewStyle) {
{ if (WordNumber< 0) {
if (WordNumber< 0) return; return;
}
var x = WordX[WordNumber]; var x = WordX[WordNumber];
var y = WordY[WordNumber]; var y = WordY[WordNumber];
if (WordNumber<= LastHorizontalWord) if (WordNumber<= LastHorizontalWord) {
for (i = 0; i < WordLength[WordNumber]; i++) for (i = 0; i < WordLength[WordNumber]; i++) {
CellAt(x + i, y).className = NewStyle; CellAt(x + i, y).className = NewStyle;
else }
for (i = 0; i < WordLength[WordNumber]; i++) } else {
for (i = 0; i < WordLength[WordNumber]; i++) {
CellAt(x, y + i).className = NewStyle; CellAt(x, y + i).className = NewStyle;
}
}
} }
// Changes the style of the cells in the current word between the selected/unselected form. // Changes the style of the cells in the current word between the selected/unselected form.
function ChangeCurrentWordSelectedStyle(IsSelected) function ChangeCurrentWordSelectedStyle(IsSelected) {
{ if (CurrentWord < 0) {
if (CurrentWord < 0) return; return;
}
var x = WordX[CurrentWord]; var x = WordX[CurrentWord];
var y = WordY[CurrentWord]; var y = WordY[CurrentWord];
if (CurrentWord <= LastHorizontalWord) if (CurrentWord <= LastHorizontalWord) {
for (i = 0; i < WordLength[CurrentWord]; i++) for (i = 0; i < WordLength[CurrentWord]; i++) {
CellAt(x + i, y).className = CellAt(x + i, y).className.replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel"); CellAt(x + i, y).className = CellAt(x + i, y).className.
else replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel");
for (i = 0; i < WordLength[CurrentWord]; i++) }
CellAt(x, y + i).className = CellAt(x, y + i).className.replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel"); } else {
for (i = 0; i < WordLength[CurrentWord]; i++) {
CellAt(x, y + i).className = CellAt(x, y + i).className.
replace(IsSelected ? "_unsel" : "_sel", IsSelected ? "_sel" : "_unsel");
}
}
} }
// Selects the new word by parsing the name of the TD element referenced by the // Selects the new word by parsing the name of the TD element referenced by the
// event object, and then applying styles as necessary. // event object, and then applying styles as necessary.
function SelectThisWord(event) function SelectThisWord(event) {
{ if (CrosswordFinished) {
if (CrosswordFinished) return; return;
}
var x, y, i, TheirWord, TableCell; var x, y, i, TheirWord, TableCell;
// Deselect the previous word if one was selected. // Deselect the previous word if one was selected.
document.getElementById("welcomemessage").style.display = "none"; document.getElementById("welcomemessage").style.display = "none";
if (CurrentWord >= 0) OKClick(); if (CurrentWord >= 0) {
OKClick();
}
DeselectCurrentWord(); DeselectCurrentWord();
// Determine the coordinates of the cell they clicked, and then the word that // Determine the coordinates of the cell they clicked, and then the word that
@ -555,12 +570,13 @@ function SelectThisWord(event)
y = parseInt(target.id.substring(4, 7), 10); y = parseInt(target.id.substring(4, 7), 10);
// If they clicked an intersection, choose the type of word that was NOT selected last time. // If they clicked an intersection, choose the type of word that was NOT selected last time.
if (TableAcrossWord[x][y] >= 0 && TableDownWord[x][y] >= 0) if (TableAcrossWord[x][y] >= 0 && TableDownWord[x][y] >= 0) {
CurrentWord = PrevWordHorizontal ? TableDownWord[x][y] : TableAcrossWord[x][y]; CurrentWord = PrevWordHorizontal ? TableDownWord[x][y] : TableAcrossWord[x][y];
else if (TableAcrossWord[x][y] >= 0) } else if (TableAcrossWord[x][y] >= 0) {
CurrentWord = TableAcrossWord[x][y]; CurrentWord = TableAcrossWord[x][y];
else if (TableDownWord[x][y] >= 0) } else if (TableDownWord[x][y] >= 0) {
CurrentWord = TableDownWord[x][y]; CurrentWord = TableDownWord[x][y];
}
PrevWordHorizontal = (CurrentWord <= LastHorizontalWord); PrevWordHorizontal = (CurrentWord <= LastHorizontalWord);
@ -572,13 +588,13 @@ function SelectThisWord(event)
y = WordY[CurrentWord]; y = WordY[CurrentWord];
TheirWord = ""; TheirWord = "";
var TheirWordLength = 0; var TheirWordLength = 0;
for (i = 0; i < WordLength[CurrentWord]; i++) for (i = 0; i < WordLength[CurrentWord]; i++) {
{
// Find the appropriate table cell. // Find the appropriate table cell.
if (CurrentWord <= LastHorizontalWord) if (CurrentWord <= LastHorizontalWord) {
TableCell = CellAt(x + i, y); TableCell = CellAt(x + i, y);
else } else {
TableCell = CellAt(x, y + i); TableCell = CellAt(x, y + i);
}
// Add its contents to the word we're building. // Add its contents to the word we're building.
if (TableCell.innerHTML != null && TableCell.innerHTML.length > 0 && if (TableCell.innerHTML != null && TableCell.innerHTML.length > 0 &&
TableCell.innerHTML != " " && TableCell.innerHTML.toLowerCase() != "&nbsp;") { TableCell.innerHTML != " " && TableCell.innerHTML.toLowerCase() != "&nbsp;") {
@ -590,68 +606,63 @@ function SelectThisWord(event)
} }
document.getElementById("wordlabel").innerHTML = TheirWord; document.getElementById("wordlabel").innerHTML = TheirWord;
<?php <?php
$msg = "\"".get_string( 'cross_across', 'game').", \" : \"". $msg = "\"".get_string( 'cross_across', 'game').", \" : \"".get_string( 'cross_down', 'game').", \"";
get_string( 'cross_down', 'game').", \""; $letters = "\" ".get_string( 'letter', 'game').".\" : \" ".get_string( 'letters', 'game').".\"";
$letters = "\" ".get_string( 'letter', 'game').".\" : \" ". ?>
get_string( 'letters', 'game').".\"";
?>
var s = ((CurrentWord <= LastHorizontalWord) ? <?php echo $msg ?>); var s = ((CurrentWord <= LastHorizontalWord) ? <?php echo $msg ?>);
s = s + WordLength[CurrentWord] + (WordLength[CurrentWord] == 1 ? <?php echo $letters;?>); s = s + WordLength[CurrentWord] + (WordLength[CurrentWord] == 1 ? <?php echo $letters;?>);
document.getElementById("wordinfo").innerHTML = s; document.getElementById("wordinfo").innerHTML = s;
document.getElementById("wordclue").innerHTML = Clue[CurrentWord]; document.getElementById("wordclue").innerHTML = Clue[CurrentWord];
document.getElementById("worderror").style.display = "none"; document.getElementById("worderror").style.display = "none";
//document.getElementById("cheatbutton").style.display = (Word.length == 0) ? "none" : "";
if (TheirWordLength == WordLength[CurrentWord]) if (TheirWordLength == WordLength[CurrentWord]) {
document.getElementById("wordentry").value = TheirWord; document.getElementById("wordentry").value = TheirWord;
else } else {
document.getElementById("wordentry").value = ""; document.getElementById("wordentry").value = "";
}
// Finally, show the answer box. // Finally, show the answer box.
document.getElementById("answerbox").style.display = "block"; document.getElementById("answerbox").style.display = "block";
document.getElementById("answerbox2").style.display = "block"; document.getElementById("answerbox2").style.display = "block";
try try {
{
document.getElementById("wordentry").focus(); document.getElementById("wordentry").focus();
document.getElementById("wordentry").select(); document.getElementById("wordentry").select();
} }
catch (e) catch (e) {
{
} }
} }
// Called when the user clicks the OK link. // Called when the user clicks the OK link.
function OKClick() function OKClick() {
{
var TheirWord, x, y, i, TableCell; var TheirWord, x, y, i, TableCell;
if (CrosswordFinished) return; if (CrosswordFinished) {
if (document.getElementById("okbutton").disabled) return; return;
}
if (document.getElementById("okbutton").disabled) {
return;
}
// First, validate the entry. // First, validate the entry.
TheirWord = document.getElementById("wordentry").value.toUpperCase(); TheirWord = document.getElementById("wordentry").value.toUpperCase();
if (TheirWord.length == 0) if (TheirWord.length == 0) {
{
DeselectCurrentWord(); DeselectCurrentWord();
return; return;
} }
if (ContainsBadChars(TheirWord)) if (ContainsBadChars(TheirWord)) {
{
document.getElementById("worderror").innerHTML = "<?php echo get_string( 'cross_error_containsbadchars', 'game');?>"; document.getElementById("worderror").innerHTML = "<?php echo get_string( 'cross_error_containsbadchars', 'game');?>";
document.getElementById("worderror").style.display = "block"; document.getElementById("worderror").style.display = "block";
return; return;
} }
if (TheirWord.length < WordLength[CurrentWord]) if (TheirWord.length < WordLength[CurrentWord]) {
{
var s = "<?php echo get_string( 'cross_error_wordlength1', 'game');?>"; var s = "<?php echo get_string( 'cross_error_wordlength1', 'game');?>";
s = s + WordLength[CurrentWord] + " <?php echo get_string( 'cross_error_wordlength2', 'game');?>"; s = s + WordLength[CurrentWord] + " <?php echo get_string( 'cross_error_wordlength2', 'game');?>";
document.getElementById("worderror").innerHTML = s; document.getElementById("worderror").innerHTML = s;
document.getElementById("worderror").style.display = "block"; document.getElementById("worderror").style.display = "block";
return; return;
} }
if (TheirWord.length > WordLength[CurrentWord]) if (TheirWord.length > WordLength[CurrentWord]) {
{
var s = "<?php echo get_string( 'cross_error_wordlength1', 'game');?>"; var s = "<?php echo get_string( 'cross_error_wordlength1', 'game');?>";
s = s + WordLength[CurrentWord] + " <?php echo get_string( 'cross_error_wordlength2', 'game');?>"; s = s + WordLength[CurrentWord] + " <?php echo get_string( 'cross_error_wordlength2', 'game');?>";
document.getElementById("worderror").innerHTML = s; document.getElementById("worderror").innerHTML = s;
@ -662,8 +673,7 @@ function OKClick()
// If we made it this far, they typed an acceptable word, so add these letters to the puzzle and hide the entry box. // If we made it this far, they typed an acceptable word, so add these letters to the puzzle and hide the entry box.
x = WordX[CurrentWord]; x = WordX[CurrentWord];
y = WordY[CurrentWord]; y = WordY[CurrentWord];
for (i = 0; i < TheirWord.length; i++) for (i = 0; i < TheirWord.length; i++) {
{
TableCell = CellAt(x + (CurrentWord <= LastHorizontalWord ? i : 0), y + (CurrentWord > LastHorizontalWord ? i : 0)); TableCell = CellAt(x + (CurrentWord <= LastHorizontalWord ? i : 0), y + (CurrentWord > LastHorizontalWord ? i : 0));
TableCell.innerHTML = TheirWord.substring(i, i + 1); TableCell.innerHTML = TheirWord.substring(i, i + 1);
} }
@ -671,40 +681,33 @@ function OKClick()
} }
<?php <?php
if ($showhtmlsolutions == false) { if ($showhtmlsolutions == false) {
?> ?>
function PackPuzzle( sData) function PackPuzzle( sData) {
{ var i, s, s2, n, j;
var i;
var s;
var s2;
var n;
var j;
s = ""; s = "";
len = sData.length; len = sData.length;
for(i=0; i < len; i++) for(i=0; i < len; i++) {
{
c = sData.charAt( i); c = sData.charAt( i);
if( (c > "0") && (c <= "9")) if( (c > "0") && (c <= "9")) {
{
s = s.concat( '/'); s = s.concat( '/');
} }
s = s.concat( c); s = s.concat( c);
} }
for(;;) for(;;) {
{
i = s.indexOf( "__"); i = s.indexOf( "__");
if( i == -1) if( i == -1) {
break; break;
}
len = s.length; len = s.length;
for( j=i ; j < len; j++) for( j=i ; j < len; j++) {
{ if( s.charAt( j) != "_") {
if( s.charAt( j) != "_")
break; break;
} }
}
n = j - i; n = j - i;
s2 = s.substr( 0, i); s2 = s.substr( 0, i);
s2 = s2.concat( n); s2 = s2.concat( n);
@ -715,60 +718,61 @@ function PackPuzzle( sData)
} }
// Called when the "check server" link is clicked. // Called when the "check server" link is clicked.
function CheckServerClick( endofgame) function CheckServerClick( endofgame) {
{
var i, j, x, y, UserEntry, ErrorsFound = 0, EmptyFound = 0, TableCell; var i, j, x, y, UserEntry, ErrorsFound = 0, EmptyFound = 0, TableCell;
if (CrosswordFinished) if (CrosswordFinished) {
return; return;
}
DeselectCurrentWord(); DeselectCurrentWord();
for (y = 0; y < CrosswordHeight; y++) for (y = 0; y < CrosswordHeight; y++) {
for (x = 0; x < CrosswordWidth; x++) for (x = 0; x < CrosswordWidth; x++) {
{ if (TableAcrossWord[x][y] >= 0 || TableDownWord[x][y] >= 0) {
if (TableAcrossWord[x][y] >= 0 || TableDownWord[x][y] >= 0)
{
TableCell = CellAt(x, y); TableCell = CellAt(x, y);
if (TableCell.className == "box boxerror_unsel") if (TableCell.className == "box boxerror_unsel") {
TableCell.className = "box boxnormal_unsel"; TableCell.className = "box boxnormal_unsel";
} }
} }
}
}
sData = ""; sData = "";
for (i = 0; i < Words; i++) for (i = 0; i < Words; i++) {
{
// Get the user's entry for this word. // Get the user's entry for this word.
UserEntry = ""; UserEntry = "";
for (j = 0; j < WordLength[i]; j++) for (j = 0; j < WordLength[i]; j++) {
{ if (i <= LastHorizontalWord) {
if (i <= LastHorizontalWord)
TableCell = CellAt(WordX[i] + j, WordY[i]); TableCell = CellAt(WordX[i] + j, WordY[i]);
else } else {
TableCell = CellAt(WordX[i], WordY[i] + j); TableCell = CellAt(WordX[i], WordY[i] + j);
if (TableCell.innerHTML.length > 0 && TableCell.innerHTML.toLowerCase() != "&nbsp;") }
if (TableCell.innerHTML.length > 0 && TableCell.innerHTML.toLowerCase() != "&nbsp;") {
UserEntry += TableCell.innerHTML.toUpperCase(); UserEntry += TableCell.innerHTML.toUpperCase();
else if( TableCell.innerHTML.toLowerCase() == "&nbsp;") } else if( TableCell.innerHTML.toLowerCase() == "&nbsp;") {
UserEntry += " "; UserEntry += " ";
else } else {
UserEntry += "_"; UserEntry += "_";
} }
}
sData += UserEntry; sData += UserEntry;
} }
sData = PackPuzzle( sData); sData = PackPuzzle( sData);
if( endofgame) if( endofgame) {
sData += "&finishattempt=1"; sData += "&finishattempt=1";
}
<?php <?php
if ($onlyshow == false) { if ($onlyshow == false) {
global $CFG; global $CFG;
$params = 'id='.$id.'&action=crosscheck&g='; $params = 'id='.$id.'&action=crosscheck&g=';
echo "window.location = \"{$CFG->wwwroot}/mod/game/attempt.php?$params\"+ sData;\r\n"; echo "window.location = \"{$CFG->wwwroot}/mod/game/attempt.php?$params\"+ sData;\r\n";
} }
?> ?>
} }
<?php <?php
} }
?> ?>
function OnPrint() function OnPrint()
@ -781,10 +785,9 @@ function OnPrint()
} }
<?php <?php
if ($showhtmlprintbutton) { if ($showhtmlprintbutton) {
?> ?>
function PrintHtmlClick() function PrintHtmlClick() {
{
document.getElementById("printhtmlbutton").style.display = "none"; document.getElementById("printhtmlbutton").style.display = "none";
<?php <?php
@ -801,11 +804,11 @@ function OnPrint()
document.getElementById("printhtmlbutton").style.display = "block"; document.getElementById("printhtmlbutton").style.display = "block";
} }
<?php <?php
} }
?> ?>
<?php <?php
if ($showhtmlprintbutton) { if ($showhtmlprintbutton) {
?> ?>
/** /**
@ -830,7 +833,6 @@ var Base64 = {
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) { while (i < input.length) {
enc1 = this._keyStr.indexOf(input.charAt(i++)); enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++));
@ -867,62 +869,55 @@ var Base64 = {
if (c < 128) { if (c < 128) {
string += String.fromCharCode(c); string += String.fromCharCode(c);
i++; i++;
} } else if((c > 191) && (c < 224)) {
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1); c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2; i += 2;
} } else {
else {
c2 = utftext.charCodeAt(i+1); c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2); c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3; i += 3;
} }
} }
return string; return string;
} }
} }
// Called when the "checkhtml" link is clicked. // Called when the "checkhtml" link is clicked.
function CheckHtmlClick() function CheckHtmlClick() {
{
var i, TableCell, UserEntry, sData, solution; var i, TableCell, UserEntry, sData, solution;
sData = ""; sData = "";
for (i = 0; i < Words; i++) for (i = 0; i < Words; i++) {
{
solution = Base64.decode( HtmlSolutions[ i]); solution = Base64.decode( HtmlSolutions[ i]);
// Get the user's entry for this word. // Get the user's entry for this word.
UserEntry = ""; UserEntry = "";
for (j = 0; j < WordLength[i]; j++) for (j = 0; j < WordLength[i]; j++) {
{ if (i <= LastHorizontalWord) {
if (i <= LastHorizontalWord)
TableCell = CellAt(WordX[i] + j, WordY[i]); TableCell = CellAt(WordX[i] + j, WordY[i]);
else } else {
TableCell = CellAt(WordX[i], WordY[i] + j); TableCell = CellAt(WordX[i], WordY[i] + j);
if (TableCell.innerHTML.length > 0 && TableCell.innerHTML.toLowerCase() != "&nbsp;") }
if (TableCell.innerHTML.length > 0 && TableCell.innerHTML.toLowerCase() != "&nbsp;") {
UserEntry += TableCell.innerHTML.toUpperCase(); UserEntry += TableCell.innerHTML.toUpperCase();
else if( TableCell.innerHTML.toLowerCase() == "&nbsp;") } else if( TableCell.innerHTML.toLowerCase() == "&nbsp;") {
UserEntry += " "; UserEntry += " ";
else } else {
UserEntry += "_"; UserEntry += "_";
}
if( UserEntry[ j] != solution[ j]) if( UserEntry[ j] != solution[ j]) {
{
TableCell.innerHTML = "&nbsp;"; TableCell.innerHTML = "&nbsp;";
} }
} }
} }
} }
<?php <?php
} }
if ($showhtmlsolutions) { if ($showhtmlsolutions) {
?> ?>
function decodeutf8(utftext) { function decodeutf8(utftext) {
var string = ""; var string = "";
@ -954,7 +949,7 @@ function CheckHtmlClick()
return string; return string;
} }
<?php <?php
} }
?> ?>
//--> //-->
@ -963,18 +958,18 @@ function CheckHtmlClick()
</table></td> </table></td>
<?php <?php
if ($game->param3 == 2) { if ($game->param3 == 2) {
echo '<td>&nbsp &nbsp &nbsp</td>'; echo '<td>&nbsp &nbsp &nbsp</td>';
game_cross_show_legends( $cross); game_cross_show_legends( $cross);
} else { } else {
game_cross_show_welcome( $game); game_cross_show_welcome( $game);
} }
?> ?>
</tr></table> </tr></table>
<?php <?php
if ($onlyshow == false) { if ($onlyshow == false) {
echo '<div style="margin-top: 1em;">'; echo '<div style="margin-top: 1em;">';
echo '<button id="checkbutton" type="button" onclick="CheckServerClick( 0);" style="display: none;">'. echo '<button id="checkbutton" type="button" onclick="CheckServerClick( 0);" style="display: none;">'.
@ -992,62 +987,61 @@ function CheckHtmlClick()
} }
echo "</div>\r\n"; echo "</div>\r\n";
} }
if ($showhtmlsolutions or $showhtmlprintbutton) { if ($showhtmlsolutions or $showhtmlprintbutton) {
echo '<br>'; echo '<br>';
} }
if ($showhtmlsolutions) { if ($showhtmlsolutions) {
echo '<button id="checkhtmlbutton" type="button" '. echo '<button id="checkhtmlbutton" type="button" '.
' onclick="CheckHtmlClick();" visible=true>'.get_string( 'cross_checkbutton', 'game'); ' onclick="CheckHtmlClick();" visible=true>'.get_string( 'cross_checkbutton', 'game');
echo '</button>'; echo '</button>';
} }
if ($showhtmlprintbutton) { if ($showhtmlprintbutton) {
if ($showhtmlsolutions) { if ($showhtmlsolutions) {
echo "&nbsp;&nbsp;&nbsp;&nbsp;"; echo "&nbsp;&nbsp;&nbsp;&nbsp;";
} }
echo '<button id="printhtmlbutton" type="button" onclick="PrintHtmlClick( 0);" visible=true>'.get_string( 'print', 'game'); echo '<button id="printhtmlbutton" type="button" onclick="PrintHtmlClick( 0);" visible=true>'.get_string( 'print', 'game');
echo '</button>'; echo '</button>';
} }
if ($game->param3 == 2) { if ($game->param3 == 2) {
echo '<td>&nbsp &nbsp &nbsp</td>'; echo '<td>&nbsp &nbsp &nbsp</td>';
game_cross_show_welcome( $game); game_cross_show_welcome( $game);
} else { } else {
game_cross_show_legends( $cross); game_cross_show_legends( $cross);
} }
if ($game->bottomtext != '') { if ($game->bottomtext != '') {
echo '<br><br>'.$game->bottomtext; echo '<br><br>'.$game->bottomtext;
} }
if ($attempt != false) { if ($attempt != false) {
if ($attempt->timefinish == 0 and $endofgame == 0) { if ($attempt->timefinish == 0 and $endofgame == 0) {
?> ?>
<script language="JavaScript" type="text/javascript"><!-- <script language="JavaScript" type="text/javascript"><!--
if (Initialized) if (Initialized) {
{
<?php <?php
if ($print == false) { if ($print == false) {
echo "document.getElementById(\"welcomemessage\").style.display = \"\";"; echo "document.getElementById(\"welcomemessage\").style.display = \"\";";
} }
if ($showsolution == false) { if ($showsolution == false) {
?> ?>
document.getElementById("checkbutton").style.display = ""; document.getElementById("checkbutton").style.display = "";
document.getElementById("finishattemptbutton").style.display = ""; document.getElementById("finishattemptbutton").style.display = "";
document.getElementById("printbutton").style.display = ""; document.getElementById("printbutton").style.display = "";
<?php <?php
} }
?> ?>
} }
//--> //-->
</script> </script>
<?php <?php
} }
} }
?> ?>
@ -1079,17 +1073,17 @@ function game_cross_show_welcome0( $game) {
<div id="wordclue" class="cluebox"> </div> <div id="wordclue" class="cluebox"> </div>
<div style="margin-top:1em;"><input id="wordentry" type="text" size="24" <div style="margin-top:1em;"><input id="wordentry" type="text" size="24"
<?php <?php
echo 'style="font-weight: bold; '; echo 'style="font-weight: bold; ';
if ($game->param6 == 0) { if ($game->param6 == 0) {
echo 'text-transform:uppercase;'; echo 'text-transform:uppercase;';
} }
echo '"'; echo '"';
?> ?>
onkeypress="WordEntryKeyPress(event)" onchange="WordEntryKeyPress(event)" autocomplete="off"></div> onkeypress="WordEntryKeyPress(event)" onchange="WordEntryKeyPress(event)" autocomplete="off"></div>
<?php <?php
if ($game->param3 == 2) { if ($game->param3 == 2) {
game_cross_show_welcome( $game); game_cross_show_welcome( $game);
} }
?> ?>
<div id="worderror" style="color:#c00000;font-weight:bold;display:none;margin-top:1em;"></div> <div id="worderror" style="color:#c00000;font-weight:bold;display:none;margin-top:1em;"></div>

46
cryptex/play.php

@ -21,6 +21,8 @@
* @package game * @package game
**/ **/
defined('MOODLE_INTERNAL') || die();
require_once( "cryptexdb_class.php"); require_once( "cryptexdb_class.php");
function game_cryptex_continue( $id, $game, $attempt, $cryptexrec, $endofgame, $context) { function game_cryptex_continue( $id, $game, $attempt, $cryptexrec, $endofgame, $context) {
@ -267,18 +269,17 @@ width: 240pt;
<?php <?php
if ($showhtmlprintbutton) { if ($showhtmlprintbutton) {
echo '<br><button id="finishattemptbutton" type="button" onclick="OnEndGame();" >'.get_string( 'finish', 'game'); echo '<br><button id="finishattemptbutton" type="button" onclick="OnEndGame();" >'.get_string( 'finish', 'game');
echo '</button>'; echo '</button>';
echo '<button id="printbutton" type="button" onclick="OnPrint();" >'.get_string( 'print', 'game'); echo '<button id="printbutton" type="button" onclick="OnPrint();" >'.get_string( 'print', 'game');
echo '</button><br>'; echo '</button><br>';
} }
if ($showhtmlprintbutton) { if ($showhtmlprintbutton) {
?> ?>
<script> <script>
function PrintHtmlClick() function PrintHtmlClick() {
{
document.getElementById("printbutton").style.display = "none"; document.getElementById("printbutton").style.display = "none";
window.print(); window.print();
@ -286,8 +287,7 @@ width: 240pt;
document.getElementById("printbutton").style.display = "block"; document.getElementById("printbutton").style.display = "block";
} }
function OnPrint() function OnPrint() {
{
<?php <?php
global $CFG; global $CFG;
@ -296,8 +296,7 @@ width: 240pt;
?> ?>
} }
function OnEndGame() function OnEndGame() {
{
<?php <?php
global $CFG; global $CFG;
@ -307,12 +306,12 @@ width: 240pt;
} }
</script> </script>
<?php <?php
} }
$i = 0; $i = 0;
$else = ''; $else = '';
$contextglossary = false; $contextglossary = false;
foreach ($questions as $key => $q) { foreach ($questions as $key => $q) {
$i++; $i++;
if ($showsolution == false) { if ($showsolution == false) {
// When I want to show the solution a want to show the questions to. // When I want to show the solution a want to show the questions to.
@ -337,23 +336,21 @@ width: 240pt;
echo " &nbsp;&nbsp;&nbsp;$q->answertext<B></b>"; echo " &nbsp;&nbsp;&nbsp;$q->answertext<B></b>";
} }
echo '<br>'; echo '<br>';
} }
if ($game->bottomtext != '') { if ($game->bottomtext != '') {
echo '<br><br>'.$game->bottomtext; echo '<br><br>'.$game->bottomtext;
} }
?> ?>
<script> <script>
function OnCheck( id, question) function OnCheck( id, question) {
{
document.getElementById("q").value = id; document.getElementById("q").value = id;
document.getElementById("wordclue").innerHTML = question; document.getElementById("wordclue").innerHTML = question;
// Finally, show the answer box. // Finally, show the answer box.
document.getElementById("answerbox").style.display = "block"; document.getElementById("answerbox").style.display = "block";
try try {
{
document.getElementById("answer").focus(); document.getElementById("answer").focus();
document.getElementById("answer").select(); document.getElementById("answer").select();
} }
@ -363,12 +360,11 @@ width: 240pt;
} }
</script> </script>
<?php <?php
if ($print) {
if ($print) {
echo '<body onload="window.print()">'; echo '<body onload="window.print()">';
} else { } else {
echo '<body>'; echo '<body>';
} }
} }
function game_cryptex_onfinished( $id, $game, $attempt, $cryptexrec) { function game_cryptex_onfinished( $id, $game, $attempt, $cryptexrec) {

2
db/access.php

@ -16,7 +16,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
/** /*
* Capability definitions for the game module. * Capability definitions for the game module.
* *
* For naming conventions, see lib/db/access.php. * For naming conventions, see lib/db/access.php.

2
db/importsnakes.php

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die();
game_importsnakes(); game_importsnakes();
function game_importsnakes() { function game_importsnakes() {

2
db/importsudoku.php

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die();
$DB->execute( "INSERT INTO {game_sudoku_database}( level, opened, data) VALUES (1, 26, ". $DB->execute( "INSERT INTO {game_sudoku_database}( level, opened, data) VALUES (1, 26, ".
"'A73IEDB8642I16875CF85237A94539712D6HBGFC849158415FI3G28913BE64GFDB89753175C41692H')"); "'A73IEDB8642I16875CF85237A94539712D6HBGFC849158415FI3G28913BE64GFDB89753175C41692H')");
$DB->execute( "INSERT INTO {game_sudoku_database}( level, opened, data) VALUES (1, 29, ". $DB->execute( "INSERT INTO {game_sudoku_database}( level, opened, data) VALUES (1, 29, ".

5
db/upgrade.php

@ -33,6 +33,8 @@
* before any action that may take longer time to finish. * before any action that may take longer time to finish.
*/ */
defined('MOODLE_INTERNAL') || die();
function xmldb_game_upgrade($oldversion) { function xmldb_game_upgrade($oldversion) {
global $CFG, $DB; global $CFG, $DB;
@ -1549,10 +1551,9 @@ function xmldb_game_upgrade($oldversion) {
$table = new xmldb_table('game_cross'); $table = new xmldb_table('game_cross');
$field = new xmldb_field('createscore', XMLDB_TYPE_FLOAT, null, null, null, null, '0'); $field = new xmldb_field('createscore', XMLDB_TYPE_FLOAT, null, null, null, null, '0');
// Launch change of type for field thisfield // Launch change of type for field thisfield.
$dbman->change_field_type($table, $field); $dbman->change_field_type($table, $field);
} }
return true; return true;
} }

2
export.php

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /*
* This page exports a game to another platform e.g. html, jar * This page exports a game to another platform e.g. html, jar
* *
* @author bdaloukas * @author bdaloukas

4
export/html/snakes/css/game.css

@ -9,15 +9,12 @@
display:none; display:none;
} }
.img1 .img1
{ {
position:absolute; position:absolute;
display:none; display:none;
} }
#dicecont #dicecont
{ {
float:right; float:right;
@ -26,7 +23,6 @@
background-repeat: repeat; background-repeat: repeat;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
font-weight: normal; font-weight: normal;
/*font-variant: small-caps;*/
color: #FFFFFF; color: #FFFFFF;
border: 0.5em solid #333333; border: 0.5em solid #333333;
top: 30px; top: 30px;

6
export/html/snakes/css/snakes.css

@ -2,11 +2,9 @@
Husain Limdiyawala(MSc IT DA-IICT) Husain Limdiyawala(MSc IT DA-IICT)
Any Duplication of this code should be avoided*/ Any Duplication of this code should be avoided*/
.blocks .blocks
{ {
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
/*color: #FFFFFF;*/
margin-left: 5px; margin-left: 5px;
margin-top:2px; margin-top:2px;
margin-bottom:2px; margin-bottom:2px;
@ -45,7 +43,7 @@ Any Duplication of this code should be avoided*/
body body
{ {
background:#CCCCCC; background:#CCCCCC;
} }
#player #player
@ -69,7 +67,6 @@ background:#CCCCCC;
background-repeat: repeat; background-repeat: repeat;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
font-weight: bold; font-weight: bold;
/*font-variant: small-caps;*/
color: #FFFFFF; color: #FFFFFF;
border: 0.5em solid #333333; border: 0.5em solid #333333;
top: 30px; top: 30px;
@ -82,7 +79,6 @@ background:#CCCCCC;
margin-left:0.5em; margin-left:0.5em;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
font-weight: bold; font-weight: bold;
/*font-variant: small-caps;*/
color: #000000; color: #000000;
background-color: #FC0; background-color: #FC0;
padding: 1em; padding: 1em;

1
export/html/snakes/css/subModal.css

@ -25,6 +25,7 @@
background-repeat: repeat; background-repeat: repeat;
display:none; display:none;
} }
#popupContainer { #popupContainer {
position: absolute; position: absolute;
z-index: 201; z-index: 201;

32
export/html/snakes/js/snakes-mod.js

@ -6,7 +6,7 @@ $(document).ready(function () {
}); });
//Global Variables // Global Variables.
var totblocks = 0; var totblocks = 0;
var data = ""; var data = "";
var currentblock = 0; var currentblock = 0;
@ -20,12 +20,12 @@ var destsnake = new Array(4);
var ladsrc = new Array(3); var ladsrc = new Array(3);
var laddest = new Array(3); var laddest = new Array(3);
var quest = new Array(); //available questions along with multiple answers var quest = new Array(); // Available questions along with multiple answers.
var COR_answered = new Array(); //record all questions (along with answers) the user responded CORRECTLY var COR_answered = new Array(); // Record all questions (along with answers) the user responded CORRECTLY.
var WRO_answered = new Array(); //record all questions (along with answers) the user responded WRONGLY var WRO_answered = new Array(); // Record all questions (along with answers) the user responded WRONGLY.
var user = new Array(); var user = new Array();
//Constract table with questions and answers and pick question to display // Constract table with questions and answers and pick question to display.
quest[0] = "Spell 1"; quest[0] = "Spell 1";
quest[1] = "one"; quest[1] = "one";
@ -45,17 +45,16 @@ quest[14] = "three";
quest[15] = "one"; quest[15] = "one";
z = 0; z = 0;
for (z = 0; quest[z] != null; z++) { for (z = 0; quest[z] != null; z++) {
// Do nothing // Do nothing.
} }
allQuest = z / 4; allQuest = z / 4;
function selectQuest(all) function selectQuest(all) {
{
pickOne = Math.floor((Math.random() * all)); pickOne = Math.floor((Math.random() * all));
return pickOne; return pickOne;
} }
//The Below Function will hide all the snakes // The Below Function will hide all the snakes.
function hideAll() { function hideAll() {
document.getElementById("img1").style.display = "none"; document.getElementById("img1").style.display = "none";
@ -68,7 +67,7 @@ function hideAll() {
document.getElementById("lad3").style.display = "none"; document.getElementById("lad3").style.display = "none";
} }
//The Below Function will Render The Main Board // The Below Function will Render The Main Board.
function paintBoard(a) { function paintBoard(a) {
totblocks = (a * a); totblocks = (a * a);
@ -136,7 +135,7 @@ function paintBoard(a) {
} }
} }
//The below Function will simulate throwing of a dice // The below Function will simulate throwing of a dice.
function throwDice(i) { function throwDice(i) {
randomno = Math.floor((Math.random() * 6)) + 1; randomno = Math.floor((Math.random() * 6)) + 1;
document.getElementById("diceimg").src = "images/dice_" + randomno + ".PNG"; document.getElementById("diceimg").src = "images/dice_" + randomno + ".PNG";
@ -175,7 +174,7 @@ function snakescheck(k) {
} }
} }
//The below function checks the ladders for a user // The below function checks the ladders for a user.
function laddercheck(k) { function laddercheck(k) {
i = 0; i = 0;
@ -194,13 +193,12 @@ function laddercheck(k) {
} }
} }
//The below Function checks for pythons // The below Function checks for pythons.
function pythoncheck(k) { function pythoncheck(k) {
i = 0; i = 0;
for (i = 0; i < pythons.length; i++) { for (i = 0; i < pythons.length; i++) {
if (pythons[i] == tots[k]) { if (pythons[i] == tots[k]) {
alert("You have been eaten up by a python.Your game is over"); alert("You have been eaten up by a python.Your game is over");
document.getElementById(tots[k]).style.background = "url(images/csnake.gif) #000000"; document.getElementById(tots[k]).style.background = "url(images/csnake.gif) #000000";
@ -219,7 +217,7 @@ function registerSnake(tp, lft, dv, src, dest, i) {
destsnake[i] = dest; destsnake[i] = dest;
} }
// The below function will register a ladder.. // The below function will register a ladder.
function registerLadder(tp, lft, dv, src, dest, i) { function registerLadder(tp, lft, dv, src, dest, i) {
document.getElementById(dv).style.top = tp + "px"; document.getElementById(dv).style.top = tp + "px";
document.getElementById(dv).style.left = lft + "px"; document.getElementById(dv).style.left = lft + "px";
@ -227,7 +225,7 @@ function registerLadder(tp, lft, dv, src, dest, i) {
laddest[i] = dest; laddest[i] = dest;
} }
//The below function checks the change in the boardtype selection combobox // The below function checks the change in the boardtype selection combobox.
function selectBoard() { function selectBoard() {
totblocks = 0; totblocks = 0;
data = ""; data = "";
@ -312,6 +310,6 @@ function Question() {
WRO_answered.concat(quest.splice(picked * 4, 4)); WRO_answered.concat(quest.splice(picked * 4, 4));
} }
// Remove question and answers from available questions - (thus not allowing to have a Repeated question) ---XOXOXO // Remove question and answers from available questions - (thus not allowing to have a Repeated question).
allQuest--; allQuest--;
} }

4
exporthtml.php

@ -14,13 +14,15 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /*
* This page export the game to html for games: cross, hangman * This page export the game to html for games: cross, hangman
* *
* @author bdaloukas * @author bdaloukas
* @package game * @package game
**/ **/
defined('MOODLE_INTERNAL') || die();
require_once( "locallib.php"); require_once( "locallib.php");
require_once( "exportjavame.php"); require_once( "exportjavame.php");

64
exporthtml_hangman.php

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /*
* This page export the game hangman to html * This page export the game hangman to html
* *
* @author bdaloukas * @author bdaloukas
@ -152,20 +152,17 @@ function selectLetter(l)
used_letters_all += l; used_letters_all += l;
if( to_guess.indexOf(l) == -1) if( to_guess.indexOf(l) == -1) {
{
used_letters += l; used_letters += l;
document.getElementById('usedLetters').innerHTML = used_letters; document.getElementById('usedLetters').innerHTML = used_letters;
} }
if (to_guess.indexOf(l) != -1) if (to_guess.indexOf(l) != -1) {
{
// correct letter guess // correct letter guess
pos = 0; pos = 0;
temp_mask = display_word; temp_mask = display_word;
while (to_guess.indexOf(l, pos) != -1) while (to_guess.indexOf(l, pos) != -1) {
{
pos = to_guess.indexOf(l, pos); pos = to_guess.indexOf(l, pos);
end = pos + 1; end = pos + 1;
@ -179,15 +176,13 @@ function selectLetter(l)
display_word = temp_mask; display_word = temp_mask;
document.getElementById('displayWord').innerHTML=display_word; document.getElementById('displayWord').innerHTML=display_word;
if (display_word.indexOf("#") == -1) if (display_word.indexOf("#") == -1) {
{
// won // won
alert( "<?php echo game_get_string_lang( 'win', 'game', $lang); ?>"); alert( "<?php echo game_get_string_lang( 'win', 'game', $lang); ?>");
can_play = false; can_play = false;
reset(); reset();
} }
}else } else {
{
wrong_guesses++; wrong_guesses++;
<?php <?php
@ -198,8 +193,7 @@ if ($html->type != 'hangmanp') {
<?php <?php
} }
?> ?>
if (wrong_guesses == <?php echo $game->param10 + 1;?>) if (wrong_guesses == <?php echo $game->param10 + 1;?>) {
{
// lost // lost
alert( "<?php echo strip_tags( game_get_string_lang( 'hangman_loose', 'game', $lang)); ?>"); alert( "<?php echo strip_tags( game_get_string_lang( 'hangman_loose', 'game', $lang)); ?>");
can_play = false; can_play = false;
@ -216,8 +210,7 @@ function stripHTML(oldString) {
} }
function reset() function reset() {
{
selectWord(); selectWord();
document.getElementById('usedLetters').innerHTML = "&nbsp;"; document.getElementById('usedLetters').innerHTML = "&nbsp;";
@ -234,40 +227,36 @@ if ($html->type != 'hangmanp') {
} }
function showallletters() function showallletters() {
{
var letters = ""; var letters = "";
var next = all_letters.length / 4; var next = all_letters.length / 4;
var letter = ""; var letter = "";
for( i=0; i < all_letters.length; i++) for( i=0; i < all_letters.length; i++) {
{ if( i > next) {
if( i > next)
{
next += all_letters.length / 4; next += all_letters.length / 4;
letters += " "; letters += " ";
} }
letter = all_letters[ i]; letter = all_letters[ i];
if( used_letters_all.length > 0) if( used_letters_all.length > 0) {
{ if( used_letters_all.indexOf( letter) > -1) {
if( used_letters_all.indexOf( letter) > -1)
continue; continue;
} }
}
letters = letters + "<a href=\"javascript:selectLetter('" + letter + "');\">" + letter + "</a>" letters = letters + "<a href=\"javascript:selectLetter('" + letter + "');\">" + letter + "</a>"
} }
document.getElementById( "letters").innerHTML = letters; document.getElementById( "letters").innerHTML = letters;
} }
function selectWord() function selectWord() {
{
can_play = true; can_play = true;
random_number = Math.round(Math.random() * (words.length - 1)); random_number = Math.round(Math.random() * (words.length - 1));
to_guess = Base64.decode( words[random_number]); to_guess = Base64.decode( words[random_number]);
to_question = Base64.decode( questions[random_number]); to_question = Base64.decode( questions[random_number]);
// display masked word // Display masked word.
masked_word = createMask(to_guess); masked_word = createMask(to_guess);
document.getElementById('displayWord').innerHTML=masked_word; document.getElementById('displayWord').innerHTML=masked_word;
@ -288,8 +277,7 @@ function createMask(m)
word_lenght = m.length; word_lenght = m.length;
for (i = 0; i < word_lenght; i ++) for (i = 0; i < word_lenght; i++) {
{
mask += "#"; mask += "#";
} }
@ -305,10 +293,10 @@ function createMask(m)
var Base64 = { var Base64 = {
// private property // Private property.
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for decoding // Public method for decoding.
decode : function (input) { decode : function (input) {
var output = ""; var output = "";
var chr1, chr2, chr3; var chr1, chr2, chr3;
@ -318,7 +306,6 @@ var Base64 = {
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) { while (i < input.length) {
enc1 = this._keyStr.indexOf(input.charAt(i++)); enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++));
@ -341,40 +328,34 @@ var Base64 = {
output = Base64._utf8_decode(output); output = Base64._utf8_decode(output);
return output; return output;
}, },
// private method for UTF-8 decoding // Private method for UTF-8 decoding.
_utf8_decode : function (utftext) { _utf8_decode : function (utftext) {
var string = ""; var string = "";
var i = 0; var i = 0;
var c = c1 = c2 = 0; var c = c1 = c2 = 0;
while ( i < utftext.length ) { while ( i < utftext.length ) {
c = utftext.charCodeAt(i); c = utftext.charCodeAt(i);
if (c < 128) { if (c < 128) {
string += String.fromCharCode(c); string += String.fromCharCode(c);
i++; i++;
} } else if((c > 191) && (c < 224)) {
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1); c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2; i += 2;
} } else {
else {
c2 = utftext.charCodeAt(i+1); c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2); c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3; i += 3;
} }
} }
return string; return string;
} }
} }
</script> </script>
</head> </head>
@ -389,4 +370,3 @@ var Base64 = {
<div id="letters"></div> <div id="letters"></div>
</body> </body>

31
exporthtml_millionaire.php

@ -305,8 +305,7 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
} }
} }
function SelectNextQuestion() function SelectNextQuestion() {
{
current_question = Math.floor(Math.random()*questions.length); current_question = Math.floor(Math.random()*questions.length);
question = Base64.decode( questions[ current_question]); question = Base64.decode( questions[ current_question]);
@ -316,14 +315,12 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
RandomizeAnswers( elements); RandomizeAnswers( elements);
document.getElementById( "question").innerHTML = elements[ 0]; document.getElementById( "question").innerHTML = elements[ 0];
for( i=1; i < elements.length; i++) for( i=1; i < elements.length; i++) {
{
document.getElementById( "lblAnswer" + i).innerHTML = elements[ i]; document.getElementById( "lblAnswer" + i).innerHTML = elements[ i];
document.getElementById( "lblAnswer" + i).style.visibility = 'visible'; document.getElementById( "lblAnswer" + i).style.visibility = 'visible';
document.getElementById( "btAnswer" + i).style.visibility = 'visible'; document.getElementById( "btAnswer" + i).style.visibility = 'visible';
} }
for( i=elements.length; i<= maxQuestions; i++) for( i=elements.length; i<= maxQuestions; i++) {
{
document.getElementById( "lblAnswer" + i).style.visibility = 'hidden'; document.getElementById( "lblAnswer" + i).style.visibility = 'hidden';
document.getElementById( "btAnswer" + i).style.visibility = 'hidden'; document.getElementById( "btAnswer" + i).style.visibility = 'hidden';
} }
@ -340,10 +337,10 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
var Base64 = { var Base64 = {
// private property // Private property.
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for decoding // Public method for decoding.
decode : function (input) { decode : function (input) {
var output = ""; var output = "";
var chr1, chr2, chr3; var chr1, chr2, chr3;
@ -376,7 +373,6 @@ var Base64 = {
output = Base64._utf8_decode(output); output = Base64._utf8_decode(output);
return output; return output;
}, },
// private method for UTF-8 decoding // private method for UTF-8 decoding
@ -390,30 +386,23 @@ var Base64 = {
if (c < 128) { if (c < 128) {
string += String.fromCharCode(c); string += String.fromCharCode(c);
i++; i++;
} } else if((c > 191) && (c < 224)) {
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1); c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2; i += 2;
} } else {
else {
c2 = utftext.charCodeAt(i+1); c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2); c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3; i += 3;
} }
} }
return string; return string;
} }
} }
</script> </script>
<table cellpadding=0 cellspacing=0 border=0> <table cellpadding=0 cellspacing=0 border=0>
<tr style='background:#408080'> <tr style='background:#408080'>
<td rowspan=<?php echo 17 + $maxquestions;?>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td rowspan=<?php echo 17 + $maxquestions;?>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
@ -499,8 +488,8 @@ var Base64 = {
</tr> </tr>
<?php <?php
$letters = get_string( 'lettersall', 'game'); $letters = get_string( 'lettersall', 'game');
for ($i = 1; $i <= $maxquestions; $i++) { for ($i = 1; $i <= $maxquestions; $i++) {
$s = game_substr( $letters, $i - 1, 1); $s = game_substr( $letters, $i - 1, 1);
echo "<tr>\n"; echo "<tr>\n";
echo "<td style='background:$colorback;color:$color1'>"; echo "<td style='background:$colorback;color:$color1'>";
@ -515,7 +504,7 @@ var Base64 = {
echo "<td style='background:#408080' rowspan=".$maxquestions." colspan=3><div id=\"info\"></div></td>\n"; echo "<td style='background:#408080' rowspan=".$maxquestions." colspan=3><div id=\"info\"></div></td>\n";
} }
echo "</tr>\n"; echo "</tr>\n";
} }
?> ?>
<tr><td colspan=10 style='background:#408080'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr> <tr><td colspan=10 style='background:#408080'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>

137
exporthtml_snakes.php

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /*
* This page export the game snakes to html * This page export the game snakes to html
* *
* @author bdaloukas * @author bdaloukas
@ -39,26 +39,27 @@ defined('MOODLE_INTERNAL') || die();
<style type="text/css"> <style type="text/css">
#pawn #pawn
{ {
position:absolute; position:absolute;
} }
img img
{ {
border:hidden border:hidden
} }
body body
{ {
background: #999 url('images/backdropJungle.png') no-repeat fixed left top; background: #999 url('images/backdropJungle.png') no-repeat fixed left top;
} }
.score
{color: #FC3; .score {
color: #FC3;
font-size: 40px; font-size: 40px;
} }
</style> </style>
</head> </head>
<body> <body>
<script language="JavaScript"> <script language="JavaScript">
@ -164,14 +165,13 @@ function ShowMainForm()
document.getElementById("boardimage").src = "images/" + board_images[ current_board]; document.getElementById("boardimage").src = "images/" + board_images[ current_board];
document.write('<div id="dicecont">&nbsp;</div>'); document.write('<div id="dicecont">&nbsp;</div>');
if( current_position >= 0) if( current_position >= 0) {
{
direction=Math.floor((current_position /cols))%2; direction=Math.floor((current_position /cols))%2;
if (direction==1) if (direction == 1) {
axis_x=(cols-(current_position %cols)-1); axis_x=(cols-(current_position %cols)-1);
else } else {
axis_x=current_position %cols; axis_x=current_position %cols;
}
axis_y=Math.floor((current_position /rows)); axis_y=Math.floor((current_position /rows));
pawn_x=board_headerx[current_board]+(axis_x*col_width)+(col_width-pawn_width[current_board])/2; pawn_x=board_headerx[current_board]+(axis_x*col_width)+(col_width-pawn_width[current_board])/2;
pawn_y=board_footery[current_board]+pawn_height[current_board]+(axis_y*col_height)+(col_height-pawn_height[current_board])/2; pawn_y=board_footery[current_board]+pawn_height[current_board]+(axis_y*col_height)+(col_height-pawn_height[current_board])/2;
@ -181,14 +181,12 @@ function ShowMainForm()
} }
} }
function selectBoard() function selectBoard() {
{
current_board = document.getElementById("boardtype").value; current_board = document.getElementById("boardtype").value;
document.getElementById("boardimage").src = "images/" + board_images[ current_board]; document.getElementById("boardimage").src = "images/" + board_images[ current_board];
} }
function select_quest() function select_quest() {
{
var quest_total = countofquestionsM + countofquestionsS; var quest_total = countofquestionsM + countofquestionsS;
var quest_candidates= new Array(); var quest_candidates= new Array();
var i, q; var i, q;
@ -208,36 +206,32 @@ function select_quest()
quest_feedb = Base64decode( feedbacks[ current_quest]); quest_feedb = Base64decode( feedbacks[ current_quest]);
} }
function IsMultipleChoiceQuestion() function IsMultipleChoiceQuestion() {
{
return (current_quest < countofquestionsM); return (current_quest < countofquestionsM);
} }
function check_answer() function check_answer() {
{
all_ans=all_ans+1; all_ans=all_ans+1;
if( IsMultipleChoiceQuestion()) if( IsMultipleChoiceQuestion()) {
check_answer_M(); check_answer_M();
else } else {
check_answer_S(); check_answer_S();
}
move_pawn(); move_pawn();
} }
function check_answer_M() function check_answer_M() {
{
document.getElementById("check_btn").style.display = "none"; document.getElementById("check_btn").style.display = "none";
var useranswer; var useranswer;
var n=document.snakesform.radio_answer.length; var n=document.snakesform.radio_answer.length;
for(useranswer=0;useranswer < n;useranswer++) for(useranswer=0;useranswer < n;useranswer++) {
{
if( document.snakesform.radio_answer[ useranswer].checked) if( document.snakesform.radio_answer[ useranswer].checked)
break; break;
} }
if( useranswer >= n) if( useranswer >= n) {
{
alert( str_no_selection); alert( str_no_selection);
document.getElementById("feedb").innerHTML= ""; document.getElementById("feedb").innerHTML= "";
document.getElementById("check_btn").style.display = "block"; document.getElementById("check_btn").style.display = "block";
@ -254,17 +248,14 @@ function check_answer_M()
document.getElementById("feedb").innerHTML= feedbacks[ mchoice_positions[useranswer]]; document.getElementById("feedb").innerHTML= feedbacks[ mchoice_positions[useranswer]];
document.getElementById("feedb").style.display = "block"; document.getElementById("feedb").style.display = "block";
if ( mchoice_positions[ useranswer] == 1) if ( mchoice_positions[ useranswer] == 1) {
{
current_position += current_dice; current_position += current_dice;
correct_ans =correct_ans+1; //calculate new score---- correct_ans =correct_ans+1; //calculate new score----
score = Math.round((correct_ans/all_ans)*100); score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>'; document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
check_game_over(); check_game_over();
check_exists_ladder(); check_exists_ladder();
} } else {
else
{
score = Math.round((correct_ans/all_ans)*100); score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>'; document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
check_exists_snake(); check_exists_snake();
@ -273,13 +264,11 @@ function check_answer_M()
document.getElementById("OK_btn").style.display = "block"; document.getElementById("OK_btn").style.display = "block";
} }
function check_answer_S() function check_answer_S() {
{
document.getElementById("answer").disabled = "true"; document.getElementById("answer").disabled = "true";
document.getElementById("check_btn").style.display = "none"; document.getElementById("check_btn").style.display = "none";
if (document.getElementById("answer").value.toUpperCase() == quest_resp[ 1].toUpperCase()) if (document.getElementById("answer").value.toUpperCase() == quest_resp[ 1].toUpperCase()) {
{
document.getElementById("feedb").style.display = "block"; document.getElementById("feedb").style.display = "block";
current_position += current_dice; current_position += current_dice;
correct_ans =correct_ans+1; //calculate new score correct_ans =correct_ans+1; //calculate new score
@ -287,9 +276,7 @@ function check_answer_S()
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>'; document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
check_game_over(); check_game_over();
check_exists_ladder(); check_exists_ladder();
} } else {
else
{
document.getElementById("feedb_wrong").style.display = "block"; document.getElementById("feedb_wrong").style.display = "block";
score = Math.round((correct_ans/all_ans)*100); score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>'; document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
@ -299,49 +286,46 @@ function check_answer_S()
document.getElementById("OK_btn").style.display = "block"; document.getElementById("OK_btn").style.display = "block";
} }
function check_game_over() function check_game_over() {
{
var out=(board_cols[current_board]*board_rows[current_board]); var out=(board_cols[current_board]*board_rows[current_board]);
if (current_position > out-1) if (current_position > out-1) {
{
current_position=out-1; current_position=out-1;
showPopWin('modalContent.html', 350, 220, returnRefresh); // modal showPopWin('modalContent.html', 350, 220, returnRefresh); // modal
} }
} }
function check_exists_ladder() function check_exists_ladder() {
{
var find = "L" + (current_position+1) + "-"; var find = "L" + (current_position+1) + "-";
var pos = board_contents[ current_board].indexOf( find); var pos = board_contents[ current_board].indexOf( find);
if( pos < 0) if( pos < 0) {
return; return;
}
var s = board_contents[ current_board].substr( pos+find.length) var s = board_contents[ current_board].substr( pos+find.length)
pos = s.indexOf( ','); pos = s.indexOf( ',');
if( pos >= 0) if (pos >= 0) {
s = s.substr( 0, pos); s = s.substr( 0, pos);
}
current_position = s-1; current_position = s-1;
} }
function check_exists_snake() function check_exists_snake() {
{
var find = "-" + (current_position+1) + ","; var find = "-" + (current_position+1) + ",";
var s= ',' +board_contents[ current_board] + ','; var s= ',' +board_contents[ current_board] + ',';
for(;;) for(;;) {
{
var pos = s.indexOf( find); var pos = s.indexOf( find);
if( pos < 0) if (pos < 0) {
return; return;
}
var pos_start = s.lastIndexOf( ',', pos-1); var pos_start = s.lastIndexOf( ',', pos-1);
var kind = s.substr( pos_start+1, 1); var kind = s.substr( pos_start+1, 1);
if( kind != "S") if ( kind != "S") {
{
s = s.substr( pos+1); s = s.substr( pos+1);
continue; continue;
} }
@ -352,16 +336,13 @@ function check_exists_snake()
} }
} }
function decode_multiple_choice(s) function decode_multiple_choice(s) {
{
var ret = new Array(); var ret = new Array();
var i=0; var i=0;
for(;;) for(;;) {
{
var pos=s.indexOf( '#'); var pos=s.indexOf( '#');
if( pos < 0) if( pos < 0) {
{
ret[ i++] = s; ret[ i++] = s;
return ret; return ret;
} }
@ -370,19 +351,18 @@ function decode_multiple_choice(s)
} }
} }
function display_quest() function display_quest() {
{
current_dice = Math.floor((Math.random() * 6)) + 1; current_dice = Math.floor((Math.random() * 6)) + 1;
select_quest(); select_quest();
if( IsMultipleChoiceQuestion()) if( IsMultipleChoiceQuestion()) {
display_quest_M(); display_quest_M();
else } else {
display_quest_S(); display_quest_S();
}
} }
function display_quest_M() function display_quest_M() {
{
s = '<table width="250px"><tr><td><div id="show_dice"> '; s = '<table width="250px"><tr><td><div id="show_dice"> ';
s = s + '<img src = "images/dice' + current_dice + '.png"> </div> </td>'; s = s + '<img src = "images/dice' + current_dice + '.png"> </div> </td>';
s = s + '<td align=right><div id="show_score" style="color: #FFFFFF; font-weight:bold; font-size: 20px;">'; s = s + '<td align=right><div id="show_score" style="color: #FFFFFF; font-weight:bold; font-size: 20px;">';
@ -393,10 +373,10 @@ function display_quest_M()
mchoice_count = quest_resp.length-1; mchoice_count = quest_resp.length-1;
mchoice_positions = new Array( mchoice_count); mchoice_positions = new Array( mchoice_count);
for(i=0; i < mchoice_count ; i++) for(i=0; i < mchoice_count ; i++) {
mchoice_positions[ i] = i+1; mchoice_positions[ i] = i+1;
for(i=0; i < mchoice_count ; i++) }
{ for(i=0; i < mchoice_count ; i++) {
var j = Math.floor((Math.random() * mchoice_count)); var j = Math.floor((Math.random() * mchoice_count));
var temp = mchoice_positions[ i]; var temp = mchoice_positions[ i];
mchoice_positions[ i] = mchoice_positions[ j]; mchoice_positions[ i] = mchoice_positions[ j];
@ -421,8 +401,7 @@ function display_quest_M()
document.getElementById("check_btn").style.display = "block"; document.getElementById("check_btn").style.display = "block";
} }
function display_quest_S() function display_quest_S() {
{
var s = ""; var s = "";
s = '<table width="250px"><tr><td><div id="show_dice"> <img src = "images/dice'; s = '<table width="250px"><tr><td><div id="show_dice"> <img src = "images/dice';
@ -440,9 +419,7 @@ function display_quest_S()
document.getElementById("check_btn").style.display = "block"; document.getElementById("check_btn").style.display = "block";
} }
function move_pawn() function move_pawn() {
{
var pawn_x =0; var pawn_x =0;
var pawn_y=0; var pawn_y=0;
var direction=0; var direction=0;
@ -451,13 +428,13 @@ function move_pawn()
var col_width = (board_width[current_board]-board_headerx[current_board]-board_footerx[current_board])/cols; var col_width = (board_width[current_board]-board_headerx[current_board]-board_footerx[current_board])/cols;
var col_height = (board_height[current_board]-board_headery[current_board]-board_footery[current_board])/rows; var col_height = (board_height[current_board]-board_headery[current_board]-board_footery[current_board])/rows;
if( current_position >= 0) if( current_position >= 0) {
{
direction=Math.floor((current_position /cols))%2; direction=Math.floor((current_position /cols))%2;
if (direction == 1) { if (direction == 1) {
axis_x=(cols-(current_position %cols)-1); axis_x=(cols-(current_position %cols)-1);
}else } else {
axis_x=current_position %cols; axis_x=current_position %cols;
}
axis_y=Math.floor((current_position /rows)); axis_y=Math.floor((current_position /rows));
pawn_x=board_headerx[current_board]+(axis_x*col_width)+(col_width-pawn_width[current_board])/2; pawn_x=board_headerx[current_board]+(axis_x*col_width)+(col_width-pawn_width[current_board])/2;
@ -505,7 +482,7 @@ function move_pawn()
}; };
// private method for UTF-8 decoding // Private method for UTF-8 decoding.
function Base64_utf8_decode(utftext) { function Base64_utf8_decode(utftext) {
var string = ""; var string = "";
var i = 0; var i = 0;

Loading…
Cancel
Save