public function test_it_sets_player_game_marks_and_creates_and_returns_new_game()
 {
     $startingPlayer = $this->createMockPlayer();
     $opposingPlayer = $this->createMockPlayer();
     $startingPlayer->shouldReceive("setGameMark")->with(GameFactory::PLAYER_MARK_1);
     $opposingPlayer->shouldReceive("setGameMark")->with(GameFactory::PLAYER_MARK_2);
     $game = $this->factory->create($startingPlayer, $opposingPlayer);
     $this->assertInstanceOf(Game::class, $game);
 }
 public function test_player_with_computer_strategy_never_loses_if_other_strategy_player_starts_game()
 {
     $computerStrategy = new ComputerStrategy($this->ioService);
     $otherStrategy = new RandomStrategy();
     $player1 = new Player("Alice", $computerStrategy);
     $player2 = new Player("Bob", $otherStrategy);
     $game = $this->gameFactory->create($player2, $player1);
     $winningPlayer = $this->gameService->run($game);
     $this->assertTrue(null === $winningPlayer || $player1 == $winningPlayer);
 }
Esempio n. 3
0
 public function play()
 {
     $this->showIntro();
     $firstGame = true;
     do {
         if ($firstGame || $this->setupNewPlayers()) {
             list($player1, $player2) = $this->createPlayers();
         }
         $startingPlayer = $this->chooseStartingPlayer($player1, $player2);
         $opposingPlayer = $player1 != $startingPlayer ? $player1 : $player2;
         $game = $this->gameFactory->create($startingPlayer, $opposingPlayer);
         $winner = $this->run($game);
         $this->showBoard($game);
         $this->showResult($winner);
         $firstGame = false;
     } while ($this->continuePlaying());
     $this->showEnding();
 }