Vasilis Daloukas
8 years ago
9 changed files with 7 additions and 2042 deletions
@ -1,190 +0,0 @@ |
|||
<?php |
|||
|
|||
class mod_game_exporthtml_form extends moodleform { |
|||
|
|||
public function definition() { |
|||
global $CFG, $game; |
|||
|
|||
$mform = $this->_form; |
|||
$html = $this->_customdata['html']; |
|||
|
|||
$mform->addElement('header', 'general', get_string('general', 'form')); |
|||
|
|||
if ( $game->gamekind == 'hangman') { |
|||
$options = array(); |
|||
$options[ '0'] = 'Hangman with phrases'; |
|||
$options[ 'hangmanp'] = 'Hangman with pictures'; |
|||
$mform->addElement('select', 'type', get_string('javame_type', 'game'), $options); |
|||
if ( $html->type == 0) { |
|||
$mform->setDefault('type', '0'); |
|||
} else { |
|||
$mform->setDefault('type', 'hangmanp'); |
|||
} |
|||
} |
|||
|
|||
// Input the filename. |
|||
$mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size' => '30')); |
|||
$mform->setDefault('filename', $html->filename); |
|||
$mform->setType('filename', PARAM_TEXT); |
|||
|
|||
// Input the html title. |
|||
$mform->addElement('text', 'title', get_string('html_title', 'game'), array('size' => '80')); |
|||
$mform->setDefault('title', $html->title); |
|||
$mform->setType('title', PARAM_TEXT); |
|||
|
|||
// Inputs special fields for hangman. |
|||
if ($game->gamekind == 'hangman') { |
|||
$mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size' => '5')); |
|||
$mform->setDefault('maxpicturewidth', $html->maxpicturewidth); |
|||
$mform->setType('maxpicturewidth', PARAM_INT); |
|||
$mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size' => '5')); |
|||
$mform->setDefault('maxpictureheight', $html->maxpictureheight); |
|||
$mform->setType('maxpictureheight', PARAM_INT); |
|||
} |
|||
|
|||
// Input special fields for crossword. |
|||
if ( $game->gamekind == 'cross') { |
|||
$mform->addElement('selectyesno', 'checkbutton', get_string('html_hascheckbutton', 'game')); |
|||
$mform->setDefault('checkbutton', $html->checkbutton); |
|||
$mform->addElement('selectyesno', 'printbutton', get_string('html_hasprintbutton', 'game')); |
|||
$mform->setDefault('printbutton', $html->printbutton); |
|||
} |
|||
|
|||
$mform->addElement('hidden', 'q', $game->id); |
|||
$mform->setType('q', PARAM_INT); |
|||
$mform->addElement('hidden', 'target', 'html'); |
|||
$mform->setType('target', PARAM_TEXT); |
|||
|
|||
$mform->addElement('submit', 'submitbutton', get_string( 'export', 'game')); |
|||
$mform->closeHeaderBefore('submitbutton'); |
|||
} |
|||
|
|||
public function validation($data, $files) { |
|||
global $CFG, $USER, $DB; |
|||
$errors = parent::validation($data, $files); |
|||
|
|||
return $errors; |
|||
} |
|||
|
|||
public function export() { |
|||
global $game, $DB; |
|||
|
|||
$mform = $this->_form; |
|||
|
|||
$html = new stdClass(); |
|||
$html->id = $this->_customdata['html']->id; |
|||
$html->type = optional_param('type', 0, PARAM_ALPHANUM); |
|||
$html->filename = $mform->getElementValue('filename'); |
|||
$html->title = $mform->getElementValue('title'); |
|||
$html->maxpicturewidth = optional_param('maxpicturewidth', 0, PARAM_INT); |
|||
$html->maxpictureheight = optional_param('maxpictureheight', 0, PARAM_INT); |
|||
if ( $mform->elementExists( 'checkbutton')) { |
|||
$checkbuttonvalue = $mform->getElementValue('checkbutton'); |
|||
$html->checkbutton = $checkbuttonvalue[ 0]; |
|||
} |
|||
if ( $mform->elementExists( 'printbutton')) { |
|||
$printbuttonvalue = $mform->getElementValue('printbutton'); |
|||
$html->printbutton = $printbuttonvalue[ 0]; |
|||
} |
|||
|
|||
if (!($DB->update_record( 'game_export_html', $html))) { |
|||
print_error("game_export_html: not updated id=$html->id"); |
|||
} |
|||
|
|||
$cm = get_coursemodule_from_instance('game', $game->id, $game->course); |
|||
$context = game_get_context_module_instance( $cm->id); |
|||
|
|||
require_once("exporthtml.php"); |
|||
game_OnExportHTML( $game, $context, $html); |
|||
} |
|||
} |
|||
|
|||
class mod_game_exportjavame_form extends moodleform { |
|||
|
|||
public function definition() { |
|||
global $CFG, $DB, $game; |
|||
|
|||
$mform = $this->_form; |
|||
$javame = $this->_customdata['javame']; |
|||
|
|||
$mform->addElement('header', 'general', get_string('general', 'form')); |
|||
|
|||
if ( $game->gamekind == 'hangman') { |
|||
$options = array(); |
|||
$options[ '0'] = 'Hangman with phrases'; |
|||
$options[ 'hangmanp'] = 'Hangman with pictures'; |
|||
$mform->addElement('select', 'type', get_string('javame_type', 'game'), $options); |
|||
} |
|||
|
|||
$mform->addElement('text', 'filename', get_string('javame_filename', 'game'), array('size' => '30')); |
|||
$mform->setDefault('filename', $javame->filename); |
|||
$mform->setType('filename', PARAM_TEXT); |
|||
$mform->addElement('text', 'icon', get_string('javame_icon', 'game')); |
|||
$mform->setDefault('icon', $javame->icon); |
|||
$mform->setType('icon', PARAM_TEXT); |
|||
$mform->addElement('text', 'createdby', get_string('javame_createdby', 'game')); |
|||
$mform->setDefault('createdby', $javame->createdby); |
|||
$mform->setType('createdby', PARAM_TEXT); |
|||
$mform->addElement('text', 'vendor', get_string('javame_vendor', 'game')); |
|||
$mform->setDefault('vendor', $javame->vendor); |
|||
$mform->setType('vendor', PARAM_TEXT); |
|||
$mform->addElement('text', 'name', get_string('javame_name', 'game'), array('size' => '80')); |
|||
$mform->setDefault('name', $javame->name); |
|||
$mform->setType('name', PARAM_TEXT); |
|||
$mform->addElement('text', 'description', get_string('javame_description', 'game'), array('size' => '80')); |
|||
$mform->setDefault('description', $javame->description); |
|||
$mform->setType('description', PARAM_TEXT); |
|||
$mform->addElement('text', 'version', get_string('javame_version', 'game'), array('size' => '10')); |
|||
$mform->setDefault('version', $javame->version); |
|||
$mform->setType('version', PARAM_TEXT); |
|||
$mform->addElement('text', 'maxpicturewidth', get_string('javame_maxpicturewidth', 'game'), array('size' => '5')); |
|||
$mform->setDefault('maxpicturewidth', $javame->maxpicturewidth); |
|||
$mform->setType('maxpicturewidth', PARAM_INT); |
|||
$mform->addElement('text', 'maxpictureheight', get_string('javame_maxpictureheight', 'game'), array('size' => '5')); |
|||
$mform->setDefault('maxpictureheight', $javame->maxpictureheight); |
|||
$mform->setType('maxpictureheight', PARAM_INT); |
|||
|
|||
$mform->addElement('hidden', 'q', $game->id); |
|||
$mform->setType('q', PARAM_INT); |
|||
$mform->addElement('hidden', 'target', 'javame'); |
|||
$mform->setType('target', PARAM_TEXT); |
|||
|
|||
$mform->addElement('submit', 'submitbutton', get_string( 'export', 'game')); |
|||
$mform->closeHeaderBefore('submitbutton'); |
|||
} |
|||
|
|||
public function validation($data, $files) { |
|||
global $CFG, $USER, $DB; |
|||
$errors = parent::validation($data, $files); |
|||
|
|||
return $errors; |
|||
} |
|||
|
|||
public function export() { |
|||
global $game, $DB; |
|||
|
|||
$mform = $this->_form; |
|||
|
|||
$javame = $this->_customdata['javame']; |
|||
|
|||
$javame->type = optional_param('type', 0, PARAM_ALPHANUM); |
|||
$javame->filename = $mform->getElementValue('filename'); |
|||
$javame->icon = $mform->getElementValue('icon'); |
|||
$javame->createdby = $mform->getElementValue('createdby'); |
|||
$javame->vendor = $mform->getElementValue('vendor'); |
|||
$javame->name = $mform->getElementValue('name'); |
|||
$javame->description = $mform->getElementValue('description'); |
|||
$javame->version = $mform->getElementValue('version'); |
|||
$javame->maxpicturewidth = $mform->getElementValue('maxpicturewidth'); |
|||
$javame->maxpictureheight = $mform->getElementValue('maxpictureheight'); |
|||
|
|||
if (!($DB->update_record( 'game_export_javame', $javame))) { |
|||
print_error("game_export_javame: not updated id=$javame->id"); |
|||
} |
|||
|
|||
require_once("exportjavame.php"); |
|||
game_OnExportJavaME( $game, $javame); |
|||
} |
|||
|
|||
} |
|||
|
@ -1,437 +0,0 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/* |
|||
* This 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"); |
|||
|
|||
function game_onexporthtml( $game, $context, $html) { |
|||
global $CFG; |
|||
|
|||
$destdir = game_export_createtempdir(); |
|||
|
|||
switch( $game->gamekind) { |
|||
case 'cross'; |
|||
game_onexporthtml_cross( $game, $context, $html, $destdir); |
|||
break; |
|||
case 'hangman': |
|||
game_onexporthtml_hangman( $game, $context, $html, $destdir); |
|||
break; |
|||
case 'snakes': |
|||
game_onexporthtml_snakes( $game, $html, $destdir, $context); |
|||
break; |
|||
case 'millionaire': |
|||
game_onexporthtml_millionaire( $game, $context, $html, $destdir); |
|||
break; |
|||
} |
|||
|
|||
remove_dir( $destdir); |
|||
} |
|||
|
|||
function game_onexporthtml_cross( $game, $context, $html, $destdir) { |
|||
|
|||
global $CFG, $DB; |
|||
|
|||
if ( $html->filename == '') { |
|||
$html->filename = 'cross'; |
|||
} |
|||
|
|||
$filename = $html->filename . '.htm'; |
|||
|
|||
require( "cross/play.php"); |
|||
$attempt = game_getattempt( $game, $crossrec, true); |
|||
if ( $crossrec == false) { |
|||
game_cross_new( $game, $attempt->id, $crossm); |
|||
$attempt = game_getattempt( $game, $crossrec); |
|||
} |
|||
|
|||
$ret = game_export_printheader( $html->title); |
|||
echo "$ret<br>"; |
|||
|
|||
ob_start(); |
|||
|
|||
game_cross_play( 0, $game, $attempt, $crossrec, '', true, false, false, false, |
|||
$html->checkbutton, true, $html->printbutton, false, $context); |
|||
|
|||
$outputstring = ob_get_contents(); |
|||
ob_end_clean(); |
|||
|
|||
$course = $DB->get_record( 'course', array( 'id' => $game->course)); |
|||
|
|||
$filename = $html->filename . '.htm'; |
|||
|
|||
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $outputstring); |
|||
|
|||
$filename = game_onexporthtml_cross_repair_questions( $game, $context, $filename, $destdir); |
|||
|
|||
game_send_stored_file( $filename); |
|||
} |
|||
|
|||
function game_onexporthtml_cross_repair_questions( $game, $context, $filename, $destdir) { |
|||
global $CFG, $DB; |
|||
|
|||
$filehandle = fopen( $destdir.'/'.$filename, "rb"); |
|||
|
|||
$found = false; |
|||
$files = array(); |
|||
$contextcourse = false; |
|||
$linesbefore = array(); |
|||
$linesafter = array(); |
|||
while (!feof($filehandle) ) { |
|||
$line = fgets( $filehandle); |
|||
|
|||
if ($found) { |
|||
if ( strpos( $line, 'new Array')) { |
|||
$linesafter[] = $line; |
|||
break; |
|||
} |
|||
$array .= $line; |
|||
continue; |
|||
} |
|||
|
|||
if (strpos( $line, 'Clue = new Array') === false) { |
|||
$linesbefore[] = $line; |
|||
continue; |
|||
} |
|||
|
|||
$array = $line; |
|||
$found = true; |
|||
} |
|||
while (!feof($filehandle) ) { |
|||
$linesafter[] = fgets( $filehandle); |
|||
} |
|||
|
|||
fclose($filehandle); |
|||
|
|||
$search = $CFG->wwwroot.'/pluginfile.php'; |
|||
$pos = 0; |
|||
$search = '"'.$CFG->wwwroot.'/pluginfile.php/'.$context->id.'/mod_game/'; |
|||
$len = strlen( $search); |
|||
$start = 0; |
|||
$filescopied = false; |
|||
for (;;) { |
|||
$pos1 = strpos( $array, $search, $start); |
|||
if ( $pos1 == false) { |
|||
break; |
|||
} |
|||
|
|||
$pos2 = strpos( $array, '\"', $pos1 + $len); |
|||
if ( $pos2 == false) { |
|||
break; |
|||
} |
|||
|
|||
// Have to copy the files. |
|||
if ($contextcourse === false) { |
|||
mkdir( $destdir.'/images'); |
|||
if (!$contextcourse = get_context_instance(CONTEXT_COURSE, $game->course)) { |
|||
print_error('nocontext'); |
|||
} |
|||
$fs = get_file_storage(); |
|||
} |
|||
|
|||
$inputs = explode( '/', substr( $array, $pos1 + $len, $pos2 - $pos1 - $len)); |
|||
|
|||
$filearea = $inputs[ 0]; |
|||
$id = $inputs[ 1]; |
|||
$fileimage = urldecode( $inputs[ 2]); |
|||
$component = 'question'; |
|||
|
|||
$params = array( 'component' => $component, 'filearea' => $filearea, |
|||
'itemid' => $id, 'filename' => $fileimage, 'contextid' => $context, 'contextid' => $contextcourse->id); |
|||
$rec = $DB->get_record( 'files', $params); |
|||
if ( $rec == false) { |
|||
break; |
|||
} |
|||
|
|||
if (!$file = $fs->get_file_by_hash($rec->pathnamehash) or $file->is_directory()) { |
|||
continue; |
|||
} |
|||
|
|||
$posext = strrpos( $fileimage, '.'); |
|||
$filenoext = substr( $fileimage, $posext); |
|||
$ext = substr( $fileimage, $posext + 1); |
|||
for ($i = 0;; $i++) { |
|||
$newfile = $filenoext.$i; |
|||
$newfile = md5( $newfile).'.'.$ext; |
|||
if (!array_search( $newfile, $files)) { |
|||
break; |
|||
} |
|||
} |
|||
$file->copy_content_to( $destdir.'/images/'.$newfile); |
|||
$filescopied = true; |
|||
|
|||
$array = substr( $array, 0, $pos1 + 1).'images/'.$newfile.substr( $array, $pos2); |
|||
} |
|||
|
|||
if ($filescopied == false) { |
|||
return $destdir.'/'.$filename; |
|||
} |
|||
|
|||
$linesbefore[] = $array; |
|||
foreach ($linesafter as $line) { |
|||
$linesbefore [] = $line; |
|||
} |
|||
file_put_contents( $destdir.'/'.$filename, $linesbefore); |
|||
|
|||
$pos = strrpos( $filename, '.'); |
|||
if ($pos === false) { |
|||
$filezip = $filename.'.zip'; |
|||
} else { |
|||
$filezip = substr( $filename, 0, $pos).'.zip'; |
|||
} |
|||
|
|||
$filezip = game_create_zip( $destdir, $game->course, $filezip); |
|||
|
|||
return $filezip; |
|||
} |
|||
|
|||
function game_export_printheader( $title, $showbody=true) { |
|||
$ret = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n"; |
|||
$ret .= '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="el" xml:lang="el">'."\n"; |
|||
$ret .= "<head>\n"; |
|||
$ret .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'."\n"; |
|||
$ret .= '<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">'."\n"; |
|||
$ret .= "<title>$title</title>\n"; |
|||
$ret .= "</head>\n"; |
|||
if ($showbody) { |
|||
$ret .= "<body>"; |
|||
} |
|||
|
|||
return $ret; |
|||
} |
|||
|
|||
function game_onexporthtml_hangman( $game, $context, $html, $destdir) { |
|||
|
|||
global $CFG, $DB; |
|||
|
|||
if ($html->filename == '') { |
|||
$html->filename = 'hangman'; |
|||
} |
|||
|
|||
if ($game->param10 <= 0) { |
|||
$game->param10 = 6; |
|||
} |
|||
|
|||
$filename = $html->filename . '.htm'; |
|||
|
|||
$ret = game_export_printheader( $html->title, false); |
|||
$ret .= "\r<body onload=\"reset()\">\r"; |
|||
|
|||
$exportattachment = ( $html->type == 'hangmanp'); |
|||
print_r( $game); |
|||
$map = game_exmportjavame_getanswers( $game, $context, $exportattachment, $destdir, $files); |
|||
if ($map == false) { |
|||
print_error( get_string('no_words', 'game')); |
|||
} |
|||
|
|||
ob_start(); |
|||
|
|||
// Here is the code of hangman. |
|||
require_once( "exporthtml_hangman.php"); |
|||
|
|||
$outputstring = ob_get_contents(); |
|||
ob_end_clean(); |
|||
|
|||
$courseid = $game->course; |
|||
$course = $DB->get_record( 'course', array( 'id' => $courseid)); |
|||
|
|||
$filename = $html->filename . '.htm'; |
|||
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $outputstring); |
|||
|
|||
if ($html->type != 'hangmanp') { |
|||
// Not copy the standard pictures when we use the "Hangman with pictures". |
|||
$src = $CFG->dirroot.'/mod/game/pix/hangman/1'; |
|||
$handle = opendir( $src); |
|||
while (false !== ($item = readdir($handle))) { |
|||
if ($item != '.' && $item != '..') { |
|||
if (!is_dir($src.'/'.$item)) { |
|||
$itemdest = $item; |
|||
|
|||
if ( strpos( $item, '.') === false) { |
|||
continue; |
|||
} |
|||
|
|||
copy( $src.'/'.$item, $destdir.'/'.$itemdest); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
$filezip = game_create_zip( $destdir, $courseid, $html->filename.'.zip'); |
|||
game_send_stored_file( $filezip); |
|||
} |
|||
|
|||
function game_onexporthtml_millionaire( $game, $context, $html, $destdir) { |
|||
|
|||
global $CFG, $DB; |
|||
|
|||
if ($html->filename == '') { |
|||
$html->filename = 'millionaire'; |
|||
} |
|||
|
|||
$filename = $html->filename . '.htm'; |
|||
|
|||
$ret = game_export_printheader( $html->title, false); |
|||
$ret .= "\r<body onload=\"Reset();\">\r"; |
|||
|
|||
// Here is the code of millionaire. |
|||
require( "exporthtml_millionaire.php"); |
|||
|
|||
$questions = game_millionaire_html_getquestions( $game, $context, $maxanswers, $maxquestions, $retfeedback, $destdir, $files); |
|||
ob_start(); |
|||
|
|||
game_millionaire_html_print( $game, $questions, $maxanswers); |
|||
|
|||
// End of millionaire code. |
|||
$outputstring = ob_get_contents(); |
|||
ob_end_clean(); |
|||
|
|||
$courseid = $game->course; |
|||
$course = $DB->get_record( 'course', array( 'id' => $courseid)); |
|||
|
|||
$filename = $html->filename . '.htm'; |
|||
|
|||
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $outputstring); |
|||
|
|||
// Copy the standard pictures of Millionaire. |
|||
$src = $CFG->dirroot.'/mod/game/pix/millionaire/1'; |
|||
$handle = opendir( $src); |
|||
while (false !== ($item = readdir($handle))) { |
|||
if ($item != '.' && $item != '..') { |
|||
if (!is_dir($src.'/'.$item)) { |
|||
$itemdest = $item; |
|||
|
|||
if (strpos( $item, '.') === false) { |
|||
continue; |
|||
} |
|||
|
|||
copy( $src.'/'.$item, $destdir.'/'.$itemdest); |
|||
} |
|||
} |
|||
} |
|||
|
|||
$filezip = game_create_zip( $destdir, $courseid, $html->filename.'.zip'); |
|||
game_send_stored_file($filezip); |
|||
} |
|||
|
|||
function game_onexporthtml_snakes( $game, $html, $destdir, $context) { |
|||
require_once( "exporthtml_millionaire.php"); |
|||
|
|||
global $CFG, $DB; |
|||
|
|||
if ($html->filename == '') { |
|||
$html->filename = 'snakes'; |
|||
} |
|||
|
|||
$filename = $html->filename . '.htm'; |
|||
|
|||
$ret = ''; |
|||
|
|||
$board = game_snakes_get_board( $game); |
|||
|
|||
if ( ($game->sourcemodule == 'quiz') or ($game->sourcemodule == 'question')) { |
|||
$questionsm = game_millionaire_html_getquestions( $game, $context, $maxquestions, |
|||
$countofquestionsm, $retfeedback, $destdir, $files); |
|||
} else { |
|||
$questionsm = array(); |
|||
$countofquestionsm = 0; |
|||
$retfeedback = ''; |
|||
} |
|||
$questionss = game_exmportjavame_getanswers( $game, $context, false, $destdir, $files); |
|||
|
|||
ob_start(); |
|||
|
|||
// Here is the code of Snakes and Ladders. |
|||
require( "exporthtml_snakes.php"); |
|||
|
|||
$outputstring = ob_get_contents(); |
|||
ob_end_clean(); |
|||
|
|||
$courseid = $game->course; |
|||
$course = $DB->get_record( 'course', array( 'id' => $courseid)); |
|||
|
|||
$filename = $html->filename . '.htm'; |
|||
|
|||
file_put_contents( $destdir.'/'.$filename, $ret . "\r\n" . $outputstring); |
|||
|
|||
$src = $CFG->dirroot.'/mod/game/export/html/snakes'; |
|||
game_copyfiles( $src, $destdir); |
|||
|
|||
mkdir( $destdir .'/css'); |
|||
$src = $CFG->dirroot.'/mod/game/export/html/snakes/css'; |
|||
game_copyfiles( $src, $destdir.'/css'); |
|||
|
|||
mkdir( $destdir .'/js'); |
|||
$src = $CFG->dirroot.'/mod/game/export/html/snakes/js'; |
|||
game_copyfiles( $src, $destdir.'/js'); |
|||
unzip_file($destdir.'/js/js.zip', $destdir.'/js', false); |
|||
unlink( $destdir.'/js/js.zip'); |
|||
|
|||
mkdir( $destdir .'/images'); |
|||
$destfile = $destdir.'/images/'.$board->fileboard; |
|||
if ( $game->param3 != 0) { |
|||
// Is a standard board. |
|||
copy( $board->imagesrc, $destfile); |
|||
} else { |
|||
$cmg = get_coursemodule_from_instance('game', $game->id, $game->course); |
|||
$modcontext = get_context_instance(CONTEXT_MODULE, $cmg->id); |
|||
$fs = get_file_storage(); |
|||
$files = $fs->get_area_files($modcontext->id, 'mod_game', 'snakes_board', $game->id); |
|||
foreach ($files as $f) { |
|||
if ( $f->is_directory()) { |
|||
continue; |
|||
} |
|||
break; |
|||
} |
|||
$f->copy_content_to( $destfile); |
|||
} |
|||
|
|||
$a = array( 'player1.png', 'dice1.png', 'dice2.png', 'dice3.png', 'dice4.png', 'dice5.png', 'dice6.png', 'numbers.png'); |
|||
foreach ($a as $file) { |
|||
copy( $CFG->dirroot.'/mod/game/snakes/1/'.$file, $destdir.'/images/'.$file); |
|||
} |
|||
|
|||
$filezip = game_create_zip( $destdir, $courseid, $html->filename.'.zip'); |
|||
game_send_stored_file($filezip); |
|||
} |
|||
|
|||
function game_copyfiles( $src, $destdir) { |
|||
$handle = opendir( $src); |
|||
while (($item = readdir($handle)) !== false) { |
|||
if ( $item == '.' or $item == '..') { |
|||
continue; |
|||
} |
|||
|
|||
if ( strpos( $item, '.') === false) { |
|||
continue; |
|||
} |
|||
|
|||
if (is_dir($src.'/'.$item)) { |
|||
continue; |
|||
} |
|||
|
|||
copy( $src.'/'.$item, $destdir.'/'.$item); |
|||
} |
|||
closedir($handle); |
|||
} |
@ -1,372 +0,0 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/* |
|||
* This page export the game hangman to html |
|||
* |
|||
* @author bdaloukas |
|||
* @package game |
|||
**/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
?> |
|||
<script type="text/javascript"> |
|||
|
|||
// Hangman for Moodle by Vasilis Daloukas. |
|||
// The script is based on HangMan II script- By Chris Fortey (http://www.c-g-f.net/) |
|||
|
|||
var can_play = true; |
|||
<?php |
|||
|
|||
$destdir = game_export_createtempdir(); |
|||
|
|||
$exportattachment = ( $html->type == 'hangmanp'); |
|||
$map = game_exmportjavame_getanswers( $game, $context, $exportattachment, $destdir, $files); |
|||
if ($map == false) { |
|||
print_error( 'No Questions'); |
|||
} |
|||
|
|||
$questions = ''; |
|||
$words = ''; |
|||
$lang = ''; |
|||
$allletters = ''; |
|||
$images = ''; |
|||
foreach ($map as $line) { |
|||
$answer = game_upper( $line->answer); |
|||
if ($game->param7) { |
|||
// Have to delete space. |
|||
$answer = str_replace(' ', '', $answer); |
|||
} |
|||
if ($game->param8) { |
|||
// Have to deletε -. |
|||
$answer = str_replace('-', '', $answer); |
|||
} |
|||
|
|||
if ($lang == '') { |
|||
$lang = $game->language; |
|||
|
|||
if ($lang == '') { |
|||
$lang = game_detectlanguage( $answer); |
|||
} |
|||
if ($lang == '') { |
|||
$lang = current_language(); |
|||
} |
|||
$allletters = game_getallletters( $answer, $lang); |
|||
} |
|||
|
|||
if (game_getallletters( $answer, $lang) != $allletters) { |
|||
continue; |
|||
} |
|||
|
|||
if ($html->type == 'hangmanp') { |
|||
$file = $line->attachment; |
|||
$pos = strrpos( $file, '.'); |
|||
if ($pos == false) { |
|||
continue; |
|||
} |
|||
} |
|||
|
|||
if ($html->type == 'hangmanp') { |
|||
$src = $line->attachment; |
|||
$pos = strrpos( $file, '.'); |
|||
if ($pos == false) { |
|||
continue; |
|||
} |
|||
} |
|||
|
|||
if ($questions != '') { |
|||
$questions .= ', '; |
|||
} |
|||
|
|||
if ($words != '') { |
|||
$words .= ', '; |
|||
} |
|||
$questions .= '"'.base64_encode( $line->question).'"'; |
|||
$words .= '"'.base64_encode( $line->answer).'"'; |
|||
|
|||
if ($html->type == 'hangmanp') { |
|||
$file = $line->id.substr( $file, $pos); |
|||
game_export_javame_smartcopyimage( $src, $destdir.'/'.$file, $html->maxpicturewidth, $html->maxpictureheight); |
|||
|
|||
if ($images != '') { |
|||
$images .= ', '; |
|||
} |
|||
$images .= '"'.$file.'"'; |
|||
} |
|||
} |
|||
|
|||
if ($game->param7) { |
|||
$allletters .= '_'; |
|||
} |
|||
|
|||
if ($game->param8) { |
|||
$allletters .= '-'; |
|||
} |
|||
|
|||
echo "var questions = new Array($questions);\r"; |
|||
echo "var words = new Array($words);\r"; |
|||
if ($html->type == 'hangmanp') { |
|||
echo "var images = new Array($images);\r"; |
|||
} |
|||
?> |
|||
|
|||
var to_guess = ""; |
|||
var display_word = ""; |
|||
var used_letters = ""; |
|||
var wrong_guesses = 0; |
|||
var used_letters_all = ""; |
|||
var all_letters = new Array(<?php |
|||
$len = game_strlen( $allletters); |
|||
for ($i = 0; $i < $len; $i++) { |
|||
if ($i > 0) { |
|||
echo ','; |
|||
} |
|||
echo '"'.game_substr( $allletters, $i, 1).'"'; |
|||
} |
|||
?>); |
|||
|
|||
function selectLetter(l) |
|||
{ |
|||
if (can_play == false) |
|||
{ |
|||
} |
|||
|
|||
if (used_letters.indexOf(l) != -1) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
used_letters_all += l; |
|||
|
|||
if( to_guess.indexOf(l) == -1) { |
|||
used_letters += l; |
|||
document.getElementById('usedLetters').innerHTML = used_letters; |
|||
} |
|||
|
|||
if (to_guess.indexOf(l) != -1) { |
|||
// correct letter guess |
|||
pos = 0; |
|||
temp_mask = display_word; |
|||
|
|||
while (to_guess.indexOf(l, pos) != -1) { |
|||
pos = to_guess.indexOf(l, pos); |
|||
end = pos + 1; |
|||
|
|||
start_text = temp_mask.substring(0, pos); |
|||
end_text = temp_mask.substring(end, temp_mask.length); |
|||
|
|||
temp_mask = start_text + l + end_text; |
|||
pos = end; |
|||
} |
|||
|
|||
display_word = temp_mask; |
|||
document.getElementById('displayWord').innerHTML=display_word; |
|||
|
|||
if (display_word.indexOf("#") == -1) { |
|||
// won |
|||
alert( "<?php echo game_get_string_lang( 'win', 'game', $lang); ?>"); |
|||
can_play = false; |
|||
reset(); |
|||
} |
|||
} else { |
|||
wrong_guesses++; |
|||
|
|||
<?php |
|||
if ($html->type != 'hangmanp') { |
|||
?>eval("document.hm.src=\"hangman_" + wrong_guesses + ".jpg\""); |
|||
// Ιncortect letter guess. |
|||
eval("document.hm.src=\"hangman_" + wrong_guesses + ".jpg\""); |
|||
<?php |
|||
} |
|||
?> |
|||
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; |
|||
reset(); |
|||
} |
|||
} |
|||
|
|||
showallletters(); |
|||
} |
|||
|
|||
function stripHTML(oldString) { |
|||
|
|||
return oldString.replace(/<[^>]*>/g, ""); |
|||
|
|||
} |
|||
|
|||
function reset() { |
|||
selectWord(); |
|||
|
|||
document.getElementById('usedLetters').innerHTML = " "; |
|||
used_letters = ""; |
|||
used_letters_all = ""; |
|||
wrong_guesses = 0; |
|||
showallletters(); |
|||
|
|||
<?php |
|||
if ($html->type != 'hangmanp') { |
|||
echo ' document.hm.src="hangman_0.jpg"'."\r"; |
|||
} |
|||
?> |
|||
|
|||
} |
|||
|
|||
function showallletters() { |
|||
var letters = ""; |
|||
var next = all_letters.length / 4; |
|||
var letter = ""; |
|||
|
|||
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) { |
|||
continue; |
|||
} |
|||
} |
|||
|
|||
letters = letters + "<a href=\"javascript:selectLetter('" + letter + "');\">" + letter + "</a>" |
|||
} |
|||
document.getElementById( "letters").innerHTML = letters; |
|||
} |
|||
|
|||
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. |
|||
masked_word = createMask(to_guess); |
|||
document.getElementById('displayWord').innerHTML=masked_word; |
|||
|
|||
display_word = masked_word; |
|||
|
|||
<?php |
|||
if ($html->type == 'hangmanp') { |
|||
echo " document.hm.src = images[ random_number];\r"; |
|||
} else { |
|||
echo " document.getElementById('question').innerHTML=to_question;\r"; |
|||
} |
|||
?> |
|||
} |
|||
|
|||
function createMask(m) |
|||
{ |
|||
mask = ""; |
|||
word_lenght = m.length; |
|||
|
|||
|
|||
for (i = 0; i < word_lenght; i++) { |
|||
mask += "#"; |
|||
} |
|||
|
|||
return mask; |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* Base64 encode / decode |
|||
* http://www.webtoolkit.info/ |
|||
* |
|||
**/ |
|||
|
|||
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; |
|||
} |
|||
} |
|||
</script> |
|||
</head> |
|||
|
|||
<div id="question"></div> |
|||
<img src="<?php echo ($html->type == 'hangmanp' ? '' : 'hangman_0.jpg');?>" name="hm"> |
|||
<a href="javascript:reset();"><?php echo game_get_string_lang( 'html_hangman_new', 'game', $lang); ?></a> |
|||
<form name="game"> |
|||
<div id="displayWord"> </div> |
|||
<div id="usedLetters"> </div> |
|||
</form> |
|||
<div id="letters"></div> |
|||
|
|||
</body> |
@ -1,518 +0,0 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/** |
|||
* This page export the game millionaire to html |
|||
* |
|||
* @author bdaloukas |
|||
* @package game |
|||
**/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
function game_millionaire_html_getquestions( $game, $context, &$maxanswers, &$countofquestions, &$retfeedback, $destdir, &$files) { |
|||
global $CFG, $DB, $USER; |
|||
|
|||
$maxanswers = 0; |
|||
$countofquestions = 0; |
|||
|
|||
$files = array(); |
|||
|
|||
if ( ($game->sourcemodule != 'quiz') and ($game->sourcemodule != 'question')) { |
|||
print_error( get_string('millionaire_sourcemodule_must_quiz_question', 'game', get_string( 'modulename', 'quiz')). |
|||
' '.get_string( 'modulename', $game->sourcemodule)); |
|||
} |
|||
|
|||
if ( $game->sourcemodule == 'quiz') { |
|||
if ( $game->quizid == 0) { |
|||
print_error( get_string( 'must_select_quiz', 'game')); |
|||
} |
|||
$select = "qtype='multichoice' AND quiz='$game->quizid' ". |
|||
" AND qqi.question=q.id"; |
|||
$table = "{question} q,{quiz_question_instances} qqi"; |
|||
} else { |
|||
if ( $game->questioncategoryid == 0) { |
|||
print_error( get_string( 'must_select_questioncategory', 'game')); |
|||
} |
|||
|
|||
// Include subcategories. |
|||
$select = 'category='.$game->questioncategoryid; |
|||
if ( $game->subcategories) { |
|||
$cats = question_categorylist( $game->questioncategoryid); |
|||
if (strpos( $cats, ',') > 0) { |
|||
$select = 'category in ('.$cats.')'; |
|||
} |
|||
} |
|||
$select .= " AND qtype='multichoice'"; |
|||
|
|||
$table = "{question} q"; |
|||
} |
|||
$select .= " AND q.hidden=0"; |
|||
$sql = "SELECT q.id as id, q.questiontext FROM $table WHERE $select"; |
|||
$recs = $DB->get_records_sql( $sql); |
|||
$ret = ''; |
|||
$retfeedback = ''; |
|||
foreach ($recs as $rec) { |
|||
$recs2 = $DB->get_records( 'question_answers', array( 'question' => $rec->id), 'fraction DESC', 'id,answer,feedback'); |
|||
|
|||
// Must parse the questiontext and get the name of files. |
|||
$line = $rec->questiontext; |
|||
$line = game_export_split_files( $game->course, $context, 'questiontext', $rec->id, $rec->questiontext, $destdir, $files); |
|||
$linefeedback = ''; |
|||
foreach ($recs2 as $rec2) { |
|||
$line .= '#'.str_replace( array( '"', '#'), array( "'", ' '), |
|||
game_export_split_files( $game->course, $context, 'answer', $rec2->id, $rec2->answer, $destdir, $files)); |
|||
$linefeedback .= '#'.str_replace( array( '"', '#'), array( "'", ' '), $rec2->feedback); |
|||
} |
|||
if ( $ret != '') { |
|||
$ret .= ",\r"; |
|||
} |
|||
$ret .= '"'.base64_encode( $line).'"'; |
|||
|
|||
if ( $retfeedback != '') { |
|||
$retfeedback .= ",\r"; |
|||
} |
|||
$retfeedback .= '"'.base64_encode( $linefeedback).'"'; |
|||
|
|||
if ( count( $recs2) > $maxanswers) { |
|||
$maxanswers = count( $recs2); |
|||
} |
|||
$countofquestions++; |
|||
} |
|||
|
|||
return $ret; |
|||
} |
|||
|
|||
function game_millionaire_html_print( $game, $questions, $maxquestions) { |
|||
$color1 = 'black'; |
|||
$color2 = 'DarkOrange'; |
|||
$colorback = "white"; |
|||
$stylequestion = "background:$colorback;color:$color1"; |
|||
$stylequestionselected = "background:$colorback;color:$color2"; |
|||
?> |
|||
|
|||
<body onload="Reset();"> |
|||
|
|||
<script type="text/javascript"> |
|||
|
|||
// Millionaire for Moodle by Vasilis Daloukas. |
|||
<?php echo 'var questions = new Array('.$questions.");\r"; ?> |
|||
var current_question = 0; |
|||
var level = 0; |
|||
var posCorrect = 0; |
|||
var infoCorrect = ""; |
|||
var flag5050 = 0; |
|||
var flagTelephone = 0; |
|||
var flagPeople = 0; |
|||
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 OnGameOver( ans) { |
|||
document.getElementById( "info").innerHTML = "<?php echo get_string( 'millionaire_info_wrong_answer', 'game');?> " + |
|||
document.getElementById( "lblAnswer" + posCorrect).innerHTML; |
|||
Highlite( posCorrect); |
|||
Restore( ans); |
|||
document.getElementById( "lblAnswer" + posCorrect).style.backgroundColor = '<?php echo $color2;?>'; |
|||
|
|||
alert( "<?php echo strip_tags( get_string( 'hangman_loose', 'game')); ?>"); |
|||
|
|||
Restore( posCorrect); |
|||
document.getElementById( "lblAnswer" + posCorrect).style.backgroundColor = '<?php echo $colorback;?>'; |
|||
|
|||
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 OnHelp5050( ans) { |
|||
if (flag5050) { |
|||
return; |
|||
} |
|||
|
|||
document.getElementById( "Help5050").src = "5050x.png"; |
|||
flag5050 = 1; |
|||
|
|||
for (pos = posCorrect;pos == posCorrect;pos = 1+Math.floor(Math.random()*countQuestions)); |
|||
|
|||
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'; |
|||
} |
|||
} |
|||
} |
|||
|
|||
function OnHelpTelephone( ans) { |
|||
if( flagTelephone) { |
|||
return; |
|||
} |
|||
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; |
|||
} |
|||
|
|||
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) { |
|||
if( flagPeople) { |
|||
return; |
|||
} |
|||
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; |
|||
} |
|||
aPercent[ countQuestions - 1] = 100 - sum; |
|||
if( Math.random() <= 0.8) { |
|||
//with percent 80% sets in the correct answer the biggest percent |
|||
max_pos = 0; |
|||
for( i=1; i < countQuestions; i++) { |
|||
if( aPercent[ i] >= aPercent[ max_pos]) |
|||
max_pos = i; |
|||
} |
|||
temp = aPercent[ max_pos]; |
|||
aPercent[ max_pos] = aPercent[ posCorrect-1]; |
|||
aPercent[ posCorrect-1] = temp; |
|||
} |
|||
|
|||
var letters = "<?php echo get_string( 'lettersall', 'game');?>"; |
|||
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; |
|||
} |
|||
|
|||
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;?>"; |
|||
} |
|||
|
|||
flag5050 = 0; |
|||
flagTelephone = 0; |
|||
flagPeople = 0; |
|||
|
|||
document.getElementById( "Help5050").src = "5050.png"; |
|||
document.getElementById( "HelpPeople").src = "people.png"; |
|||
document.getElementById( "HelpTelephone").src = "telephone.png"; |
|||
|
|||
document.getElementById( "info").innerHTML = ""; |
|||
UpdateLevel( 1); |
|||
SelectNextQuestion(); |
|||
} |
|||
|
|||
function RandomizeAnswers( elements) { |
|||
posCorrect = 1; |
|||
countQuestions = elements.length-1; |
|||
|
|||
for( i=1; i <= countQuestions; i++) { |
|||
pos = 1+Math.floor(Math.random()*countQuestions); |
|||
if( posCorrect == i) { |
|||
posCorrect = pos; |
|||
} else if ( posCorrect == pos) |
|||
posCorrect = i; |
|||
|
|||
var temp = elements[ i]; |
|||
elements[ i] = elements[ pos]; |
|||
elements[ pos] = temp; |
|||
} |
|||
} |
|||
|
|||
function SelectNextQuestion() { |
|||
current_question = Math.floor(Math.random()*questions.length); |
|||
question = Base64.decode( questions[ current_question]); |
|||
|
|||
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 = ""; |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* Base64 encode / decode |
|||
* http://www.webtoolkit.info/ |
|||
* |
|||
**/ |
|||
|
|||
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; |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<table cellpadding=0 cellspacing=0 border=0> |
|||
<tr style='background:#408080'> |
|||
<td rowspan=<?php echo 17 + $maxquestions;?>> </td> |
|||
<td colspan=6> </td> |
|||
<td rowspan=<?php echo 17 + $maxquestions;?>> </td> |
|||
</tr> |
|||
|
|||
<tr height=10%> |
|||
<td style='background:#408080' rowspan=3 colspan=2> |
|||
<input type="image" name="Help5050" id="Help5050" Title="50 50" src="5050.png" alt="" border="0" onmousedown=OnHelp5050();> |
|||
<input type="image" name="HelpTelephone" id="HelpTelephone" Title="<?php echo get_string( 'millionaire_telephone', 'game');?>" |
|||
src="telephone.png" alt="" border="0" onmousedown="OnHelpTelephone();"> |
|||
<input type="image" name="HelpPeople" id="HelpPeople" Title="<?php echo get_string( 'millionaire_helppeople', 'game');?>" |
|||
src="people.png" alt="" border="0" onmousedown="OnHelpPeople();"> |
|||
<input type="image" name="Quit" id="Quit" Title="<?php echo get_string( 'millionaire_quit', 'game');?>" |
|||
src="x.png" alt="" border="0" onmousedown=OnQuit();> |
|||
</td> |
|||
<td rowspan=<?php echo 16 + $maxquestions;?> style='background:#408080'> </td> |
|||
<td id="levela15" align=right>15</td> |
|||
<td id="levelb15"> </td> |
|||
<td id="levelc15" align=right> 150000</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela14" align=right>14</td> |
|||
<td id="levelb14"></td><td id="levelc14" align=right> 800000</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela13" align=right>13</td> |
|||
<td id="levelb13"></td><td id="levelc13" align=right> 400000</td> |
|||
</tr> |
|||
|
|||
<tr><td rowspan=12 colspan=2 valign=top style='background:<?php echo $colorback;?>;color:<?php echo $color1;?>'> |
|||
<div id="question">aa</div></td> |
|||
<td id="levela12" align=r0ight>12</div></td> |
|||
<td id="levelb12"></td><td id="levelc12" align=right> 200000</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela11" align=right>11</td> |
|||
<td id="levelb11"></td><td id="levelc11" align=right> 10000</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela10" align=right>10</td> |
|||
<td id="levelb10"></td><td id="levelc10" align=right> 5000</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela9" align=right>9</td> |
|||
<td id="levelb9"></td><td id="levelc9" align=right> 4000</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela8" align=right>8</td> |
|||
<td id="levelb8"></td><td id="levelc8" align=right> 2000</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela7" align=right>7</td> |
|||
<td id="levelb7"></td><td id="levelc7" align=right> 1500</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela6" align=right>6</td> |
|||
<td id="levelb6"></td><td id="levelc6" align=right> 1000</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela5" align=right>5</td> |
|||
<td id="levelb5"></td><td id="levelc5" align=right> 500</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela4" align=right>4</td> |
|||
<td id="levelb4"></td><td id="levelc4" align=right> 400</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela3" align=right>3</td> |
|||
<td id="levelb3"></td><td id="levelc3" align=right> 300</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela2" align=right>2</td> |
|||
<td id="levelb2"></td><td id="levelc2" align=right> 200</td> |
|||
</tr> |
|||
|
|||
<tr><td id="levela1" align=right>1</td> |
|||
<td id="levelb1"></td><td id="levelc1" align=right> 100</td> |
|||
</tr> |
|||
|
|||
<tr style='background:#408080'><td colspan=10> </td> |
|||
</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%> <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'> </td></tr> |
|||
|
|||
</table> |
|||
|
|||
|
|||
</body> |
|||
</html> |
|||
<?php |
|||
} |
@ -1,519 +0,0 @@ |
|||
<?php |
|||
// This file is part of Moodle - http://moodle.org/ |
|||
// |
|||
// Moodle is free software: you can redistribute it and/or modify |
|||
// it under the terms of the GNU General Public License as published by |
|||
// the Free Software Foundation, either version 3 of the License, or |
|||
// (at your option) any later version. |
|||
// |
|||
// Moodle is distributed in the hope that it will be useful, |
|||
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
// GNU General Public License for more details. |
|||
// |
|||
// You should have received a copy of the GNU General Public License |
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
/* |
|||
* This page export the game snakes to html |
|||
* |
|||
* @author bdaloukas |
|||
* @package game |
|||
**/ |
|||
|
|||
defined('MOODLE_INTERNAL') || die(); |
|||
|
|||
?> |
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|||
<html xmlns="http://www.w3.org/1999/xhtml"> |
|||
<head> |
|||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|||
<title><?php echo $html->title;?></title> |
|||
|
|||
<link href="css/game.css" rel="stylesheet" type="text/css" /> |
|||
|
|||
<link rel="stylesheet" type="text/css" href="css/subModal.css" /> |
|||
<script type="text/javascript" src="js/common.js"></script> |
|||
<script type="text/javascript" src="js/subModal.js"></script> |
|||
|
|||
<style type="text/css"> |
|||
#pawn |
|||
{ |
|||
position:absolute; |
|||
} |
|||
|
|||
img |
|||
{ |
|||
border:hidden |
|||
|
|||
} |
|||
body |
|||
{ |
|||
background: #999 url('images/backdropJungle.png') no-repeat fixed left top; |
|||
} |
|||
|
|||
.score { |
|||
color: #FC3; |
|||
font-size: 40px; |
|||
} |
|||
</style> |
|||
|
|||
</head> |
|||
|
|||
<body> |
|||
|
|||
<script language="JavaScript"> |
|||
// Snakes for Moodle by Maria Rigkou. |
|||
|
|||
var boards = 1; |
|||
var board_images = new Array( boards); |
|||
var board_names = new Array( boards); |
|||
var pawn_width = new Array(boards); |
|||
var pawn_height = new Array(boards); |
|||
var board_cols = new Array(boards); |
|||
var board_rows = new Array(boards); |
|||
var board_contents = new Array (boards); |
|||
var board_headerx = new Array(boards); |
|||
var board_headery = new Array(boards); |
|||
var board_footerx = new Array(boards); |
|||
var board_footery = new Array(boards); |
|||
var board_width = new Array(boards); |
|||
var board_height = new Array(boards); |
|||
var board_data = new Array(boards); |
|||
var pawn_width = new Array(boards); |
|||
var pawn_height = new Array(boards); |
|||
|
|||
var current_board = 0; |
|||
var current_position=0; |
|||
var current_quest = 0; |
|||
var mchoice_count = 0; |
|||
var mchoice_positions =new Array( 1); |
|||
|
|||
var quest_text = ""; //Question |
|||
var quest_resp = ""; // Answer |
|||
var quest_feedb = ""; // feedback |
|||
var quest_total = 25; // Count of questions |
|||
|
|||
board_names[ 0] = "<?php echo $game->name; ?>"; |
|||
board_images[ 0] = '<?php echo $board->fileboard; ?>'; |
|||
board_cols [0] = <?php echo $board->cols; ?>; |
|||
board_rows [0] = <?php echo $board->rows; ?>; |
|||
board_contents [0] = '<?php echo $board->data; ?>'; |
|||
board_headerx [0] = <?php echo $board->headerx; ?>; |
|||
board_headery [0] = <?php echo $board->headery; ?>; |
|||
board_footerx [0] = <?php echo $board->footerx; ?>; |
|||
board_footery [0] = <?php echo $board->footery; ?>; |
|||
board_width [0] = <?php echo $board->width; ?>; |
|||
board_height [0] = <?php echo $board->height; ?>; |
|||
pawn_width [0] = 40; |
|||
pawn_height [0]= 40; |
|||
|
|||
<?php |
|||
|
|||
echo "var countofquestionsM=$countofquestionsm;\r\n"; |
|||
echo 'var countofquestionsS='.count($questionss).";\r\n"; |
|||
|
|||
foreach ($questionss as $line) { |
|||
$s = $line->question.'#'.str_replace( array( '"', '#'), array( "'", ' '), $line->answer); |
|||
if ($questionsm != '') { |
|||
$questionsm .= ",\r"; |
|||
} |
|||
$questionsm .= '"'.base64_encode( game_upper( $s)).'"'; |
|||
|
|||
$s = '#'.str_replace( array( '"', '#'), array( "'", ' '), $line->feedback); |
|||
if ($retfeedback != '') { |
|||
$retfeedback .= ",\r"; |
|||
} |
|||
$retfeedback .= '"'.base64_encode( $s).'"'; |
|||
} |
|||
$rettimesasked = ''; |
|||
for ($i = 0; $i < $countofquestionsm + count($questionss); $i++) { |
|||
$rettimesasked .= ',0'; |
|||
} |
|||
$rettimesasked = substr( $rettimesasked, 1); |
|||
|
|||
echo "var questions=new Array( $questionsm);\r\n"; |
|||
echo "var feedbacks=new Array( $retfeedback);\r\n"; |
|||
echo "var quest_times_asked=new Array( $rettimesasked); //How many times is used a question\r\n"; |
|||
|
|||
?> |
|||
var current_dice=0; |
|||
var feedb_correct_S = "<?php print_string( 'html_snakes_correct', 'game'); ?>"; |
|||
var feedb_wrong_S = "<?php print_string( 'html_snakes_wrong', 'game'); ?>"; |
|||
var str_score = "<?php print_string( 'score', 'game'); ?>"; |
|||
var str_check = "<?php print_string( 'html_snakes_check', 'game'); ?>"; |
|||
var str_no_selection = "<?php print_string( 'html_snakes_no_selection', 'game'); ?>"; |
|||
|
|||
var correct_ans = 0; //counter of correct answers |
|||
var all_ans = 0; //counter of all answers |
|||
var score = 0; |
|||
|
|||
ShowMainForm(); |
|||
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"> </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); |
|||
pawn_y += (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() { |
|||
current_board = document.getElementById("boardtype").value; |
|||
document.getElementById("boardimage").src = "images/" + board_images[ current_board]; |
|||
} |
|||
|
|||
function select_quest() { |
|||
var quest_total = countofquestionsM + countofquestionsS; |
|||
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]; |
|||
} |
|||
|
|||
q=Base64decode( questions[ current_quest]); |
|||
quest_resp = decode_multiple_choice( q); |
|||
quest_text = quest_resp[ 0]; |
|||
quest_feedb = Base64decode( feedbacks[ current_quest]); |
|||
} |
|||
|
|||
function IsMultipleChoiceQuestion() { |
|||
return (current_quest < countofquestionsM); |
|||
} |
|||
|
|||
function check_answer() { |
|||
all_ans=all_ans+1; |
|||
if( IsMultipleChoiceQuestion()) { |
|||
check_answer_M(); |
|||
} else { |
|||
check_answer_S(); |
|||
} |
|||
|
|||
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; |
|||
} |
|||
|
|||
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]]; |
|||
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); |
|||
var s = '<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>'; |
|||
document.getElementById("show_score").innerHTML = s; |
|||
check_game_over(); |
|||
check_exists_ladder(); |
|||
} else { |
|||
score = Math.round((correct_ans/all_ans)*100); |
|||
var s = '<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>'; |
|||
document.getElementById("show_score").innerHTML = s; |
|||
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); |
|||
var s = '<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>'; |
|||
document.getElementById("show_score").innerHTML = s; |
|||
check_game_over(); |
|||
check_exists_ladder(); |
|||
} else { |
|||
document.getElementById("feedb_wrong").style.display = "block"; |
|||
score = Math.round((correct_ans/all_ans)*100); |
|||
var s = '<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>'; |
|||
document.getElementById("show_score").innerHTML = s; |
|||
check_exists_snake(); |
|||
} |
|||
|
|||
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_exists_ladder() { |
|||
var find = "L" + (current_position+1) + "-"; |
|||
var pos = board_contents[ current_board].indexOf( find); |
|||
|
|||
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); |
|||
} |
|||
|
|||
current_position = s-1; |
|||
} |
|||
|
|||
function check_exists_snake() { |
|||
var find = "-" + (current_position+1) + ","; |
|||
var s= ',' +board_contents[ current_board] + ','; |
|||
|
|||
for(;;) { |
|||
var pos = s.indexOf( find); |
|||
|
|||
if (pos < 0) { |
|||
return; |
|||
} |
|||
|
|||
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; |
|||
} |
|||
} |
|||
|
|||
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(); |
|||
|
|||
if( IsMultipleChoiceQuestion()) { |
|||
display_quest_M(); |
|||
} else { |
|||
display_quest_S(); |
|||
} |
|||
} |
|||
|
|||
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; |
|||
} |
|||
|
|||
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 />'; |
|||
} |
|||
|
|||
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 + quest_feedb+' </div> <br /><div id="feedb" style="display:none; color:yellow;"> '; |
|||
s = s + quest_feedb+'. Θα προχωρήσεις '; |
|||
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("question_area").style.display = "block"; |
|||
document.getElementById("check_btn").style.display = "block"; |
|||
} |
|||
|
|||
function display_quest_S() { |
|||
var s = ""; |
|||
|
|||
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">'; |
|||
s = s + quest_text+'</div> <br /><input type="text" id="answer"/><br /><br /> <input type="button" id="check_btn" value="'; |
|||
s = s + str_check+'" onclick="check_answer();"> <br /> <div id="feedb_area">'; |
|||
s = s + ' <div id="feedb_wrong" style="display:none; color:yellow;"> '; |
|||
s = s + feedb_wrong_S+' </div> <div id="feedb" style="display:none; color:yellow;"> '; |
|||
s = s + feedb_correct_S+'</div> <br /><div id="OK_btn" style="display:none;">'; |
|||
s = s + '<input type="button" onclick="display_quest();" value="OK"/></div> </div>'; |
|||
document.getElementById("dicecont").innerHTML = s; |
|||
document.getElementById("question_area").style.display = "block"; |
|||
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; |
|||
|
|||
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); |
|||
pawn_y += (col_height-pawn_height[current_board])/2; |
|||
|
|||
document.getElementById("pawn1").style.position='relative'; |
|||
document.getElementById("pawn1").style.left=pawn_x+'px'; |
|||
document.getElementById("pawn1").style.bottom=pawn_y+'px'; |
|||
} |
|||
} |
|||
|
|||
function Base64decode(input) { |
|||
var output = ""; |
|||
var chr1, chr2, chr3; |
|||
var enc1, enc2, enc3, enc4; |
|||
var i = 0; |
|||
var keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; |
|||
|
|||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); |
|||
|
|||
while (i < input.length) { |
|||
enc1 = keyStr.indexOf(input.charAt(i++)); |
|||
enc2 = keyStr.indexOf(input.charAt(i++)); |
|||
enc3 = keyStr.indexOf(input.charAt(i++)); |
|||
enc4 = 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. |
|||
function Base64_utf8_decode(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> |
|||
|
|||
</body> |
|||
</html> |
Loading…
Reference in new issue