Browse Source

Fix: PHP coding style problems

MOODLE_20_STABLE
bdaloukas 8 years ago
parent
commit
b0ffb2d355
  1. 2
      cross/crossdb_class.php
  2. 894
      cross/play.php
  3. 132
      cryptex/play.php
  4. 2
      db/access.php
  5. 2
      db/importsnakes.php
  6. 2
      db/importsudoku.php
  7. 11
      db/upgrade.php
  8. 4
      export.php
  9. 40
      export/html/snakes/css/game.css
  10. 54
      export/html/snakes/css/modal.css
  11. 142
      export/html/snakes/css/snakes.css
  12. 16
      export/html/snakes/css/style.css
  13. 101
      export/html/snakes/css/subModal.css
  14. 230
      export/html/snakes/js/snakes-mod.js
  15. 6
      exporthtml.php
  16. 196
      exporthtml_hangman.php
  17. 413
      exporthtml_millionaire.php
  18. 463
      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

894
cross/play.php

File diff suppressed because it is too large

132
cryptex/play.php

@ -16,11 +16,13 @@
/** /**
* This page plays the cryptex game * This page plays the cryptex game
* *
* @author bdaloukas * @author bdaloukas
* @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,27 +269,25 @@ 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();
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,68 +306,65 @@ 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.
if (array_key_exists( $q->id, $corrects)) { if (array_key_exists( $q->id, $corrects)) {
continue; continue;
}
} }
}
$question = game_show_query( $game, $q, "$i. ".$q->questiontext, $context); $question = game_show_query( $game, $q, "$i. ".$q->questiontext, $context);
$question2 = strip_tags($question); // ADDED BY DP (AUG 2009) - fixes " breaking the Answer button for this question. $question2 = strip_tags($question); // ADDED BY DP (AUG 2009) - fixes " breaking the Answer button for this question.
echo "<script>var msg{$q->id}=".json_encode( $question2).';</script>';
if (($onlyshow == false) and ($showsolution == false)) {
if (($game->param8 == 0) || ($game->param8 > $q->tries)) {
$question .= ' &nbsp;<input type="submit" value="'.
get_string( 'answer').'" onclick="OnCheck( '.$q->id.",msg{$q->id});\" />";
}
}
echo $question;
if ($showsolution) { echo "<script>var msg{$q->id}=".json_encode( $question2).';</script>';
echo " &nbsp;&nbsp;&nbsp;$q->answertext<B></b>"; if (($onlyshow == false) and ($showsolution == false)) {
if (($game->param8 == 0) || ($game->param8 > $q->tries)) {
$question .= ' &nbsp;<input type="submit" value="'.
get_string( 'answer').'" onclick="OnCheck( '.$q->id.",msg{$q->id});\" />";
} }
echo '<br>';
} }
echo $question;
if ($game->bottomtext != '') { if ($showsolution) {
echo '<br><br>'.$game->bottomtext; echo " &nbsp;&nbsp;&nbsp;$q->answertext<B></b>";
} }
echo '<br>';
}
if ($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").select();
document.getElementById("answer").focus(); }
document.getElementById("answer").select(); catch (e)
} {
catch (e) }
{ }
} </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, ".

11
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;
@ -1544,15 +1546,14 @@ function xmldb_game_upgrade($oldversion) {
upgrade_mod_savepoint(true, $ver, 'game'); upgrade_mod_savepoint(true, $ver, 'game');
} }
if ($oldversion < ($ver = 2016062603)) { if ($oldversion < ($ver = 2016062603)) {
$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;
} }

4
export.php

@ -14,9 +14,9 @@
// 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
* @package game * @package game
**/ **/

40
export/html/snakes/css/game.css

@ -1,37 +1,33 @@
.nodis .nodis
{ {
list-style-type:none; list-style-type:none;
} }
#cont #cont
{ {
position:relative; position:relative;
display:none; display:none;
} }
.img1 .img1
{ {
position:absolute; position:absolute;
display:none; display:none;
} }
#dicecont #dicecont
{ {
float:right; float:right;
width:250px; width:250px;
background-image: url(../images/meter.png); background-image: url(../images/meter.png);
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; position: absolute;
position: absolute; left: 500px;
left: 500px; font-size: 14px;
font-size: 14px; padding: 10px;
padding: 10px;
} }

54
export/html/snakes/css/modal.css

@ -1,39 +1,39 @@
@charset "utf-8"; @charset "utf-8";
#fade { /*--Transparent background layer--*/ #fade { /*--Transparent background layer--*/
display: none; /*--hidden by default--*/ display: none; /*--hidden by default--*/
background: #000; background: #000;
position: fixed; left: 0; top: 0; position: fixed; left: 0; top: 0;
width: 100%; height: 100%; width: 100%; height: 100%;
opacity: .80; opacity: .80;
z-index: 9999; z-index: 9999;
} }
.popup_block{ .popup_block{
display: none; /*--hidden by default--*/ display: none; /*--hidden by default--*/
background: #fff; background: #fff;
padding: 20px; padding: 20px;
border: 20px solid #ddd; border: 20px solid #ddd;
float: left; float: left;
font-size: 1.2em; font-size: 1.2em;
position: fixed; position: fixed;
top: 50%; left: 50%; top: 50%; left: 50%;
z-index: 99999; z-index: 99999;
/*--CSS3 Box Shadows--*/ /*--CSS3 Box Shadows--*/
-webkit-box-shadow: 0px 0px 20px #000; -webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000; -moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000; box-shadow: 0px 0px 20px #000;
/*--CSS3 Rounded Corners--*/ /*--CSS3 Rounded Corners--*/
-webkit-border-radius: 10px; -webkit-border-radius: 10px;
-moz-border-radius: 10px; -moz-border-radius: 10px;
border-radius: 10px; border-radius: 10px;
} }
img.btn_close { img.btn_close {
float: right; float: right;
margin: -55px -55px 0 0; margin: -55px -55px 0 0;
} }
/*--Making IE6 Understand Fixed Positioning--*/ /*--Making IE6 Understand Fixed Positioning--*/
*html #fade { *html #fade {
position: absolute; position: absolute;
} }
*html .popup_block { *html .popup_block {
position: absolute; position: absolute;
} }

142
export/html/snakes/css/snakes.css

@ -2,130 +2,126 @@
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; padding: 0px;
padding: 0px; float:left;
float:left; height: 52px;
height: 52px; width: 52px;
width: 52px; display:block;
display:block; position:relative;
position:relative; background-image: url(../square52.png);
background-image: url(../square52.png);
} }
.nodis .nodis
{ {
list-style-type:none; list-style-type:none;
} }
#cont #cont
{ {
position:relative; position:relative;
display:none; display:none;
} }
#diceimg #diceimg
{ {
display:none; display:none;
width:45px; width:45px;
height:44px; height:44px;
} }
.img1 .img1
{ {
position:absolute; position:absolute;
display:none; display:none;
} }
body body
{ {
background:#CCCCCC; background:#CCCCCC;
} }
#player #player
{ {
display:none; display:none;
z-index:5; z-index:5;
position:absolute; position:absolute;
} }
#players #players
{ {
margin-top: 0.3em; margin-top: 0.3em;
margin-bottom: 1em; margin-bottom: 1em;
} }
#dicecont #dicecont
{ {
float:right; float:right;
width:170px; width:170px;
background-image: url(../images/meter.png); background-image: url(../images/meter.png);
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; position: absolute;
position: absolute; right: 880px;
right: 880px;
} }
#playbtn #playbtn
{ {
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;
} }
/*-- from modal window coding --*/ /*-- from modal window coding --*/
#fade { /*--Transparent background layer--*/ #fade { /*--Transparent background layer--*/
display: none; /*--hidden by default--*/ display: none; /*--hidden by default--*/
background: #000; background: #000;
position: fixed; left: 0; top: 0; position: fixed; left: 0; top: 0;
width: 100%; height: 100%; width: 100%; height: 100%;
opacity: .80; opacity: .80;
z-index: 9999; z-index: 9999;
} }
.popup_block{ .popup_block{
display: none; /*--hidden by default--*/ display: none; /*--hidden by default--*/
background: #fff; background: #fff;
padding: 20px; padding: 20px;
border: 20px solid #ddd; border: 20px solid #ddd;
float: left; float: left;
font-size: 1.2em; font-size: 1.2em;
position: fixed; position: fixed;
top: 50%; left: 50%; top: 50%; left: 50%;
z-index: 99999; z-index: 99999;
/*--CSS3 Box Shadows--*/ /*--CSS3 Box Shadows--*/
-webkit-box-shadow: 0px 0px 20px #000; -webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000; -moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000; box-shadow: 0px 0px 20px #000;
/*--CSS3 Rounded Corners--*/ /*--CSS3 Rounded Corners--*/
-webkit-border-radius: 10px; -webkit-border-radius: 10px;
-moz-border-radius: 10px; -moz-border-radius: 10px;
border-radius: 10px; border-radius: 10px;
} }
img.btn_close { img.btn_close {
float: right; float: right;
margin: -55px -55px 0 0; margin: -55px -55px 0 0;
border: 0; border: 0;
} }
/*--Making IE6 Understand Fixed Positioning--*/ /*--Making IE6 Understand Fixed Positioning--*/
*html #fade { *html #fade {
position: absolute; position: absolute;
} }
*html .popup_block { *html .popup_block {
position: absolute; position: absolute;
} }

16
export/html/snakes/css/style.css

@ -1,15 +1,15 @@
body { body {
background-color: #efefef; background-color: #efefef;
} }
body, html, input { body, html, input {
font-family:Verdana, Arial, Helvetica, sans-serif; font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px; font-size:11px;
color: #333333; color: #333333;
} }
.info { .info {
font-style:italic; font-style:italic;
font-size: 0.9em; font-size: 0.9em;
color: #666666; color: #666666;
} }

101
export/html/snakes/css/subModal.css

@ -2,68 +2,69 @@
* POPUP CONTAINER STYLES * POPUP CONTAINER STYLES
*/ */
#popupMask { #popupMask {
position: absolute; position: absolute;
z-index: 200; z-index: 200;
top: 0px; top: 0px;
left: 0px; left: 0px;
width: 100%; width: 100%;
height: 100%; height: 100%;
opacity: .4; opacity: .4;
filter: alpha(opacity=50); filter: alpha(opacity=50);
/* this hack is so it works in IE /* this hack is so it works in IE
* I find setting the color in the css gives me more flexibility * I find setting the color in the css gives me more flexibility
* than the PNG solution. * than the PNG solution.
*/ */
background-color:transparent !important; background-color:transparent !important;
background-color: #333333; background-color: #333333;
/* this hack is for opera support /* this hack is for opera support
* you can uncomment the background-image if you don't care about opera. * you can uncomment the background-image if you don't care about opera.
* this gives you the flexibility to use any bg color that you want, instead of the png * this gives you the flexibility to use any bg color that you want, instead of the png
*/ */
background-image/**/: url("../images/maskBG.png") !important; // For browsers Moz, Opera, etc. background-image/**/: url("../images/maskBG.png") !important; // For browsers Moz, Opera, etc.
background-image:none; background-image:none;
background-repeat: repeat; background-repeat: repeat;
display:none; display:none;
} }
#popupContainer { #popupContainer {
position: absolute; position: absolute;
z-index: 201; z-index: 201;
top: 0px; top: 0px;
left: 0px; left: 0px;
display:none; display:none;
padding: 0px; padding: 0px;
} }
#popupInner { #popupInner {
border: 2px solid #000000; border: 2px solid #000000;
background-color: #ffffff; background-color: #ffffff;
} }
#popupFrame { #popupFrame {
margin: 0px; margin: 0px;
width: 100%; width: 100%;
height: 100%; height: 100%;
position: relative; position: relative;
z-index: 202; z-index: 202;
} }
#popupTitleBar { #popupTitleBar {
background-color: #090; background-color: #090;
color: # 000; color: # 000;
font-weight: bold; font-weight: bold;
height: 1.3em; height: 1.3em;
padding: 5px; padding: 5px;
border-bottom: 2px solid #000000; border-bottom: 2px solid #000000;
border-top: 1px solid #78A3F2; border-top: 1px solid #78A3F2;
border-left: 1px solid #78A3F2; border-left: 1px solid #78A3F2;
border-right: 1px solid #204095; border-right: 1px solid #204095;
position: relative; position: relative;
z-index: 203; z-index: 203;
} }
#popupTitle { #popupTitle {
float:left; float:left;
font-size: 1.1em; font-size: 1.1em;
} }
#popupControls { #popupControls {
float: right; float: right;
cursor: pointer; cursor: pointer;
cursor: hand; cursor: hand;
} }

230
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,30 +45,29 @@ 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";
document.getElementById("img2").style.display = "none"; document.getElementById("img2").style.display = "none";
document.getElementById("img3").style.display = "none"; document.getElementById("img3").style.display = "none";
document.getElementById("img4").style.display = "none"; document.getElementById("img4").style.display = "none";
document.getElementById("lad1").style.display = "none"; document.getElementById("lad1").style.display = "none";
document.getElementById("lad2").style.display = "none"; document.getElementById("lad2").style.display = "none";
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);
@ -88,42 +87,42 @@ function paintBoard(a) {
currentblock -= (a - 1); currentblock -= (a - 1);
} }
} else { } else {
currentblock = (a * a); currentblock = (a * a);
for (j = 0; j < (a / 2); j++) { for (j = 0; j < (a / 2); j++) {
for (i = 0; i < a; i++) { for (i = 0; i < a; i++) {
data += "<div class='blocks' id='" + currentblock + "'>" + currentblock + "</div>"; data += "<div class='blocks' id='" + currentblock + "'>" + currentblock + "</div>";
currentblock--; currentblock--;
} }
currentblock -= (a - 1); currentblock -= (a - 1);
if (currentblock < 2) { if (currentblock < 2) {
break; break;
} }
for (i = 0; i < a; i++) { for (i = 0; i < a; i++) {
data += "<div id='" + currentblock + "' class ='blocks'>" + currentblock + "</div>"; data += "<div id='" + currentblock + "' class ='blocks'>" + currentblock + "</div>";
currentblock++; currentblock++;
} }
currentblock -= (a + 1); currentblock -= (a + 1);
} }
} }
document.getElementById("cont").style.width = (a * 52 + 52) + "px" document.getElementById("cont").style.width = (a * 52 + 52) + "px"
document.getElementById("cont").innerHTML = data; document.getElementById("cont").innerHTML = data;
$("#cont").slideDown("slow"); $("#cont").slideDown("slow");
$("#cont").effect("shake",3000); $("#cont").effect("shake",3000);
$("img:hidden").fadeIn(5000); $("img:hidden").fadeIn(5000);
if (a == 6) { if (a == 6) {
registerSnake(158, 196, "img1", 14, 3, 0); registerSnake(158, 196, "img1", 14, 3, 0);
registerSnake(62, 183, "img2", 27, 24, 1); registerSnake(62, 183, "img2", 27, 24, 1);
registerSnake(175, 18, "img3", 18, 4, 2); registerSnake(175, 18, "img3", 18, 4, 2);
registerSnake(10, 45, "img4", 32, 23, 3); registerSnake(10, 45, "img4", 32, 23, 3);
registerLadder(27, 132, "lad1", 28, 34, 0); registerLadder(27, 132, "lad1", 28, 34, 0);
registerLadder(90, 22, "lad2", 19, 30, 1); registerLadder(90, 22, "lad2", 19, 30, 1);
registerLadder(179, 137, "lad3", 2, 16, 2); registerLadder(179, 137, "lad3", 2, 16, 2);
} else if (a == 8) { } else if (a == 8) {
registerSnake(300, 380, "img1", 44, 29, 0); registerSnake(300, 380, "img1", 44, 29, 0);
registerSnake(180, 550, "img2", 51, 46, 1); registerSnake(180, 550, "img2", 51, 46, 1);
@ -136,98 +135,97 @@ 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";
document.getElementById("diceimg").style.display = "block"; document.getElementById("diceimg").style.display = "block";
if (lastposition[i] > 0) { if (lastposition[i] > 0) {
document.getElementById(lastposition[i]).style.background = "url(images/square52.png)"; document.getElementById(lastposition[i]).style.background = "url(images/square52.png)";
} }
tots[i] += randomno; tots[i] += randomno;
if (totblocks - tots[i] >= 0) { if (totblocks - tots[i] >= 0) {
lastposition[i] = tots[i]; lastposition[i] = tots[i];
document.getElementById(tots[i]).style.background = "url(images/pawn1.png)"; document.getElementById(tots[i]).style.background = "url(images/pawn1.png)";
} else { } else {
tots[i] -= randomno; tots[i] -= randomno;
document.getElementById(tots[i]).style.background = "url(images/pawn1.png)"; document.getElementById(tots[i]).style.background = "url(images/pawn1.png)";
} }
} }
// The below Function Checks The Snake Biting for a user. // The below Function Checks The Snake Biting for a user.
function snakescheck(k) { function snakescheck(k) {
i = 0; i = 0;
for(i = 0; i <= srcsnake.length; i++) { for(i = 0; i <= srcsnake.length; i++) {
if (srcsnake[i] == tots[k]) { if (srcsnake[i] == tots[k]) {
alert("Ωχ! Σε τσίμπησε φίδι στο τετράγωνο " + srcsnake[i] + " και θα πρέπει να γυρίσεις στο τετράγωνο " + destsnake[i] + ", εκτός κι αν απαντήσεις σωστά στην ερώτηση που ακολουθεί."); alert("Ωχ! Σε τσίμπησε φίδι στο τετράγωνο " + srcsnake[i] + " και θα πρέπει να γυρίσεις στο τετράγωνο " + destsnake[i] + ", εκτός κι αν απαντήσεις σωστά στην ερώτηση που ακολουθεί.");
document.getElementById(destsnake[i]).style.background = "url(images/pawn1.png)"; document.getElementById(destsnake[i]).style.background = "url(images/pawn1.png)";
document.getElementById(tots[k]).style.background = "url(images/square52.png)"; document.getElementById(tots[k]).style.background = "url(images/square52.png)";
lastposition[k] = destsnake[i]; lastposition[k] = destsnake[i];
tots[k] = destsnake[i]; tots[k] = destsnake[i];
break; break;
} }
} }
if (!checkWin(k)) { if (!checkWin(k)) {
alert("???d?se?!S???a??t???a!"); alert("???d?se?!S???a??t???a!");
} }
} }
//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;
for(i = 0; i <= ladsrc.length; i++) { for(i = 0; i <= ladsrc.length; i++) {
if (ladsrc[i] == tots[k]) { if (ladsrc[i] == tots[k]) {
alert("Υπάρχει μια σκάλα στο τετράγωνο " + ladsrc[i] + " και θα σας οδηγήσει κατευθείαν στο τετράγωνο " + laddest[i] + "αν απαντήσεις σωστά στην ερώτηση που ακολουθεί."); alert("Υπάρχει μια σκάλα στο τετράγωνο " + ladsrc[i] + " και θα σας οδηγήσει κατευθείαν στο τετράγωνο " + laddest[i] + "αν απαντήσεις σωστά στην ερώτηση που ακολουθεί.");
document.getElementById(laddest[i]).style.background = "url(images/pawn1.png)"; document.getElementById(laddest[i]).style.background = "url(images/pawn1.png)";
document.getElementById(tots[k]).style.background = "url(images/square52.png)"; document.getElementById(tots[k]).style.background = "url(images/square52.png)";
lastposition[k] = laddest[i]; lastposition[k] = laddest[i];
tots[k] = laddest[i]; tots[k] = laddest[i];
break; break;
} }
} }
if(!checkWin(k)) { if(!checkWin(k)) {
alert("You have won!"); alert("You have won!");
} }
} }
//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"; lastposition[k] = null;
lastposition[k] = null; tots[k] = null;
tots[k] = null; break;
break; }
} }
}
} }
// The below function will register a snake. // The below function will register a snake.
function registerSnake(tp, lft, dv, src, dest, i) { function registerSnake(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";
srcsnake[i] = src; srcsnake[i] = src;
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";
ladsrc[i] = src; ladsrc[i] = src;
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 = "";
@ -244,24 +242,24 @@ function selectBoard() {
function selectPlayer() { function selectPlayer() {
if (document.getElementById("players").value != null) { if (document.getElementById("players").value != null) {
user[document.getElementById("players").value - 1] = 0; user[document.getElementById("players").value - 1] = 0;
tots[document.getElementById("players").value - 1] = 0; tots[document.getElementById("players").value - 1] = 0;
lastposition[document.getElementById("players").value - 1] = 0; lastposition[document.getElementById("players").value - 1] = 0;
for(var j = 0; j < lastposition.length; j++) { for(var j = 0; j < lastposition.length; j++) {
lastposition[j] = 0; lastposition[j] = 0;
tots[j] = 0; tots[j] = 0;
} }
} }
} }
// The below function starts the play. // The below function starts the play.
function play() { function play() {
if (tots[l] != null) { if (tots[l] != null) {
disableField(); disableField();
document.getElementById("status").innerHTML = "<ul class='nodis'><li>O Paiktis " + (l + 1) + " </li><li>brisketai sto tetragwno " + tots[l] + "</li><li></li></ul>"; document.getElementById("status").innerHTML = "<ul class='nodis'><li>O Paiktis " + (l + 1) + " </li><li>brisketai sto tetragwno " + tots[l] + "</li><li></li></ul>";
Question(); Question();
document.getElementById("status").innerHTML = "<ul class='nodis'><li>O Paiktis " + (l + 1) + " </li><li>vrisketai sto tetragwno " + tots[l] + "</li></ul>"; document.getElementById("status").innerHTML = "<ul class='nodis'><li>O Paiktis " + (l + 1) + " </li><li>vrisketai sto tetragwno " + tots[l] + "</li></ul>";
} else { } else {
document.getElementById("status").innerHTML = "<ul class='nodis'><li>Molis exases...</li></ul>"; document.getElementById("status").innerHTML = "<ul class='nodis'><li>Molis exases...</li></ul>";
} }
@ -277,7 +275,7 @@ function doit(i) {
throwDice(i); throwDice(i);
if (checkWin(i)) { if (checkWin(i)) {
snakescheck(i); snakescheck(i);
laddercheck(i); laddercheck(i);
} else { } else {
alert("ÏëïêëÞñùóåò ôçí ðßóôá, óõã÷áñçôÞñéá!!!"); alert("ÏëïêëÞñùóåò ôçí ðßóôá, óõã÷áñçôÞñéá!!!");
} }
@ -285,7 +283,7 @@ function doit(i) {
// The below function checks whether the player has won or not. // The below function checks whether the player has won or not.
function checkWin(i) { function checkWin(i) {
if( tots[i] == totblocks) { if( tots[i] == totblocks) {
return false; return false;
} else { } else {
return true; return true;
@ -294,8 +292,8 @@ function checkWin(i) {
// The below function will disable both the combobox . // The below function will disable both the combobox .
function disableField() { function disableField() {
document.getElementById("players").disabled = "disabled"; document.getElementById("players").disabled = "disabled";
document.getElementById("boardtype").disabled = "disabled"; document.getElementById("boardtype").disabled = "disabled";
} }
function Question() { function Question() {
@ -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--;
} }

6
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");

196
exporthtml_hangman.php

@ -14,9 +14,9 @@
// 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
* @package game * @package game
**/ **/
@ -129,7 +129,7 @@ var display_word = "";
var used_letters = ""; var used_letters = "";
var wrong_guesses = 0; var wrong_guesses = 0;
var used_letters_all = ""; var used_letters_all = "";
var all_letters = new Array(<?php var all_letters = new Array(<?php
$len = game_strlen( $allletters); $len = game_strlen( $allletters);
for ($i = 0; $i < $len; $i++) { for ($i = 0; $i < $len; $i++) {
if ($i > 0) { if ($i > 0) {
@ -149,24 +149,21 @@ function selectLetter(l)
{ {
return; return;
} }
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;
start_text = temp_mask.substring(0, pos); start_text = temp_mask.substring(0, pos);
@ -178,16 +175,14 @@ 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,25 +227,22 @@ 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>"
@ -260,14 +250,13 @@ function showallletters()
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,76 +293,69 @@ 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;
var enc1, enc2, enc3, enc4; var enc1, enc2, enc3, enc4;
var i = 0; var i = 0;
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++)); enc4 = this._keyStr.indexOf(input.charAt(i++));
enc4 = this._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4;
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
if (enc3 != 64) { output = output + String.fromCharCode(chr2);
output = output + String.fromCharCode(chr2); }
} if (enc4 != 64) {
if (enc4 != 64) { output = output + String.fromCharCode(chr3);
output = output + String.fromCharCode(chr3); }
} }
}
output = Base64._utf8_decode(output);
output = Base64._utf8_decode(output);
return output;
return output; },
},
// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
// Private method for UTF-8 decoding.
_utf8_decode : function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
} else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
} }
</script> </script>
</head> </head>
@ -389,4 +370,3 @@ var Base64 = {
<div id="letters"></div> <div id="letters"></div>
</body> </body>

413
exporthtml_millionaire.php

@ -16,7 +16,7 @@
/** /**
* This page export the game millionaire to html * This page export the game millionaire to html
* *
* @author bdaloukas * @author bdaloukas
* @package game * @package game
**/ **/
@ -120,28 +120,28 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
var countQuestions = 0; var countQuestions = 0;
var maxQuestions = <?php echo $maxquestions;?>; var maxQuestions = <?php echo $maxquestions;?>;
function Highlite( ans) { function Highlite( ans) {
document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $color2;?>'; document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $color2;?>';
} }
function Restore( ans) { function Restore( ans) {
document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $colorback;?>'; document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $colorback;?>';
} }
function OnSelectAnswer( ans) { function OnSelectAnswer( ans) {
if ( posCorrect == ans) { if ( posCorrect == ans) {
if( level+1 > 15) { if( level+1 > 15) {
alert( "<?php echo get_string( 'win', 'game');?>"); alert( "<?php echo get_string( 'win', 'game');?>");
Reset(); Reset();
} else { } else {
UpdateLevel( level+1); UpdateLevel( level+1);
SelectNextQuestion(); SelectNextQuestion();
} }
} else { } else {
OnGameOver( ans); OnGameOver( ans);
} }
} }
function OnGameOver( ans) { function OnGameOver( ans) {
document.getElementById( "info").innerHTML = "<?php echo get_string( 'millionaire_info_wrong_answer', 'game');?> " + document.getElementById( "info").innerHTML = "<?php echo get_string( 'millionaire_info_wrong_answer', 'game');?> " +
document.getElementById( "lblAnswer" + posCorrect).innerHTML; document.getElementById( "lblAnswer" + posCorrect).innerHTML;
@ -150,38 +150,38 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
document.getElementById( "lblAnswer" + posCorrect).style.backgroundColor = '<?php echo $color2;?>'; document.getElementById( "lblAnswer" + posCorrect).style.backgroundColor = '<?php echo $color2;?>';
alert( "<?php echo strip_tags( get_string( 'hangman_loose', 'game')); ?>"); alert( "<?php echo strip_tags( get_string( 'hangman_loose', 'game')); ?>");
Restore( posCorrect); Restore( posCorrect);
document.getElementById( "lblAnswer" + posCorrect).style.backgroundColor = '<?php echo $colorback;?>'; document.getElementById( "lblAnswer" + posCorrect).style.backgroundColor = '<?php echo $colorback;?>';
Reset(); Reset();
} }
function UpdateLevel( newlevel) { function UpdateLevel( newlevel) {
if ( level > 0) { if ( level > 0) {
document.getElementById( "levela" + level).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levela" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelb" + level).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levelb" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelc" + level).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levelc" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levela" + level).style.color = "<?php echo $color1;?>"; document.getElementById( "levela" + level).style.color = "<?php echo $color1;?>";
document.getElementById( "levelb" + level).style.color = "<?php echo $color1;?>"; document.getElementById( "levelb" + level).style.color = "<?php echo $color1;?>";
document.getElementById( "levelc" + level).style.color = "<?php echo $color1;?>"; document.getElementById( "levelc" + level).style.color = "<?php echo $color1;?>";
}
level = newlevel;
document.getElementById( "levela" + level).bgColor = "<?php echo $color2;?>";
document.getElementById( "levelb" + level).bgColor = "<?php echo $color2;?>";
document.getElementById( "levelc" + level).bgColor = "<?php echo $color2;?>";
document.getElementById( "levela" + level).style.color = "<?php echo $colorback;?>";
document.getElementById( "levelb" + level).style.color = "<?php echo $colorback;?>";
document.getElementById( "levelc" + level).style.color = "<?php echo $colorback;?>";
}
function OnHelp5050( ans) {
if (flag5050) {
return;
} }
level = newlevel;
document.getElementById( "levela" + level).bgColor = "<?php echo $color2;?>";
document.getElementById( "levelb" + level).bgColor = "<?php echo $color2;?>";
document.getElementById( "levelc" + level).bgColor = "<?php echo $color2;?>";
document.getElementById( "levela" + level).style.color = "<?php echo $colorback;?>";
document.getElementById( "levelb" + level).style.color = "<?php echo $colorback;?>";
document.getElementById( "levelc" + level).style.color = "<?php echo $colorback;?>";
}
function OnHelp5050( ans) {
if (flag5050) {
return;
}
document.getElementById( "Help5050").src = "5050x.png"; document.getElementById( "Help5050").src = "5050x.png";
flag5050 = 1; flag5050 = 1;
@ -190,54 +190,54 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
for (i=1; i <= countQuestions; i++) { for (i=1; i <= countQuestions; i++) {
if( (i != pos) && (i != posCorrect)) { if( (i != pos) && (i != posCorrect)) {
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';
} }
} }
} }
function OnHelpTelephone( ans) { function OnHelpTelephone( ans) {
if( flagTelephone) { if( flagTelephone) {
return; return;
} }
flagTelephone = 1; flagTelephone = 1;
document.getElementById( "HelpTelephone").src = "telephonex.png"; document.getElementById( "HelpTelephone").src = "telephonex.png";
if (countQuestions < 2) { if (countQuestions < 2) {
wrong = posCorrect; wrong = posCorrect;
} else { } else {
for(;;) { for(;;) {
wrong = 1 + Math.floor(Math.random() * countQuestions); wrong = 1 + Math.floor(Math.random() * countQuestions);
if ( wrong != posCorrect) { if ( wrong != posCorrect) {
break; break;
} }
} }
} }
// With 80% gives the correct answer. // With 80% gives the correct answer.
if (Math.random() <= 0.8) { if (Math.random() <= 0.8) {
pos = posCorrect; pos = posCorrect;
} else { } else {
pos = wrong; pos = wrong;
} }
info = "<?php echo get_string( 'millionaire_info_telephone', 'game').'<br><b>';?> "; info = "<?php echo get_string( 'millionaire_info_telephone', 'game').'<br><b>';?> ";
info += document.getElementById( "lblAnswer" + pos).innerHTML; info += document.getElementById( "lblAnswer" + pos).innerHTML;
document.getElementById( "info").innerHTML = info; document.getElementById( "info").innerHTML = info;
} }
function OnHelpPeople( ans) { function OnHelpPeople( ans) {
if( flagPeople) { if( flagPeople) {
return; return;
} }
flagPeople = 1; flagPeople = 1;
document.getElementById( "HelpPeople").src = "peoplex.png"; document.getElementById( "HelpPeople").src = "peoplex.png";
sum = 0; sum = 0;
var aPercent = new Array(); var aPercent = new Array();
for( i = 0; i < countQuestions-1; i++) { for( i = 0; i < countQuestions-1; i++) {
percent = Math.floor(Math.random()*(100-sum)); percent = Math.floor(Math.random()*(100-sum));
aPercent[ i] = percent; aPercent[ i] = percent;
sum += percent; sum += percent;
} }
aPercent[ countQuestions - 1] = 100 - sum; aPercent[ countQuestions - 1] = 100 - sum;
if( Math.random() <= 0.8) { if( Math.random() <= 0.8) {
@ -256,24 +256,24 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
info = "<?php echo '<br>'.get_string( 'millionaire_info_people', 'game').':<br>';?>"; info = "<?php echo '<br>'.get_string( 'millionaire_info_people', 'game').':<br>';?>";
for( i=0; i < countQuestions; i++) { for( i=0; i < countQuestions; i++) {
info += "<br>" + letters.charAt( i) + " : " + aPercent[ i] + " %"; info += "<br>" + letters.charAt( i) + " : " + aPercent[ i] + " %";
} }
document.getElementById( "info").innerHTML = info; document.getElementById( "info").innerHTML = info;
} }
function OnQuit( ans) { function OnQuit( ans) {
Reset(); Reset();
} }
function Reset() { function Reset() {
for(i=1; i <= 15; i++) { for(i=1; i <= 15; i++) {
document.getElementById( "levela" + i).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levela" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelb" + i).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levelb" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelc" + i).bgColor = "<?php echo $colorback;?>"; document.getElementById( "levelc" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levela" + i).style.color = "<?php echo $color1;?>"; document.getElementById( "levela" + i).style.color = "<?php echo $color1;?>";
document.getElementById( "levelb" + i).style.color = "<?php echo $color1;?>"; document.getElementById( "levelb" + i).style.color = "<?php echo $color1;?>";
document.getElementById( "levelc" + i).style.color = "<?php echo $color1;?>"; document.getElementById( "levelc" + i).style.color = "<?php echo $color1;?>";
} }
flag5050 = 0; flag5050 = 0;
flagTelephone = 0; flagTelephone = 0;
@ -283,10 +283,10 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
document.getElementById( "HelpPeople").src = "people.png"; document.getElementById( "HelpPeople").src = "people.png";
document.getElementById( "HelpTelephone").src = "telephone.png"; document.getElementById( "HelpTelephone").src = "telephone.png";
document.getElementById( "info").innerHTML = ""; document.getElementById( "info").innerHTML = "";
UpdateLevel( 1); UpdateLevel( 1);
SelectNextQuestion(); SelectNextQuestion();
} }
function RandomizeAnswers( elements) { function RandomizeAnswers( elements) {
posCorrect = 1; posCorrect = 1;
@ -305,30 +305,27 @@ 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]);
var elements = new Array();
var elements = new Array();
elements = question.split('#'); elements = question.split('#');
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( "btAnswer" + i).style.visibility = 'hidden';
document.getElementById( "lblAnswer" + i).style.visibility = 'hidden'; }
document.getElementById( "btAnswer" + i).style.visibility = 'hidden';
} document.getElementById( "info").innerHTML = "";
document.getElementById( "info").innerHTML = "";
} }
/** /**
@ -340,79 +337,71 @@ 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;
var enc1, enc2, enc3, enc4; var enc1, enc2, enc3, enc4;
var i = 0; var i = 0;
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++));
enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++));
enc4 = this._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = Base64._utf8_decode(output);
return output;
},
// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
}
</script>
enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++));
enc4 = this._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = Base64._utf8_decode(output);
return output;
},
// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
} else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
}
</script>
<table cellpadding=0 cellspacing=0 border=0> <table cellpadding=0 cellspacing=0 border=0>
<tr style='background:#408080'> <tr style='background:#408080'>
@ -499,23 +488,23 @@ 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'>";
echo "<input style=\"background:$colorback;color:$color1;\" echo "<input style=\"background:$colorback;color:$color1;\"
type=\"submit\" name=\"btAnswer$i\" value=\"$s\" id=\"btAnswer$i\""; type=\"submit\" name=\"btAnswer$i\" value=\"$s\" id=\"btAnswer$i\"";
echo " onmouseover=\"Highlite( $i);\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\">"; echo " onmouseover=\"Highlite( $i);\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\">";
echo "</td>\n"; echo "</td>\n";
echo "<td style=\"background:$colorback;color:$color1;\" width=100%> &nbsp; <span id=lblAnswer$i echo "<td style=\"background:$colorback;color:$color1;\" width=100%> &nbsp; <span id=lblAnswer$i
style=\"background:$colorback;color:$color1\" style=\"background:$colorback;color:$color1\"
onmouseover=\"Highlite($i);\r \n\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\"></span></td>\n"; onmouseover=\"Highlite($i);\r \n\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\"></span></td>\n";
if ( $i == 1) { if ( $i == 1) {
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>

463
exporthtml_snakes.php

@ -14,9 +14,9 @@
// 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
* @package game * @package game
**/ **/
@ -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;
font-size: 40px;
} }
.score
{color: #FC3;
font-size: 40px;
}
</style> </style>
</head> </head>
<body> <body>
<script language="JavaScript"> <script language="JavaScript">
@ -152,55 +153,52 @@ display_quest();
function ShowMainForm() function ShowMainForm()
{ {
var pawn_x =0; var pawn_x =0;
var pawn_y=0; var pawn_y=0;
var direction=0; var direction=0;
var cols = board_cols[current_board]; var cols = board_cols[current_board];
var rows = board_rows[current_board]; var rows = board_rows[current_board];
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;
document.write('<img id="boardimage" src="images/meter.png">'); document.write('<img id="boardimage" src="images/meter.png">');
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));
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;
axis_y=Math.floor((current_position /rows)); document.write('<div id="pawn1"><img id="pawn" alt="" src="images/player1.png"></div>');
pawn_x=board_headerx[current_board]+(axis_x*col_width)+(col_width-pawn_width[current_board])/2; move_pawn();
pawn_y=board_footery[current_board]+pawn_height[current_board]+(axis_y*col_height)+(col_height-pawn_height[current_board])/2; }
document.write('<div id="pawn1"><img id="pawn" alt="" src="images/player1.png"></div>');
move_pawn();
}
} }
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;
for (i=0;i<3;i++) { for (i=0;i<3;i++) {
quest_candidates[i]=Math.floor((Math.random() * quest_total)); quest_candidates[i]=Math.floor((Math.random() * quest_total));
} }
current_quest = quest_candidates[0]; current_quest = quest_candidates[0];
for (i=1;i<3;i++) { for (i=1;i<3;i++) {
if (quest_times_asked[quest_candidates[i]]>quest_times_asked[current_quest]) if (quest_times_asked[quest_candidates[i]]>quest_times_asked[current_quest])
current_quest=quest_candidates[i]; current_quest=quest_candidates[i];
} }
q=Base64decode( questions[ current_quest]); q=Base64decode( questions[ current_quest]);
quest_resp = decode_multiple_choice( q); quest_resp = decode_multiple_choice( q);
@ -208,206 +206,188 @@ 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)
{
alert( str_no_selection);
document.getElementById("feedb").innerHTML= "";
document.getElementById("check_btn").style.display = "block";
return;
}
var feedbacks = decode_multiple_choice(quest_feedb);
var j;
for (j=0;j<n;j++) {
document.snakesform.radio_answer[ j].disabled = "true";
}
document.getElementById("feedb").innerHTML= feedbacks[ mchoice_positions[useranswer]]; if( useranswer >= n) {
document.getElementById("feedb").style.display = "block"; alert( str_no_selection);
document.getElementById("feedb").innerHTML= "";
if ( mchoice_positions[ useranswer] == 1) document.getElementById("check_btn").style.display = "block";
{ return;
current_position += current_dice; }
correct_ans =correct_ans+1; //calculate new score----
score = Math.round((correct_ans/all_ans)*100); var feedbacks = decode_multiple_choice(quest_feedb);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
check_game_over(); var j;
check_exists_ladder(); for (j=0;j<n;j++) {
} document.snakesform.radio_answer[ j].disabled = "true";
else }
{
score = Math.round((correct_ans/all_ans)*100); document.getElementById("feedb").innerHTML= feedbacks[ mchoice_positions[useranswer]];
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>'; document.getElementById("feedb").style.display = "block";
check_exists_snake();
} if ( mchoice_positions[ useranswer] == 1) {
current_position += current_dice;
document.getElementById("OK_btn").style.display = "block"; correct_ans =correct_ans+1; //calculate new score----
score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
check_game_over();
check_exists_ladder();
} else {
score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
check_exists_snake();
}
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())
{
document.getElementById("feedb").style.display = "block";
current_position += current_dice;
correct_ans =correct_ans+1; //calculate new score
score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
check_game_over();
check_exists_ladder();
}
else
{
document.getElementById("feedb_wrong").style.display = "block";
score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
check_exists_snake();
}
document.getElementById("OK_btn").style.display = "block"; if (document.getElementById("answer").value.toUpperCase() == quest_resp[ 1].toUpperCase()) {
document.getElementById("feedb").style.display = "block";
current_position += current_dice;
correct_ans =correct_ans+1; //calculate new score
score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
check_game_over();
check_exists_ladder();
} else {
document.getElementById("feedb_wrong").style.display = "block";
score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
check_exists_snake();
}
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;
{ showPopWin('modalContent.html', 350, 220, returnRefresh); // modal
current_position=out-1; }
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) {
return;
}
if( pos < 0) var s = board_contents[ current_board].substr( pos+find.length)
return; pos = s.indexOf( ',');
if (pos >= 0) {
var s = board_contents[ current_board].substr( pos+find.length) s = s.substr( 0, pos);
pos = s.indexOf( ','); }
if( pos >= 0)
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) {
return;
if( pos < 0) }
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);
{ continue;
s = s.substr( pos+1); }
continue; s = s.substr( pos_start+2);
} pos = s.indexOf( '-');
s = s.substr( pos_start+2); current_position = s.substr( 0, pos)-1;
pos = s.indexOf( '-'); break;
current_position = s.substr( 0, pos)-1; }
break;
}
} }
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( '#');
{ if( pos < 0) {
var pos=s.indexOf( '#'); ret[ i++] = s;
if( pos < 0) return ret;
{ }
ret[ i++] = s; ret[ i++] = s.substr( 0, pos);
return ret; s = s.substr( pos+1);
} }
ret[ i++] = s.substr( 0, pos);
s = s.substr( pos+1);
}
} }
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;">';
s = s + '<strong>'+str_score+': </strong>'; s = s + '<strong>'+str_score+': </strong>';
s = s + '<strong class="score">' +score+ '</strong></div></td></tr></table>'; s = s + '<strong class="score">' +score+ '</strong></div></td></tr></table>';
s = s + '<div id="question_area">' + quest_text+'</div>'; s = s + '<div id="question_area">' + quest_text+'</div>';
s = s + '<form name="snakesform">'; s = s + '<form name="snakesform">';
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];
mchoice_positions[ j] = temp; mchoice_positions[ j] = temp;
} }
for(i=0; i < mchoice_count;i++) { for(i=0; i < mchoice_count;i++) {
s = s + '<input type="radio" name="radio_answer" id="radio_answer" value="'; s = s + '<input type="radio" name="radio_answer" id="radio_answer" value="';
s = s + i+'" />'+quest_resp[ mchoice_positions[ i]] + '<br />'; s = s + i+'" />'+quest_resp[ mchoice_positions[ i]] + '<br />';
} }
s = s + '<br /><input type="button" id="check_btn" value="'+str_check; s = s + '<br /><input type="button" id="check_btn" value="'+str_check;
s = s + '" onclick="check_answer();"> <br/><div id="feedb_area"> <div id="feedb_wrong" style="display:none; color:yellow;"> '; s = s + '" onclick="check_answer();"> <br/><div id="feedb_area"> <div id="feedb_wrong" style="display:none; color:yellow;"> ';
s = s + quest_feedb+' </div> <br /><div id="feedb" style="display:none; color:yellow;"> '; s = s + quest_feedb+' </div> <br /><div id="feedb" style="display:none; color:yellow;"> ';
@ -415,17 +395,16 @@ function display_quest_M()
s = s + current_dice+' τετράγωνα μπροστά!</div><br /> <div id="OK_btn"'; s = s + current_dice+' τετράγωνα μπροστά!</div><br /> <div id="OK_btn"';
s = s + 'style="display:none;"><input type="button" onclick="display_quest();" value="OK"/></div> </div></form>'; s = s + 'style="display:none;"><input type="button" onclick="display_quest();" value="OK"/></div> </div></form>';
document.getElementById("dicecont").innerHTML = s; document.getElementById("dicecont").innerHTML = s;
document.getElementById("question_area").style.display = "block"; document.getElementById("question_area").style.display = "block";
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';
s = s + current_dice + '.png"> </div> </td><td align=right>'; s = s + current_dice + '.png"> </div> </td><td align=right>';
s = s + '<div id="show_score" style="color: #FFFFFF; font-weight:bold; font-size: 20px;"><strong>'; s = s + '<div id="show_score" style="color: #FFFFFF; font-weight:bold; font-size: 20px;"><strong>';
s = s + str_score+': </strong><strong class="score">' +score+ '</strong></div></td></tr></table><div id="question_area">'; s = s + str_score+': </strong><strong class="score">' +score+ '</strong></div></td></tr></table><div id="question_area">';
@ -440,24 +419,22 @@ 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_y=0;
var pawn_x =0; var direction=0;
var pawn_y=0; var cols = board_cols[current_board];
var direction=0; var rows = board_rows[current_board];
var cols = board_cols[current_board]; var col_width = (board_width[current_board]-board_headerx[current_board]-board_footerx[current_board])/cols;
var rows = board_rows[current_board]; var col_height = (board_height[current_board]-board_headery[current_board]-board_footery[current_board])/rows;
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;
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