protected function doKeep(array $kept) { $channel = $this->event->getRequest()->getSource(); $this->current_game->keep($kept); if (!$this->current_game->getCurrentPlayer()->turnIsComplete()) { $this->doRoll(); return; } $message = '@' . $this->current_game->getCurrentPlayer()->getName() . ', that was your last roll. '; if ($this->current_game->getCurrentPlayer()->getScore() > 0) { $message .= 'Your final score was ' . $this->current_game->getCurrentPlayer()->getScore() . '.'; } else { $message .= 'You did not qualify.'; } $this->event->addResponse(Response::notice($channel, $message)); if (!$this->current_game->currentPlayerIsLastPlayer()) { $this->current_game->setCurrentPlayerToNextPlayer(); $this->event->addResponse(Response::notice($channel, '@' . $this->current_game->getCurrentPlayer()->getName() . ', it\'s your turn next. Type \'@oftbot roll\' to take your first roll.')); } else { $this->finishGame(); } }
/** * @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()); }