Пример #1
0
 protected function createMotionModule(SnakePlayer $player, $direction)
 {
     $head = $player->getHead();
     $module = new \stdClass();
     $direction = $this->calcDirection($direction, $head->d);
     switch ($direction) {
         case "l":
             $module->x = $head->x + minus(self::distance);
             $module->y = $head->y;
             break;
         case "r":
             $module->x = $head->x + self::distance;
             $module->y = $head->y;
             break;
         case "u":
             $module->y = $head->y + minus(self::distance);
             $module->x = $head->x;
             break;
         case "d":
             $module->y = $head->y + self::distance;
             $module->x = $head->x;
             break;
     }
     $module->d = $direction;
     return $module;
 }
Пример #2
0
 public function computeMovement(SnakeBoard $board, SnakePlayer $player, $module)
 {
     if ($this->isOccupied($board, $module->x, $module->y) || $this->isBorder($board, $module->x, $module->y)) {
         $player->inGame(false);
         return false;
     }
     if ($this->isBug($board, $module->x, $module->y)) {
         $player->addExtra();
         $player->incScore(25);
         $board->addBug();
     }
     $player->setModule($module);
     return true;
 }