예제 #1
0
 /**
  * Get ont highest-rank card which is situated by players
  *
  * @return Card
  */
 protected function getOneHighestCardPutted() : Card
 {
     $this->gameTable->checkEveryPlayersHasSituatedCards();
     $this->checkIsOneHighestCardSituated();
     $lastPuttedCardsByPlayers = new CardCollection();
     foreach ($this->getPlayers() as $player) {
         if ($this->gameTable->getPlayerCards($player)->count() > 0) {
             $lastPuttedCardsByPlayers->append($this->gameTable->getPlayerCards($player)->getLast());
         }
     }
     foreach (array_reverse(self::ORDER_OF_FIGURES) as $orderedFigure) {
         if ($lastPuttedCardsByPlayers->hasCardWithFigure($orderedFigure)) {
             foreach ($lastPuttedCardsByPlayers as $card) {
                 if ($card->getFigure() === $orderedFigure) {
                     return $card;
                 }
             }
         }
     }
 }
예제 #2
0
 public function testHasCardWithFigure()
 {
     $cardCollection = new CardCollection();
     foreach (FigureInterface::FIGURES as $figure) {
         $this->assertFalse($cardCollection->hasCardWithFigure($figure));
     }
     $addedCard = TestDataProvider::getCard2();
     $cardCollection->append($addedCard);
     foreach (FigureInterface::FIGURES as $figure) {
         if ($addedCard->getFigure() === $figure) {
             $this->assertTrue($cardCollection->hasCardWithFigure($figure));
         } else {
             $this->assertFalse($cardCollection->hasCardWithFigure($figure));
         }
     }
     $expectedException = CardException::incorrectFigure('notExistedFigure');
     $this->expectException(get_class($expectedException));
     $this->expectExceptionMessage($expectedException->getMessage());
     $cardCollection->hasCardWithFigure('notExistedFigure');
 }