Browse Source

New: In parameters you can set the maximum number of attempts

MOODLE_20_STABLE
root 12 years ago
parent
commit
fe0cf9a1fb
  1. 8
      cross/crossdb_class.php
  2. 7
      cross/play.php
  3. 9
      hangman/play.php
  4. 11
      lang/en/game.php
  5. 83
      lib.php
  6. 17
      locallib.php
  7. 8
      mod_form.php
  8. 4
      version.php
  9. 8
      view.php

8
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[] = '<b>'.$wrongletters.' '.( $wrongletters > 1 ? get_string( 'cross_errors', 'game') : get_string( 'cross_error', 'game')).'</b>';
if( $correctletters > 1 or $wrongletters > 1) {
$ret = get_string( 'cross_found_many', 'game');

7
cross/play.php

@ -118,8 +118,11 @@ function game_cross_play( $id, $game, $attempt, $crossrec, $g, $onlyshow, $shows
if( $endofgame == false){
echo '<B>'.get_string( 'win', 'game').'</B><BR>';
}
echo '<br>';
echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id=$id&forcenew=1\">".get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
if( game_can_start_new_attempt( $game))
{
echo '<br>';
echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id=$id&forcenew=1\">".get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
}
}else if( $info != ''){
echo "<br>$info<br>";
}

9
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 '<br/>';
if( ($hangman->try < $hangman->maxtries) or ($hangman->maxtries == 0)){
//continue to next word
$params = "id=$id&action2=nextword\">".get_string( 'nextword', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp;';
echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?$params";
echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?$params";
}else
{
game_hangman_onfinishgame( $game, $attempt, $hangman);
echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id=$id\">".get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
if( game_can_start_new_attempt( $game))
echo "<a href=\"{$CFG->wwwroot}/mod/game/attempt.php?id=$id\">".get_string( 'nextgame', 'game').'</a> &nbsp; &nbsp; &nbsp; &nbsp; ';
}
if (! $cm = $DB->get_record('course_modules', array( 'id' => $id))) {

11
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'] = '<h3>Welcome!</h3><p>Click on a word to begin.</p>';
$string[ 'cross_welcome'] = '<h3>Welcome!</h3><p>Click on a word to begin/continue.</p>';
$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';

83
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

17
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;
}

8
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

4
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';

8
view.php

@ -94,6 +94,10 @@
//echo '<div class="gameattemptcounts"><a href="report.php?mode=overview&amp;id=' .
// $cm->id . '">' . $strattemptnum . "</a></div>\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 '<br>';
if ($numattempts == 0) {

Loading…
Cancel
Save