예제 #1
0
파일: GameManager.php 프로젝트: h0ke/OftBot
 public function start()
 {
     try {
         $user = $this->event->getRequest()->getSendingUser();
         $channel = $this->event->getRequest()->getSource();
         if (!$this->current_game) {
             throw new \Exception('There\'s no game in progress.');
         }
         if ($user != $this->current_game->getGameOwner()->getName()) {
             throw new \Exception('You can\'t do that because you didn\'t create this game - @' . $this->current_game->getGameOwner()->getName() . ' did.');
         }
         $this->current_game->start();
         $this->event->addResponse(Response::notice($channel, 'Joining has ended, time to play the game.'));
         $this->event->addResponse(Response::notice($channel, 'Play order: ' . join(', ', $this->getCurrentGamePlayerNames())));
         $this->event->addResponse(Response::notice($channel, '@' . $this->current_game->getCurrentPlayer()->getName() . ', you\'re up first.  Type \'@oftbot roll\' to take your first roll.'));
     } catch (\Exception $e) {
         $this->event->addResponse(Response::msg($user, $e->getMessage()));
     }
 }
예제 #2
0
파일: GameTest.php 프로젝트: h0ke/OftBot
 /**
  * @covers \OftBot\Game::roll
  * @covers \OftBot\Game::keep
  */
 public function testFullTurn()
 {
     $game = new Game('creating_player_name');
     $game->start();
     $player = $game->getCurrentPlayer();
     // First roll
     $game->roll();
     $roll = $player->getRoll();
     $this->assertCount(6, $roll);
     $game->keep(array($roll[0], $roll[1]));
     // Keep the first two die rolled
     $kept = $player->getKept();
     $this->assertCount(2, $kept);
     $this->assertFalse($player->turnIsComplete());
     $this->assertSame(null, $player->getScore());
     // Second roll
     $game->roll();
     $roll = $player->getRoll();
     $this->assertCount(4, $roll);
     $game->keep(array($roll[0]));
     // Keep the first die rolled
     $kept = $player->getKept();
     $this->assertCount(3, $kept);
     $this->assertFalse($player->turnIsComplete());
     $this->assertSame(null, $player->getScore());
     // third roll
     $game->roll();
     $roll = $player->getRoll();
     $this->assertCount(3, $roll);
     $game->keep(array($roll[0], $roll[1], $roll[2]));
     // Keep all 3 die rolled
     $kept = $player->getKept();
     $this->assertCount(6, $kept);
     $this->assertTrue($player->turnIsComplete());
     $this->assertNotSame(null, $player->getScore());
 }