示例#1
0
 public function initialise($seed)
 {
     $this->m_matrix = array();
     // initialise random number generator with game seed
     sjMathRandom::setSeed($seed);
     $typeCount = 0;
     // initialise board matrix, evenly distributing tiles
     for ($x = 0; $x < BOARD_WIDTH; $x++) {
         for ($y = 0; $y < BOARD_HEIGHT; $y++) {
             if ($y == 0) {
                 $this->m_matrix[$x] = array();
             }
             $typeCount = ($typeCount + 1) % BOARD_NUM_TILES;
             $this->m_matrix[$x][$y] = $typeCount;
         }
     }
     // randomise tiles based on seed
     for ($x = 0; $x < BOARD_WIDTH; $x++) {
         for ($y = 0; $y < BOARD_HEIGHT; $y++) {
             $newX = sjMathRandom::getRandom(BOARD_WIDTH) - 1;
             $newY = sjMathRandom::getRandom(BOARD_HEIGHT) - 1;
             // swop tiles
             $typeA = $this->m_matrix[$x][$y];
             $typeB = $this->m_matrix[$newX][$newY];
             $this->m_matrix[$x][$y] = $typeB;
             $this->m_matrix[$newX][$newY] = $typeA;
         }
     }
 }
示例#2
0
 public static function getRandom($max)
 {
     sjMathRandom::nextSeed();
     return ceil(sjMathRandom::$m_seed / sjMathRandom::PARAM_C * $max);
 }