Browse Source

Fix: PHP coding style problems

MOODLE_20_STABLE
bdaloukas 8 years ago
parent
commit
b0ffb2d355
  1. 2
      cross/crossdb_class.php
  2. 862
      cross/play.php
  3. 128
      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. 40
      export/html/snakes/css/game.css
  10. 54
      export/html/snakes/css/modal.css
  11. 142
      export/html/snakes/css/snakes.css
  12. 14
      export/html/snakes/css/style.css
  13. 101
      export/html/snakes/css/subModal.css
  14. 230
      export/html/snakes/js/snakes-mod.js
  15. 4
      exporthtml.php
  16. 166
      exporthtml_hangman.php
  17. 381
      exporthtml_millionaire.php
  18. 435
      exporthtml_snakes.php

2
cross/crossdb_class.php

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

862
cross/play.php

File diff suppressed because it is too large

128
cryptex/play.php

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

2
db/access.php

@ -16,7 +16,7 @@
defined('MOODLE_INTERNAL') || die();
/**
/*
* Capability definitions for the game module.
*
* 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
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die();
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
// 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, ".
"'A73IEDB8642I16875CF85237A94539712D6HBGFC849158415FI3G28913BE64GFDB89753175C41692H')");
$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.
*/
defined('MOODLE_INTERNAL') || die();
function xmldb_game_upgrade($oldversion) {
global $CFG, $DB;
@ -1549,10 +1551,9 @@ function xmldb_game_upgrade($oldversion) {
$table = new xmldb_table('game_cross');
$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);
}
return true;
}

2
export.php

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

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

@ -1,37 +1,33 @@
.nodis
{
list-style-type:none;
list-style-type:none;
}
#cont
{
position:relative;
display:none;
position:relative;
display:none;
}
.img1
{
position:absolute;
display:none;
position:absolute;
display:none;
}
#dicecont
{
float:right;
width:250px;
background-image: url(../images/meter.png);
background-repeat: repeat;
font-family: Arial, Helvetica, sans-serif;
font-weight: normal;
/*font-variant: small-caps;*/
color: #FFFFFF;
border: 0.5em solid #333333;
top: 30px;
position: absolute;
left: 500px;
font-size: 14px;
padding: 10px;
float:right;
width:250px;
background-image: url(../images/meter.png);
background-repeat: repeat;
font-family: Arial, Helvetica, sans-serif;
font-weight: normal;
color: #FFFFFF;
border: 0.5em solid #333333;
top: 30px;
position: absolute;
left: 500px;
font-size: 14px;
padding: 10px;
}

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

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

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

@ -2,130 +2,126 @@
Husain Limdiyawala(MSc IT DA-IICT)
Any Duplication of this code should be avoided*/
.blocks
{
font-family: Arial, Helvetica, sans-serif;
/*color: #FFFFFF;*/
margin-left: 5px;
margin-top:2px;
margin-bottom:2px;
padding: 0px;
float:left;
height: 52px;
width: 52px;
display:block;
position:relative;
background-image: url(../square52.png);
font-family: Arial, Helvetica, sans-serif;
margin-left: 5px;
margin-top:2px;
margin-bottom:2px;
padding: 0px;
float:left;
height: 52px;
width: 52px;
display:block;
position:relative;
background-image: url(../square52.png);
}
.nodis
{
list-style-type:none;
list-style-type:none;
}
#cont
{
position:relative;
display:none;
position:relative;
display:none;
}
#diceimg
{
display:none;
width:45px;
display:none;
width:45px;
height:44px;
}
.img1
{
position:absolute;
display:none;
position:absolute;
display:none;
}
body
{
background:#CCCCCC;
background:#CCCCCC;
}
#player
{
display:none;
z-index:5;
position:absolute;
display:none;
z-index:5;
position:absolute;
}
#players
{
margin-top: 0.3em;
margin-bottom: 1em;
margin-top: 0.3em;
margin-bottom: 1em;
}
#dicecont
{
float:right;
width:170px;
background-image: url(../images/meter.png);
background-repeat: repeat;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
/*font-variant: small-caps;*/
color: #FFFFFF;
border: 0.5em solid #333333;
top: 30px;
position: absolute;
right: 880px;
float:right;
width:170px;
background-image: url(../images/meter.png);
background-repeat: repeat;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FFFFFF;
border: 0.5em solid #333333;
top: 30px;
position: absolute;
right: 880px;
}
#playbtn
{
margin-left:0.5em;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
/*font-variant: small-caps;*/
color: #000000;
background-color: #FC0;
padding: 1em;
margin-left:0.5em;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #000000;
background-color: #FC0;
padding: 1em;
}
/*-- from modal window coding --*/
#fade { /*--Transparent background layer--*/
display: none; /*--hidden by default--*/
background: #000;
position: fixed; left: 0; top: 0;
width: 100%; height: 100%;
opacity: .80;
z-index: 9999;
display: none; /*--hidden by default--*/
background: #000;
position: fixed; left: 0; top: 0;
width: 100%; height: 100%;
opacity: .80;
z-index: 9999;
}
.popup_block{
display: none; /*--hidden by default--*/
background: #fff;
padding: 20px;
border: 20px solid #ddd;
float: left;
font-size: 1.2em;
position: fixed;
top: 50%; left: 50%;
z-index: 99999;
/*--CSS3 Box Shadows--*/
-webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000;
/*--CSS3 Rounded Corners--*/
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
display: none; /*--hidden by default--*/
background: #fff;
padding: 20px;
border: 20px solid #ddd;
float: left;
font-size: 1.2em;
position: fixed;
top: 50%; left: 50%;
z-index: 99999;
/*--CSS3 Box Shadows--*/
-webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000;
/*--CSS3 Rounded Corners--*/
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
img.btn_close {
float: right;
margin: -55px -55px 0 0;
border: 0;
float: right;
margin: -55px -55px 0 0;
border: 0;
}
/*--Making IE6 Understand Fixed Positioning--*/
*html #fade {
position: absolute;
position: absolute;
}
*html .popup_block {
position: absolute;
position: absolute;
}

14
export/html/snakes/css/style.css

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

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

@ -2,68 +2,69 @@
* POPUP CONTAINER STYLES
*/
#popupMask {
position: absolute;
z-index: 200;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
opacity: .4;
filter: alpha(opacity=50);
/* this hack is so it works in IE
position: absolute;
z-index: 200;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
opacity: .4;
filter: alpha(opacity=50);
/* this hack is so it works in IE
* I find setting the color in the css gives me more flexibility
* than the PNG solution.
*/
background-color:transparent !important;
background-color: #333333;
/* this hack is for opera support
* 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
*/
background-image/**/: url("../images/maskBG.png") !important; // For browsers Moz, Opera, etc.
background-image:none;
background-repeat: repeat;
display:none;
* than the PNG solution.
*/
background-color:transparent !important;
background-color: #333333;
/* this hack is for opera support
* 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
*/
background-image/**/: url("../images/maskBG.png") !important; // For browsers Moz, Opera, etc.
background-image:none;
background-repeat: repeat;
display:none;
}
#popupContainer {
position: absolute;
z-index: 201;
top: 0px;
left: 0px;
display:none;
padding: 0px;
position: absolute;
z-index: 201;
top: 0px;
left: 0px;
display:none;
padding: 0px;
}
#popupInner {
border: 2px solid #000000;
background-color: #ffffff;
border: 2px solid #000000;
background-color: #ffffff;
}
#popupFrame {
margin: 0px;
width: 100%;
height: 100%;
position: relative;
z-index: 202;
margin: 0px;
width: 100%;
height: 100%;
position: relative;
z-index: 202;
}
#popupTitleBar {
background-color: #090;
color: # 000;
font-weight: bold;
height: 1.3em;
padding: 5px;
border-bottom: 2px solid #000000;
border-top: 1px solid #78A3F2;
border-left: 1px solid #78A3F2;
border-right: 1px solid #204095;
position: relative;
z-index: 203;
background-color: #090;
color: # 000;
font-weight: bold;
height: 1.3em;
padding: 5px;
border-bottom: 2px solid #000000;
border-top: 1px solid #78A3F2;
border-left: 1px solid #78A3F2;
border-right: 1px solid #204095;
position: relative;
z-index: 203;
}
#popupTitle {
float:left;
font-size: 1.1em;
float:left;
font-size: 1.1em;
}
#popupControls {
float: right;
cursor: pointer;
cursor: hand;
float: right;
cursor: pointer;
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 data = "";
var currentblock = 0;
@ -20,12 +20,12 @@ var destsnake = new Array(4);
var ladsrc = new Array(3);
var laddest = new Array(3);
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 WRO_answered = new Array(); //record all questions (along with answers) the user responded WRONGLY
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 WRO_answered = new Array(); // Record all questions (along with answers) the user responded WRONGLY.
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[1] = "one";
@ -45,30 +45,29 @@ quest[14] = "three";
quest[15] = "one";
z = 0;
for (z = 0; quest[z] != null; z++) {
// Do nothing
// Do nothing.
}
allQuest = z / 4;
function selectQuest(all)
{
function selectQuest(all) {
pickOne = Math.floor((Math.random() * all));
return pickOne;
}
//The Below Function will hide all the snakes
// The Below Function will hide all the snakes.
function hideAll() {
document.getElementById("img1").style.display = "none";
document.getElementById("img2").style.display = "none";
document.getElementById("img3").style.display = "none";
document.getElementById("img4").style.display = "none";
document.getElementById("img1").style.display = "none";
document.getElementById("img2").style.display = "none";
document.getElementById("img3").style.display = "none";
document.getElementById("img4").style.display = "none";
document.getElementById("lad1").style.display = "none";
document.getElementById("lad2").style.display = "none";
document.getElementById("lad1").style.display = "none";
document.getElementById("lad2").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) {
totblocks = (a * a);
@ -88,42 +87,42 @@ function paintBoard(a) {
currentblock -= (a - 1);
}
} else {
currentblock = (a * a);
for (j = 0; j < (a / 2); j++) {
for (i = 0; i < a; i++) {
data += "<div class='blocks' id='" + currentblock + "'>" + currentblock + "</div>";
currentblock--;
}
currentblock -= (a - 1);
if (currentblock < 2) {
break;
}
for (i = 0; i < a; i++) {
data += "<div id='" + currentblock + "' class ='blocks'>" + currentblock + "</div>";
currentblock++;
}
currentblock -= (a + 1);
}
}
currentblock = (a * a);
for (j = 0; j < (a / 2); j++) {
for (i = 0; i < a; i++) {
data += "<div class='blocks' id='" + currentblock + "'>" + currentblock + "</div>";
currentblock--;
}
currentblock -= (a - 1);
if (currentblock < 2) {
break;
}
for (i = 0; i < a; i++) {
data += "<div id='" + currentblock + "' class ='blocks'>" + currentblock + "</div>";
currentblock++;
}
currentblock -= (a + 1);
}
}
document.getElementById("cont").style.width = (a * 52 + 52) + "px"
document.getElementById("cont").innerHTML = data;
$("#cont").slideDown("slow");
$("#cont").effect("shake",3000);
$("img:hidden").fadeIn(5000);
document.getElementById("cont").innerHTML = data;
$("#cont").slideDown("slow");
$("#cont").effect("shake",3000);
$("img:hidden").fadeIn(5000);
if (a == 6) {
registerSnake(158, 196, "img1", 14, 3, 0);
registerSnake(62, 183, "img2", 27, 24, 1);
registerSnake(175, 18, "img3", 18, 4, 2);
registerSnake(10, 45, "img4", 32, 23, 3);
if (a == 6) {
registerSnake(158, 196, "img1", 14, 3, 0);
registerSnake(62, 183, "img2", 27, 24, 1);
registerSnake(175, 18, "img3", 18, 4, 2);
registerSnake(10, 45, "img4", 32, 23, 3);
registerLadder(27, 132, "lad1", 28, 34, 0);
registerLadder(90, 22, "lad2", 19, 30, 1);
registerLadder(179, 137, "lad3", 2, 16, 2);
registerLadder(27, 132, "lad1", 28, 34, 0);
registerLadder(90, 22, "lad2", 19, 30, 1);
registerLadder(179, 137, "lad3", 2, 16, 2);
} else if (a == 8) {
registerSnake(300, 380, "img1", 44, 29, 0);
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) {
randomno = Math.floor((Math.random() * 6)) + 1;
document.getElementById("diceimg").src = "images/dice_" + randomno + ".PNG";
randomno = Math.floor((Math.random() * 6)) + 1;
document.getElementById("diceimg").src = "images/dice_" + randomno + ".PNG";
document.getElementById("diceimg").style.display = "block";
if (lastposition[i] > 0) {
if (lastposition[i] > 0) {
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];
document.getElementById(tots[i]).style.background = "url(images/pawn1.png)";
} else {
} else {
tots[i] -= randomno;
document.getElementById(tots[i]).style.background = "url(images/pawn1.png)";
}
}
}
// The below Function Checks The Snake Biting for a user.
function snakescheck(k) {
i = 0;
for(i = 0; i <= srcsnake.length; i++) {
if (srcsnake[i] == tots[k]) {
alert("Ωχ! Σε τσίμπησε φίδι στο τετράγωνο " + srcsnake[i] + " και θα πρέπει να γυρίσεις στο τετράγωνο " + destsnake[i] + ", εκτός κι αν απαντήσεις σωστά στην ερώτηση που ακολουθεί.");
document.getElementById(destsnake[i]).style.background = "url(images/pawn1.png)";
document.getElementById(tots[k]).style.background = "url(images/square52.png)";
lastposition[k] = destsnake[i];
tots[k] = destsnake[i];
break;
}
}
i = 0;
for(i = 0; i <= srcsnake.length; i++) {
if (srcsnake[i] == tots[k]) {
alert("Ωχ! Σε τσίμπησε φίδι στο τετράγωνο " + srcsnake[i] + " και θα πρέπει να γυρίσεις στο τετράγωνο " + destsnake[i] + ", εκτός κι αν απαντήσεις σωστά στην ερώτηση που ακολουθεί.");
document.getElementById(destsnake[i]).style.background = "url(images/pawn1.png)";
document.getElementById(tots[k]).style.background = "url(images/square52.png)";
lastposition[k] = destsnake[i];
tots[k] = destsnake[i];
break;
}
}
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) {
i = 0;
i = 0;
for(i = 0; i <= ladsrc.length; i++) {
if (ladsrc[i] == tots[k]) {
for(i = 0; i <= ladsrc.length; i++) {
if (ladsrc[i] == tots[k]) {
alert("Υπάρχει μια σκάλα στο τετράγωνο " + ladsrc[i] + " και θα σας οδηγήσει κατευθείαν στο τετράγωνο " + laddest[i] + "αν απαντήσεις σωστά στην ερώτηση που ακολουθεί.");
document.getElementById(laddest[i]).style.background = "url(images/pawn1.png)";
document.getElementById(tots[k]).style.background = "url(images/square52.png)";
lastposition[k] = laddest[i];
tots[k] = laddest[i];
break;
}
}
if(!checkWin(k)) {
alert("You have won!");
document.getElementById(laddest[i]).style.background = "url(images/pawn1.png)";
document.getElementById(tots[k]).style.background = "url(images/square52.png)";
lastposition[k] = laddest[i];
tots[k] = laddest[i];
break;
}
}
if(!checkWin(k)) {
alert("You have won!");
}
}
//The below Function checks for pythons
// The below Function checks for pythons.
function pythoncheck(k) {
i = 0;
for (i = 0; i < pythons.length; i++) {
if (pythons[i] == tots[k]) {
alert("You have been eaten up by a python.Your game is over");
document.getElementById(tots[k]).style.background = "url(images/csnake.gif) #000000";
lastposition[k] = null;
tots[k] = null;
break;
}
}
for (i = 0; i < pythons.length; i++) {
if (pythons[i] == tots[k]) {
alert("You have been eaten up by a python.Your game is over");
document.getElementById(tots[k]).style.background = "url(images/csnake.gif) #000000";
lastposition[k] = null;
tots[k] = null;
break;
}
}
}
// The below function will register a snake.
function registerSnake(tp, lft, dv, src, dest, i) {
document.getElementById(dv).style.top = tp + "px";
document.getElementById(dv).style.left = lft + "px";
srcsnake[i] = src;
destsnake[i] = dest;
document.getElementById(dv).style.top = tp + "px";
document.getElementById(dv).style.left = lft + "px";
srcsnake[i] = src;
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) {
document.getElementById(dv).style.top = tp + "px";
document.getElementById(dv).style.left = lft + "px";
ladsrc[i] = src;
laddest[i] = dest;
document.getElementById(dv).style.top = tp + "px";
document.getElementById(dv).style.left = lft + "px";
ladsrc[i] = src;
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() {
totblocks = 0;
data = "";
@ -244,24 +242,24 @@ function selectBoard() {
function selectPlayer() {
if (document.getElementById("players").value != null) {
user[document.getElementById("players").value - 1] = 0;
tots[document.getElementById("players").value - 1] = 0;
lastposition[document.getElementById("players").value - 1] = 0;
for(var j = 0; j < lastposition.length; j++) {
tots[document.getElementById("players").value - 1] = 0;
lastposition[document.getElementById("players").value - 1] = 0;
for(var j = 0; j < lastposition.length; j++) {
lastposition[j] = 0;
tots[j] = 0;
}
}
}
}
}
// The below function starts the play.
function play() {
if (tots[l] != null) {
if (tots[l] != null) {
disableField();
document.getElementById("status").innerHTML = "<ul class='nodis'><li>O Paiktis " + (l + 1) + " </li><li>brisketai sto tetragwno " + tots[l] + "</li><li></li></ul>";
Question();
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>";
}
@ -277,7 +275,7 @@ function doit(i) {
throwDice(i);
if (checkWin(i)) {
snakescheck(i);
laddercheck(i);
laddercheck(i);
} else {
alert("ÏëïêëÞñùóåò ôçí ðßóôá, óõã÷áñçôÞñéá!!!");
}
@ -285,7 +283,7 @@ function doit(i) {
// The below function checks whether the player has won or not.
function checkWin(i) {
if( tots[i] == totblocks) {
if( tots[i] == totblocks) {
return false;
} else {
return true;
@ -294,8 +292,8 @@ function checkWin(i) {
// The below function will disable both the combobox .
function disableField() {
document.getElementById("players").disabled = "disabled";
document.getElementById("boardtype").disabled = "disabled";
document.getElementById("players").disabled = "disabled";
document.getElementById("boardtype").disabled = "disabled";
}
function Question() {
@ -312,6 +310,6 @@ function Question() {
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--;
}

4
exporthtml.php

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

166
exporthtml_hangman.php

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

381
exporthtml_millionaire.php

@ -120,27 +120,27 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
var countQuestions = 0;
var maxQuestions = <?php echo $maxquestions;?>;
function Highlite( ans) {
document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $color2;?>';
}
function Restore( ans) {
document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $colorback;?>';
}
function OnSelectAnswer( ans) {
if ( posCorrect == ans) {
if( level+1 > 15) {
alert( "<?php echo get_string( 'win', 'game');?>");
Reset();
} else {
UpdateLevel( level+1);
SelectNextQuestion();
}
} else {
OnGameOver( ans);
}
}
function Highlite( ans) {
document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $color2;?>';
}
function Restore( ans) {
document.getElementById( "btAnswer" + ans).style.backgroundColor = '<?php echo $colorback;?>';
}
function OnSelectAnswer( ans) {
if ( posCorrect == ans) {
if( level+1 > 15) {
alert( "<?php echo get_string( 'win', 'game');?>");
Reset();
} else {
UpdateLevel( level+1);
SelectNextQuestion();
}
} else {
OnGameOver( ans);
}
}
function OnGameOver( ans) {
document.getElementById( "info").innerHTML = "<?php echo get_string( 'millionaire_info_wrong_answer', 'game');?> " +
@ -157,29 +157,29 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
Reset();
}
function UpdateLevel( newlevel) {
if ( level > 0) {
document.getElementById( "levela" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelb" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelc" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levela" + level).style.color = "<?php echo $color1;?>";
document.getElementById( "levelb" + 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 UpdateLevel( newlevel) {
if ( level > 0) {
document.getElementById( "levela" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelb" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelc" + level).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levela" + level).style.color = "<?php echo $color1;?>";
document.getElementById( "levelb" + 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;
function OnHelp5050( ans) {
if (flag5050) {
return;
}
document.getElementById( "Help5050").src = "5050x.png";
@ -190,54 +190,54 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
for (i=1; i <= countQuestions; i++) {
if( (i != pos) && (i != posCorrect)) {
document.getElementById( "lblAnswer" + i).style.visibility = 'hidden';
document.getElementById( "btAnswer" + i).style.visibility = 'hidden';
}
document.getElementById( "btAnswer" + i).style.visibility = 'hidden';
}
}
}
}
function OnHelpTelephone( ans) {
if( flagTelephone) {
return;
function OnHelpTelephone( ans) {
if( flagTelephone) {
return;
}
flagTelephone = 1;
flagTelephone = 1;
document.getElementById( "HelpTelephone").src = "telephonex.png";
if (countQuestions < 2) {
wrong = posCorrect;
} else {
for(;;) {
wrong = 1 + Math.floor(Math.random() * countQuestions);
if ( wrong != posCorrect) {
break;
}
}
}
// With 80% gives the correct answer.
if (Math.random() <= 0.8) {
pos = posCorrect;
} else {
pos = wrong;
if (countQuestions < 2) {
wrong = posCorrect;
} else {
for(;;) {
wrong = 1 + Math.floor(Math.random() * countQuestions);
if ( wrong != posCorrect) {
break;
}
}
}
// With 80% gives the correct answer.
if (Math.random() <= 0.8) {
pos = posCorrect;
} else {
pos = wrong;
}
info = "<?php echo get_string( 'millionaire_info_telephone', 'game').'<br><b>';?> ";
info += document.getElementById( "lblAnswer" + pos).innerHTML;
document.getElementById( "info").innerHTML = info;
}
}
function OnHelpPeople( ans) {
function OnHelpPeople( ans) {
if( flagPeople) {
return;
return;
}
flagPeople = 1;
flagPeople = 1;
document.getElementById( "HelpPeople").src = "peoplex.png";
sum = 0;
var aPercent = new Array();
for( i = 0; i < countQuestions-1; i++) {
percent = Math.floor(Math.random()*(100-sum));
aPercent[ i] = percent;
sum += percent;
percent = Math.floor(Math.random()*(100-sum));
aPercent[ i] = percent;
sum += percent;
}
aPercent[ countQuestions - 1] = 100 - sum;
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>';?>";
for( i=0; i < countQuestions; i++) {
info += "<br>" + letters.charAt( i) + " : " + aPercent[ i] + " %";
}
}
document.getElementById( "info").innerHTML = info;
}
document.getElementById( "info").innerHTML = info;
}
function OnQuit( ans) {
Reset();
}
function OnQuit( ans) {
Reset();
}
function Reset() {
for(i=1; i <= 15; i++) {
document.getElementById( "levela" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelb" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelc" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levela" + i).style.color = "<?php echo $color1;?>";
document.getElementById( "levelb" + i).style.color = "<?php echo $color1;?>";
document.getElementById( "levelc" + i).style.color = "<?php echo $color1;?>";
}
function Reset() {
for(i=1; i <= 15; i++) {
document.getElementById( "levela" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelb" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levelc" + i).bgColor = "<?php echo $colorback;?>";
document.getElementById( "levela" + i).style.color = "<?php echo $color1;?>";
document.getElementById( "levelb" + i).style.color = "<?php echo $color1;?>";
document.getElementById( "levelc" + i).style.color = "<?php echo $color1;?>";
}
flag5050 = 0;
flagTelephone = 0;
@ -283,10 +283,10 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
document.getElementById( "HelpPeople").src = "people.png";
document.getElementById( "HelpTelephone").src = "telephone.png";
document.getElementById( "info").innerHTML = "";
UpdateLevel( 1);
SelectNextQuestion();
}
document.getElementById( "info").innerHTML = "";
UpdateLevel( 1);
SelectNextQuestion();
}
function RandomizeAnswers( elements) {
posCorrect = 1;
@ -305,30 +305,27 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
}
}
function SelectNextQuestion()
{
current_question = Math.floor(Math.random()*questions.length);
question = Base64.decode( questions[ current_question]);
function SelectNextQuestion() {
current_question = Math.floor(Math.random()*questions.length);
question = Base64.decode( questions[ current_question]);
var elements = new Array();
var elements = new Array();
elements = question.split('#');
RandomizeAnswers( elements);
document.getElementById( "question").innerHTML = elements[ 0];
for( i=1; i < elements.length; i++)
{
document.getElementById( "lblAnswer" + i).innerHTML = elements[ i];
document.getElementById( "lblAnswer" + i).style.visibility = 'visible';
document.getElementById( "btAnswer" + i).style.visibility = 'visible';
}
for( i=elements.length; i<= maxQuestions; i++)
{
document.getElementById( "lblAnswer" + i).style.visibility = 'hidden';
document.getElementById( "btAnswer" + i).style.visibility = 'hidden';
}
document.getElementById( "info").innerHTML = "";
document.getElementById( "question").innerHTML = elements[ 0];
for( i=1; i < elements.length; i++) {
document.getElementById( "lblAnswer" + i).innerHTML = elements[ i];
document.getElementById( "lblAnswer" + i).style.visibility = 'visible';
document.getElementById( "btAnswer" + i).style.visibility = 'visible';
}
for( i=elements.length; i<= maxQuestions; i++) {
document.getElementById( "lblAnswer" + i).style.visibility = 'hidden';
document.getElementById( "btAnswer" + i).style.visibility = 'hidden';
}
document.getElementById( "info").innerHTML = "";
}
/**
@ -340,79 +337,71 @@ function game_millionaire_html_print( $game, $questions, $maxquestions) {
var Base64 = {
// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for decoding
decode : function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
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;
}
// Private property.
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
}
// Public method for decoding.
decode : function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
</script>
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
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>
<table cellpadding=0 cellspacing=0 border=0>
<tr style='background:#408080'>
@ -499,23 +488,23 @@ var Base64 = {
</tr>
<?php
$letters = get_string( 'lettersall', 'game');
for ($i = 1; $i <= $maxquestions; $i++) {
$s = game_substr( $letters, $i - 1, 1);
echo "<tr>\n";
echo "<td style='background:$colorback;color:$color1'>";
echo "<input style=\"background:$colorback;color:$color1;\"
type=\"submit\" name=\"btAnswer$i\" value=\"$s\" id=\"btAnswer$i\"";
echo " onmouseover=\"Highlite( $i);\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\">";
echo "</td>\n";
echo "<td style=\"background:$colorback;color:$color1;\" width=100%> &nbsp; <span id=lblAnswer$i
style=\"background:$colorback;color:$color1\"
onmouseover=\"Highlite($i);\r \n\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\"></span></td>\n";
if ( $i == 1) {
echo "<td style='background:#408080' rowspan=".$maxquestions." colspan=3><div id=\"info\"></div></td>\n";
}
echo "</tr>\n";
$letters = get_string( 'lettersall', 'game');
for ($i = 1; $i <= $maxquestions; $i++) {
$s = game_substr( $letters, $i - 1, 1);
echo "<tr>\n";
echo "<td style='background:$colorback;color:$color1'>";
echo "<input style=\"background:$colorback;color:$color1;\"
type=\"submit\" name=\"btAnswer$i\" value=\"$s\" id=\"btAnswer$i\"";
echo " onmouseover=\"Highlite( $i);\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\">";
echo "</td>\n";
echo "<td style=\"background:$colorback;color:$color1;\" width=100%> &nbsp; <span id=lblAnswer$i
style=\"background:$colorback;color:$color1\"
onmouseover=\"Highlite($i);\r \n\" onmouseout=\"Restore( $i);\" onmousedown=\"OnSelectAnswer( $i);\"></span></td>\n";
if ( $i == 1) {
echo "<td style='background:#408080' rowspan=".$maxquestions." colspan=3><div id=\"info\"></div></td>\n";
}
echo "</tr>\n";
}
?>
<tr><td colspan=10 style='background:#408080'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>

435
exporthtml_snakes.php

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
/*
* This page export the game snakes to html
*
* @author bdaloukas
@ -39,26 +39,27 @@ defined('MOODLE_INTERNAL') || die();
<style type="text/css">
#pawn
{
position:absolute;
position:absolute;
}
img
{
border:hidden
border:hidden
}
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>
</head>
<body>
<script language="JavaScript">
@ -152,55 +153,52 @@ display_quest();
function ShowMainForm()
{
var pawn_x =0;
var pawn_y=0;
var direction=0;
var cols = board_cols[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_height = (board_height[current_board]-board_headery[current_board]-board_footery[current_board])/rows;
document.write('<img id="boardimage" src="images/meter.png">');
document.getElementById("boardimage").src = "images/" + board_images[ current_board];
document.write('<div id="dicecont">&nbsp;</div>');
if( current_position >= 0)
{
direction=Math.floor((current_position /cols))%2;
if (direction==1)
axis_x=(cols-(current_position %cols)-1);
else
var pawn_x =0;
var pawn_y=0;
var direction=0;
var cols = board_cols[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_height = (board_height[current_board]-board_headery[current_board]-board_footery[current_board])/rows;
document.write('<img id="boardimage" src="images/meter.png">');
document.getElementById("boardimage").src = "images/" + board_images[ current_board];
document.write('<div id="dicecont">&nbsp;</div>');
if( current_position >= 0) {
direction=Math.floor((current_position /cols))%2;
if (direction == 1) {
axis_x=(cols-(current_position %cols)-1);
} else {
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));
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;
document.write('<div id="pawn1"><img id="pawn" alt="" src="images/player1.png"></div>');
move_pawn();
}
document.write('<div id="pawn1"><img id="pawn" alt="" src="images/player1.png"></div>');
move_pawn();
}
}
function selectBoard()
{
current_board = document.getElementById("boardtype").value;
document.getElementById("boardimage").src = "images/" + board_images[ current_board];
function selectBoard() {
current_board = document.getElementById("boardtype").value;
document.getElementById("boardimage").src = "images/" + board_images[ current_board];
}
function select_quest()
{
function select_quest() {
var quest_total = countofquestionsM + countofquestionsS;
var quest_candidates= new Array();
var i, q;
var quest_candidates= new Array();
var i, q;
for (i=0;i<3;i++) {
quest_candidates[i]=Math.floor((Math.random() * quest_total));
}
current_quest = quest_candidates[0];
for (i=1;i<3;i++) {
if (quest_times_asked[quest_candidates[i]]>quest_times_asked[current_quest])
current_quest=quest_candidates[i];
}
for (i=0;i<3;i++) {
quest_candidates[i]=Math.floor((Math.random() * quest_total));
}
current_quest = quest_candidates[0];
for (i=1;i<3;i++) {
if (quest_times_asked[quest_candidates[i]]>quest_times_asked[current_quest])
current_quest=quest_candidates[i];
}
q=Base64decode( questions[ current_quest]);
quest_resp = decode_multiple_choice( q);
@ -208,203 +206,185 @@ function select_quest()
quest_feedb = Base64decode( feedbacks[ current_quest]);
}
function IsMultipleChoiceQuestion()
{
function IsMultipleChoiceQuestion() {
return (current_quest < countofquestionsM);
}
function check_answer()
{
all_ans=all_ans+1;
if( IsMultipleChoiceQuestion())
check_answer_M();
else
check_answer_S();
function check_answer() {
all_ans=all_ans+1;
if( IsMultipleChoiceQuestion()) {
check_answer_M();
} else {
check_answer_S();
}
move_pawn();
move_pawn();
}
function check_answer_M()
{
document.getElementById("check_btn").style.display = "none";
var useranswer;
var n=document.snakesform.radio_answer.length;
for(useranswer=0;useranswer < n;useranswer++)
{
if( document.snakesform.radio_answer[ useranswer].checked)
break;
}
function check_answer_M() {
document.getElementById("check_btn").style.display = "none";
if( useranswer >= n)
{
alert( str_no_selection);
document.getElementById("feedb").innerHTML= "";
document.getElementById("check_btn").style.display = "block";
return;
}
var useranswer;
var n=document.snakesform.radio_answer.length;
for(useranswer=0;useranswer < n;useranswer++) {
if( document.snakesform.radio_answer[ useranswer].checked)
break;
}
var feedbacks = decode_multiple_choice(quest_feedb);
if( useranswer >= n) {
alert( str_no_selection);
document.getElementById("feedb").innerHTML= "";
document.getElementById("check_btn").style.display = "block";
return;
}
var j;
for (j=0;j<n;j++) {
document.snakesform.radio_answer[ j].disabled = "true";
}
var feedbacks = decode_multiple_choice(quest_feedb);
document.getElementById("feedb").innerHTML= feedbacks[ mchoice_positions[useranswer]];
document.getElementById("feedb").style.display = "block";
if ( mchoice_positions[ useranswer] == 1)
{
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
{
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();
}
var j;
for (j=0;j<n;j++) {
document.snakesform.radio_answer[ j].disabled = "true";
}
document.getElementById("OK_btn").style.display = "block";
document.getElementById("feedb").innerHTML= feedbacks[ mchoice_positions[useranswer]];
document.getElementById("feedb").style.display = "block";
if ( mchoice_positions[ useranswer] == 1) {
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 {
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()
{
document.getElementById("answer").disabled = "true";
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();
}
function check_answer_S() {
document.getElementById("answer").disabled = "true";
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";
document.getElementById("OK_btn").style.display = "block";
}
function check_game_over()
{
var out=(board_cols[current_board]*board_rows[current_board]);
if (current_position > out-1)
{
current_position=out-1;
showPopWin('modalContent.html', 350, 220, returnRefresh); // modal
}
function check_game_over() {
var out=(board_cols[current_board]*board_rows[current_board]);
if (current_position > out-1) {
current_position=out-1;
showPopWin('modalContent.html', 350, 220, returnRefresh); // modal
}
}
function check_exists_ladder()
{
var find = "L" + (current_position+1) + "-";
var pos = board_contents[ current_board].indexOf( find);
function check_exists_ladder() {
var find = "L" + (current_position+1) + "-";
var pos = board_contents[ current_board].indexOf( find);
if( pos < 0)
return;
if( pos < 0) {
return;
}
var s = board_contents[ current_board].substr( pos+find.length)
pos = s.indexOf( ',');
if( pos >= 0)
s = s.substr( 0, pos);
var s = board_contents[ current_board].substr( pos+find.length)
pos = s.indexOf( ',');
if (pos >= 0) {
s = s.substr( 0, pos);
}
current_position = s-1;
current_position = s-1;
}
function check_exists_snake()
{
var find = "-" + (current_position+1) + ",";
var s= ',' +board_contents[ current_board] + ',';
function check_exists_snake() {
var find = "-" + (current_position+1) + ",";
var s= ',' +board_contents[ current_board] + ',';
for(;;)
{
var pos = s.indexOf( find);
for(;;) {
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);
if( kind != "S")
{
s = s.substr( pos+1);
continue;
}
s = s.substr( pos_start+2);
pos = s.indexOf( '-');
current_position = s.substr( 0, pos)-1;
break;
}
var kind = s.substr( pos_start+1, 1);
if ( kind != "S") {
s = s.substr( pos+1);
continue;
}
s = s.substr( pos_start+2);
pos = s.indexOf( '-');
current_position = s.substr( 0, pos)-1;
break;
}
}
function decode_multiple_choice(s)
{
var ret = new Array();
var i=0;
for(;;)
{
var pos=s.indexOf( '#');
if( pos < 0)
{
ret[ i++] = s;
return ret;
}
ret[ i++] = s.substr( 0, pos);
s = s.substr( pos+1);
}
function decode_multiple_choice(s) {
var ret = new Array();
var i=0;
for(;;) {
var pos=s.indexOf( '#');
if( pos < 0) {
ret[ i++] = s;
return ret;
}
ret[ i++] = s.substr( 0, pos);
s = s.substr( pos+1);
}
}
function display_quest()
{
current_dice = Math.floor((Math.random() * 6)) + 1;
select_quest();
function display_quest() {
current_dice = Math.floor((Math.random() * 6)) + 1;
select_quest();
if( IsMultipleChoiceQuestion())
display_quest_M();
else
display_quest_S();
if( IsMultipleChoiceQuestion()) {
display_quest_M();
} else {
display_quest_S();
}
}
function display_quest_M()
{
s = '<table width="250px"><tr><td><div id="show_dice"> ';
function display_quest_M() {
s = '<table width="250px"><tr><td><div id="show_dice"> ';
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 + '<strong>'+str_score+': </strong>';
s = s + '<strong class="score">' +score+ '</strong></div></td></tr></table>';
s = s + '<div id="question_area">' + quest_text+'</div>';
s = s + '<form name="snakesform">';
mchoice_count = quest_resp.length-1;
mchoice_positions = new Array( mchoice_count);
for(i=0; i < mchoice_count ; i++)
mchoice_positions[ i] = i+1;
for(i=0; i < mchoice_count ; i++)
{
var j = Math.floor((Math.random() * mchoice_count));
var temp = mchoice_positions[ i];
mchoice_positions[ i] = mchoice_positions[ j];
mchoice_positions[ j] = temp;
}
s = s + '<div id="question_area">' + quest_text+'</div>';
s = s + '<form name="snakesform">';
mchoice_count = quest_resp.length-1;
mchoice_positions = new Array( mchoice_count);
for(i=0; i < mchoice_count ; i++) {
mchoice_positions[ i] = i+1;
}
for(i=0; i < mchoice_count ; i++) {
var j = Math.floor((Math.random() * mchoice_count));
var temp = mchoice_positions[ i];
mchoice_positions[ i] = mchoice_positions[ j];
mchoice_positions[ j] = temp;
}
for(i=0; i < mchoice_count;i++) {
s = s + '<input type="radio" name="radio_answer" id="radio_answer" value="';
for(i=0; i < mchoice_count;i++) {
s = s + '<input type="radio" name="radio_answer" id="radio_answer" value="';
s = s + i+'" />'+quest_resp[ mchoice_positions[ i]] + '<br />';
}
@ -415,17 +395,16 @@ function display_quest_M()
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>';
document.getElementById("dicecont").innerHTML = s;
document.getElementById("dicecont").innerHTML = s;
document.getElementById("question_area").style.display = "block";
document.getElementById("check_btn").style.display = "block";
document.getElementById("question_area").style.display = "block";
document.getElementById("check_btn").style.display = "block";
}
function display_quest_S()
{
function display_quest_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 + '<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">';
@ -440,24 +419,22 @@ function display_quest_S()
document.getElementById("check_btn").style.display = "block";
}
function move_pawn()
{
var pawn_x =0;
var pawn_y=0;
var direction=0;
var cols = board_cols[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_height = (board_height[current_board]-board_headery[current_board]-board_footery[current_board])/rows;
function move_pawn() {
var pawn_x =0;
var pawn_y=0;
var direction=0;
var cols = board_cols[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_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;
if (direction == 1) {
axis_x=(cols-(current_position %cols)-1);
}else
} else {
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;
@ -505,7 +482,7 @@ function move_pawn()
};
// private method for UTF-8 decoding
// Private method for UTF-8 decoding.
function Base64_utf8_decode(utftext) {
var string = "";
var i = 0;

Loading…
Cancel
Save