Browse Source

New: FinishGame button on Cryptex Game

MOODLE_20_STABLE
Vasilis Daloukas 10 years ago
parent
commit
3439e213c2
  1. 2
      attempt.php
  2. 45
      cryptex/play.php
  3. 10
      lib.php
  4. 8
      locallib.php
  5. 4
      version.php

2
attempt.php

@ -150,7 +150,7 @@
break;
case 'cryptexcheck': //the user tries to guess a question
$attempt = game_getattempt( $game, $detail);
game_cryptex_check( $id, $game, $attempt, $detail, $q, $answer, $context);
game_cryptex_check( $id, $game, $attempt, $detail, $q, $answer, $finishattempt, $context);
break;
case 'bookquizcheck': //the student tries to answer a question
$attempt = game_getattempt( $game, $detail);

45
cryptex/play.php

@ -85,12 +85,21 @@ function game_cryptex_continue( $id, $game, $attempt, $cryptexrec, $endofgame, $
}
//q means game_queries.id
function game_cryptex_check( $id, $game, $attempt, $cryptexrec, $q, $answer, $context)
function game_cryptex_check( $id, $game, $attempt, $cryptexrec, $q, $answer, $finishattempt, $context)
{
global $DB;
if( $attempt === false){
game_cryptex_continue( $id, $game, $attempt, $cryptexrec, false);
if( $finishattempt)
{
game_updateattempts( $game, $attempt, -1, true);
game_cryptex_continue( $id, $game, false, false, true, $context);
return;
}
if( $attempt === false)
{
game_cryptex_continue( $id, $game, $attempt, $cryptexrec, false, $context);
return;
}
@ -256,8 +265,10 @@ width: 240pt;
<?php
if( $showhtmlprintbutton){
echo ' &nbsp;&nbsp;&nbsp;&nbsp;<button id="printbutton" type="button" onclick="OnPrint();" style="display: block;">'.get_string( 'print', 'game');
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){
@ -272,14 +283,23 @@ if( $showhtmlprintbutton){
document.getElementById("printbutton").style.display = "block";
}
function OnPrint()
{
<?php
function OnPrint()
{
<?php
global $CFG;
$params = "id=$id&gameid=$game->id";
echo "window.open( \"{$CFG->wwwroot}/mod/game/print.php?$params\")";
?>
}
echo "window.open( \"{$CFG->wwwroot}/mod/game/print.php?$params\");";
?>
}
function OnEndGame()
{
<?php
global $CFG;
$params = 'id='.$id.'&action=cryptexcheck&g=&finishattempt=1';
echo "window.location = \"{$CFG->wwwroot}/mod/game/attempt.php?$params\";\r\n";
?>
}
</script>
<?php
}
@ -336,11 +356,10 @@ function OnPrint()
</script>
<?php
if( $print){
if( $print)
echo '<body onload="window.print()">';
}else{
else
echo '<body>';
}
}

10
lib.php

@ -1166,7 +1166,7 @@ function game_reset_userdata($data) {
if (!$cm = get_coursemodule_from_instance('game', $rec->id)) {
continue;
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = game_get_context_module_instance( $cm->id);
$fs->delete_area_files($context->id, 'mod_game', 'gnakes_file');
$fs->delete_area_files($context->id, 'mod_game', 'gnakes_board');
@ -1278,3 +1278,11 @@ function game_scale_used_anywhere($scaleid) {
return false;
}
}
function game_get_context_module_instance( $moduleid)
{
if( class_exists( 'context_module'))
return context_module::instance( $moduleid);
return get_context_instance( CONTEXT_MODULE, $moduleid);
}

8
locallib.php

@ -2080,14 +2080,6 @@ function game_get_context_course_instance( $courseid)
return get_context_instance( 50, $courseid);
}
function game_get_context_module_instance( $moduleid)
{
if( class_exists( 'context_module'))
return context_module::instance( $moduleid);
return get_context_instance( CONTEXT_MODULE, $moduleid);
}
function game_show_query( $game, $query, $text)
{
if( $game->glossaryid)

4
version.php

@ -22,10 +22,10 @@ if( !isset( $plugin))
$useplugin = 2;
$plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics)
$plugin->version = 2015071204; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2015071205; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2010112400; // Requires Moodle 2.0
$plugin->cron = 0; // Period for cron to check this module (secs)
$plugin->release = '3.30.12.4';
$plugin->release = '3.30.12.5';
if( $useplugin != 2)
$module = $plugin;

Loading…
Cancel
Save