Browse Source

New: Cross,Cryptex can set the minimum number of words that a cross/cryptex can have

MOODLE_20_STABLE
bdaloukas 12 years ago
parent
commit
6a117da888
  1. 17
      cross/cross_class.php
  2. 3
      cross/play.php
  3. 4
      cryptex/cryptexdb_class.php
  4. 4
      cryptex/play.php
  5. 9
      lang/en/game.php
  6. 8
      mod_form.php

17
cross/cross_class.php

@ -105,7 +105,7 @@ class Cross
}
}
function computedata( &$crossm, &$crossd, &$letters, $maxwords)
function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords)
{
$t1 = time();
@ -121,9 +121,9 @@ class Cross
//selects the size of the cross
$N20 = mt_rand( $this->m_N20min, $this->m_N20max);
if( !$this->computenextcross( $N20, $t1, $ctries, $maxwords, $nochange))
if( !$this->computenextcross( $N20, $t1, $ctries, $minwords, $maxwords, $nochange))
break;
$ctries++;
if (time() - $t1 > $this->m_time_limit - 3){
@ -140,7 +140,7 @@ class Cross
return $this->savepuzzle( $crossm, $crossd, $ctries, time()-$t1);
}
function computenextcross( $N20, $t1, $ctries, $maxwords, &$nochange)
function computenextcross( $N20, $t1, $ctries, $minwords, $maxwords, &$nochange)
{
$MAXW = $N20;
@ -186,7 +186,8 @@ class Cross
if ($this->scan_pos($p[0], $p[1], false, $puzzle, $words, $magics, $poss, $cross_pos, $cross_dir, $cross_word, $N20)){
$n_words = count( $cross_word);
if( $maxwords){
if( $maxwords)
{
if( $n_words >= $maxwords){
break;
}
@ -198,6 +199,12 @@ class Cross
}
$n_words = count( $cross_word);
if( $minwords)
{
if( $n_words < $minwords)
return true;
}
$score = $this->computescore( $puzzle, $N20, $N22, $N2222, $n_words, $n_connectors, $n_filleds, $cSpaces, $cross_word);
if ($score > $this->m_best_score)

3
cross/play.php

@ -62,8 +62,9 @@ function game_cross_new( $game, $attemptid, &$crossm)
$cross->setwords( $answers, $game->param1, $reps);
//game->param4 is minimum words in crossword
//game->param2 is maximum words in crossword
if( $cross->computedata( $crossm, $crossd, $lettets, $game->param2)){
if( $cross->computedata( $crossm, $crossd, $lettets, $game->param4, $game->param2)){
$new_crossd = array();
foreach( $crossd as $rec)
{

4
cryptex/cryptexdb_class.php

@ -214,9 +214,9 @@ class CryptexDB extends CrossDB
return Cross::setwords( $answers, $maxcols, $reps);
}
function computedata( &$crossm, &$crossd, &$letters, $maxwords)
function computedata( &$crossm, &$crossd, &$letters, $minwords, $maxwords)
{
if( !cross::computedata( $crossm, $crossd, $letters, $maxwords)){
if( !cross::computedata( $crossm, $crossd, $letters, $minwords, $maxwords)){
return false;
}

4
cryptex/play.php

@ -59,7 +59,9 @@ function game_cryptex_continue( $id, $game, $attempt, $cryptexrec, $endofgame, $
$cryptex->setwords( $answers, $game->param1, $reps);
if( $cryptex->computedata( $crossm, $crossd, $letters, $game->param2)){
//game->param4 is minimum words
//game->param2 is maximum words
if( $cryptex->computedata( $crossm, $crossd, $letters, $game->param4, $game->param2)){
$new_crossd = array();
foreach( $crossd as $rec)
{

9
lang/en/game.php

@ -209,13 +209,12 @@ $string[ 'bottomtext'] = 'Text at the bottom of page';
$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 of crossword';
$string[ 'cross_maxwords'] = 'Maximum number of words of crossword';
$string[ 'cross_maxcols'] = 'Maximum number of cols/rows';
$string[ 'cross_maxwords'] = 'Maximum number of words';
$string[ 'cross_minwords'] = 'Minimum number of words';
$string[ 'cross_options'] = 'Crossword options';
$string[ 'cryptex_maxcols'] = 'Maximum number of cols/rows in cryptex';
$string[ 'cryptex_maxtries'] = 'Max tries';
$string[ 'cryptex_maxwords'] = 'Maximum number of words in cryptex';
$string[ 'cryptex_options'] = 'Cryptex ofptions';
$string[ 'cryptex_options'] = 'Cryptex options';
$string[ 'gameclose'] = 'Close the game';
$string[ 'gameopen'] = 'Open the game';
$string[ 'grademethod'] = 'Grading method';

8
mod_form.php

@ -224,6 +224,8 @@ class mod_game_mod_form extends moodleform_mod {
$mform->addElement('header', 'cross', get_string( 'cross_options', 'game'));
$mform->addElement('text', 'param1', get_string('cross_maxcols', 'game'));
$mform->setType('param1', PARAM_INT);
$mform->addElement('text', 'param4', get_string('cross_minwords', 'game'));
$mform->setType('param4', PARAM_INT);
$mform->addElement('text', 'param2', get_string('cross_maxwords', 'game'));
$mform->setType('param2', PARAM_INT);
$mform->addElement('selectyesno', 'param7', get_string('hangman_allowspaces','game'));
@ -238,9 +240,11 @@ class mod_game_mod_form extends moodleform_mod {
if($gamekind == 'cryptex'){
$mform->addElement('header', 'cryptex', get_string( 'cryptex_options', 'game'));
$mform->addElement('text', 'param1', get_string('cryptex_maxcols', 'game'));
$mform->addElement('text', 'param1', get_string('cross_maxcols', 'game'));
$mform->setType('param1', PARAM_INT);
$mform->addElement('text', 'param2', get_string('cryptex_maxwords', 'game'));
$mform->addElement('text', 'param4', get_string('cross_minwords', 'game'));
$mform->setType('param4', PARAM_INT);
$mform->addElement('text', 'param2', get_string('cross_maxwords', 'game'));
$mform->setType('param2', PARAM_INT);
$mform->addElement('selectyesno', 'param7', get_string('hangman_allowspaces','game'));
$mform->addElement('text', 'param8', get_string('cryptex_maxtries','game'));

Loading…
Cancel
Save