diff --git a/cross/crossdb_class.php b/cross/crossdb_class.php
index 9aad2c6..85a4b8c 100755
--- a/cross/crossdb_class.php
+++ b/cross/crossdb_class.php
@@ -124,9 +124,9 @@ function game_cross_computecheck( $correctletters, $wrongletters, $restletters,
{
$ret = '';
- if( $correctletters == 0 and $wrongletters == 0){
- return $ret;
- }
+ //if( $correctletters == 0 and $wrongletters == 0){
+ // return $ret;
+ //}
$and = get_string( 'and', 'game');
@@ -134,7 +134,7 @@ function game_cross_computecheck( $correctletters, $wrongletters, $restletters,
if( $correctletters)
$a[] = $correctletters.' '.( $correctletters > 1 ? get_string( 'cross_corrects', 'game') :get_string( 'cross_correct', 'game'));
if( $wrongletters)
- $a[] = $wrongletters.' '.( $wrongletters > 1 ? get_string( 'cross_errors', 'game') : get_string( 'cross_error', 'game'));
+ $a[] = ''.$wrongletters.' '.( $wrongletters > 1 ? get_string( 'cross_errors', 'game') : get_string( 'cross_error', 'game')).'';
if( $correctletters > 1 or $wrongletters > 1) {
$ret = get_string( 'cross_found_many', 'game');
diff --git a/cross/play.php b/cross/play.php
index fcf743f..6ac9337 100755
--- a/cross/play.php
+++ b/cross/play.php
@@ -118,8 +118,11 @@ function game_cross_play( $id, $game, $attempt, $crossrec, $g, $onlyshow, $shows
if( $endofgame == false){
echo ''.get_string( 'win', 'game').'
';
}
- echo '
';
- echo "wwwroot}/mod/game/attempt.php?id=$id&forcenew=1\">".get_string( 'nextgame', 'game').' ';
+ if( game_can_start_new_attempt( $game))
+ {
+ echo '
';
+ echo "wwwroot}/mod/game/attempt.php?id=$id&forcenew=1\">".get_string( 'nextgame', 'game').' ';
+ }
}else if( $info != ''){
echo "
$info
";
}
diff --git a/hangman/play.php b/hangman/play.php
index d1dfca8..4b470a8 100755
--- a/hangman/play.php
+++ b/hangman/play.php
@@ -466,17 +466,20 @@ function hangman_onincorrect( $id, $word_line, $word, $game, $attempt, $hangman,
function game_hangman_show_nextword( $id, $game, $attempt, $hangman)
{
- global $CFG, $DB;
+ global $CFG, $DB;
echo '
';
if( ($hangman->try < $hangman->maxtries) or ($hangman->maxtries == 0)){
//continue to next word
+
$params = "id=$id&action2=nextword\">".get_string( 'nextword', 'game').' ';
- echo "wwwroot}/mod/game/attempt.php?$params";
+ echo "wwwroot}/mod/game/attempt.php?$params";
}else
{
game_hangman_onfinishgame( $game, $attempt, $hangman);
- echo "wwwroot}/mod/game/attempt.php?id=$id\">".get_string( 'nextgame', 'game').' ';
+
+ if( game_can_start_new_attempt( $game))
+ echo "wwwroot}/mod/game/attempt.php?id=$id\">".get_string( 'nextgame', 'game').' ';
}
if (! $cm = $DB->get_record('course_modules', array( 'id' => $id))) {
diff --git a/lang/en/game.php b/lang/en/game.php
index 0db7ba5..bd2fc6a 100755
--- a/lang/en/game.php
+++ b/lang/en/game.php
@@ -20,10 +20,10 @@ $string[ 'lettersall'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
//cross/crossdb_class.php
$string[ 'and'] = 'and';
-$string[ 'cross_correct'] = 'corrert';
-$string[ 'cross_corrects'] = 'corrects';
-$string[ 'cross_error'] = 'error';
-$string[ 'cross_errors'] = 'errors';
+$string[ 'cross_correct'] = 'corrert character';
+$string[ 'cross_corrects'] = 'correct characters';
+$string[ 'cross_error'] = 'wrong character';
+$string[ 'cross_errors'] = 'wrong characters';
$string[ 'cross_found_many'] = 'Found';
$string[ 'cross_found_one'] = 'Found';
$string[ 'grade'] = 'Grade';
@@ -37,7 +37,7 @@ $string[ 'cross_error_containsbadchars'] = 'The word contains illegal charactere
$string[ 'cross_error_wordlength1'] = 'The correct word contains ';
$string[ 'cross_error_wordlength2'] = ' letters.';
$string[ 'cross_pleasewait'] = 'Please wait while cross is loading';
-$string[ 'cross_welcome'] = '
Click on a word to begin.
'; +$string[ 'cross_welcome'] = 'Click on a word to begin/continue.
'; $string[ 'letter'] = 'letter'; $string[ 'letters'] = 'letters'; $string[ 'nextgame'] = 'New game'; @@ -210,6 +210,7 @@ $string[ 'cross_layout'] = 'Layout'; $string[ 'cross_layout0'] = 'Phrases on the bottom of cross'; $string[ 'cross_layout1'] = 'Phrases on the right of cross'; $string[ 'cross_maxcols'] = 'Maximum number of cols/rows'; +$string[ 'cross_max_attempts'] = 'Maximum number of attempts'; $string[ 'cross_maxwords'] = 'Maximum number of words'; $string[ 'cross_minwords'] = 'Minimum number of words'; $string[ 'cross_options'] = 'Crossword options'; diff --git a/lib.php b/lib.php index 4e8839a..2744c54 100755 --- a/lib.php +++ b/lib.php @@ -786,6 +786,7 @@ function game_get_grading_options() { * @param stdClass $module The module object returned from the DB * @param stdClass $cm The course module isntance returned from the DB */ + /* function game_extend_navigation($gamenode, $course, $module, $cm) { $context = get_context_instance(CONTEXT_MODULE, $cm->id); @@ -802,10 +803,10 @@ function game_extend_navigation($gamenode, $course, $module, $cm) { $gamenode->add(get_string('edit', 'moodle', ''), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('t/edit', '')); } - /* if (has_capability('mod/game:viewreports', $context)) { - $url = new moodle_url('/mod/game/report.php', array('q'=>$cm->instance)); - $reportnode = $gamenode->add(get_string('results', 'game'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/item', '')); - } */ + // if (has_capability('mod/game:viewreports', $context)) { + // $url = new moodle_url('/mod/game/report.php', array('q'=>$cm->instance)); + // $reportnode = $gamenode->add(get_string('results', 'game'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/item', '')); + //} if (has_capability('mod/game:viewreports', $context)) { $url = new moodle_url('/mod/game/showanswers.php', array('q'=>$cm->instance)); @@ -844,6 +845,80 @@ function game_extend_navigation($gamenode, $course, $module, $cm) { } } } +*/ +/** + * This function extends the settings navigation block for the site. + * + * It is safe to rely on PAGE here as we will only ever be within the module + * context when this is called + * + * @param settings_navigation $settings + * @param navigation_node $quiznode + * @return void + */ +function game_extend_settings_navigation($settings, $gamenode) { + global $PAGE, $CFG, $DB; + + $context = $PAGE->cm->context; + + if (!has_capability('mod/game:viewreports', $context)) + return; + + if (has_capability('mod/game:view', $context)) { + $url = new moodle_url('/mod/game/view.php', array('id'=>$PAGE->cm->id)); + $gamenode->add(get_string('info', 'game'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/info', '')); + } + + if (has_capability('mod/game:manage', $context)) { + $url = new moodle_url('/course/modedit.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey())); + $gamenode->add(get_string('edit', 'moodle', ''), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('t/edit', '')); + } + + /* if (has_capability('mod/game:viewreports', $context)) { + $url = new moodle_url('/mod/game/report.php', array('q'=>$cm->instance)); + $reportnode = $gamenode->add(get_string('results', 'game'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/item', '')); + } */ + + if (has_capability('mod/game:viewreports', $context)) { + $url = new moodle_url('/mod/game/showanswers.php', array('q'=>$PAGE->cm->instance)); + $reportnode = $gamenode->add(get_string('showanswers', 'game'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/item', '')); + } + + if (has_capability('mod/game:viewreports', $context)) { + $url = new moodle_url('/mod/game/showattempts.php', array('q'=>$PAGE->cm->instance)); + $reportnode = $gamenode->add(get_string('showattempts', 'game'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('f/explore', '')); + } + + + if (has_capability('mod/game:viewreports', $context)) + { + $game = $DB->get_record('game', array("id" => $PAGE->cm->instance)); + $courseid = $game->course; + + switch( $game->gamekind){ + case 'bookquiz': + $url = new moodle_url('/mod/game/bookquiz/questions.php', array('q'=>$PAGE->cm->instance)); + $exportnode = $gamenode->add( get_string('bookquiz_questions', 'game'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/item', '')); + break; + case 'hangman': + $url = new moodle_url('', null); + $exportnode = $gamenode->add( get_string('export', 'game'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')); + + $url = new moodle_url('/mod/game/export.php', array( 'id' => $PAGE->cm->id,'courseid'=>$courseid, 'target' => 'html')); + $exportnode->add( get_string('export_to_html', 'game'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/item', '')); + + $url = new moodle_url('/mod/game/export.php', array( 'id' => $PAGE->cm->id,'courseid'=>$courseid, 'target' => 'javame')); + $exportnode->add( get_string('export_to_javame', 'game'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/item', '')); + break; + case 'snakes': + case 'cross': + case 'millionaire': + $url = new moodle_url('/mod/game/export.php', array( 'id' => $game->id,'courseid'=>$courseid, 'target' => 'html')); + $gamenode->add(get_string('export_to_html', 'game'), $url, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/item', '')); + break; + } + } +} /** * Returns an array of game type objects to construct diff --git a/locallib.php b/locallib.php index 3a8bf83..57c0fb9 100755 --- a/locallib.php +++ b/locallib.php @@ -1907,3 +1907,20 @@ function game_get_version() return $rec->version; } + +function game_can_start_new_attempt( $game) +{ + global $DB, $USER; + + if( $game->maxattempts == 0) + return true; + + $sql = "SELECT COUNT(*) as c FROM {game_attempts} WHERE gameid={$game->id} AND userid={$USER->id}"; + if( ($rec = $DB->get_record_sql( $sql)) === false) + return true; + + if( $rec->c >= $game->maxattempts) + return false; + else + return true; +} diff --git a/mod_form.php b/mod_form.php index 82dd086..487cd63 100755 --- a/mod_form.php +++ b/mod_form.php @@ -158,6 +158,10 @@ class mod_game_mod_form extends moodleform_mod { } $mform->addElement('select', 'bookid', get_string('sourcemodule_book', 'game'), $a); } + +//Common settings to all games + $mform->addElement('text', 'maxattempts', get_string('cross_max_attempts','game')); + $mform->setType('maxattempts', PARAM_INT); //--------------------------------------------------------------------------- // Grade options @@ -178,8 +182,8 @@ class mod_game_mod_form extends moodleform_mod { $mform->addHelpButton('timeopen', 'quizopenclose', 'quiz'); $mform->addElement('date_time_selector', 'timeclose', get_string('gameclose', 'game'), - array('optional' => true, 'step' => 1)); - + array('optional' => true, 'step' => 1)); + //--------------------------------------------------------------------------- // Bookquiz options diff --git a/version.php b/version.php index fb78b65..93cf48f 100755 --- a/version.php +++ b/version.php @@ -11,7 +11,7 @@ defined('MOODLE_INTERNAL') || die(); $module->component = 'mod_game'; // Full name of the plugin (used for diagnostics) -$module->version = 2013071601; // The current module version (Date: YYYYMMDDXX) +$module->version = 2013072501; // The current module version (Date: YYYYMMDDXX) $module->requires = 2010112400; // Requires Moodle 2.0 $module->cron = 0; // Period for cron to check this module (secs) -$module->release = '3.7.16'; +$module->release = '3.7.25'; diff --git a/view.php b/view.php index 2fb2d27..7ed5fd3 100755 --- a/view.php +++ b/view.php @@ -94,6 +94,10 @@ //echo '\n"; echo $strattemptnum; + if( $game->maxattempts) + { + echo ' ('.get_string( 'max', 'quiz').': '.$game->maxattempts.')'; + } } } @@ -262,6 +266,10 @@ $buttontext = get_string('continueattemptgame', 'game'); } } else { + //Game is finished. Check if max number of attempts is reached + if( !game_can_start_new_attempt( $game)) + $canattempt = false; + if ($canattempt) { echo '