Exemple #1
0
 /**
  * Increase winner count in line
  *
  * @param WinCount $winCount
  *
  * @return bool
  */
 protected function mergeWinCount(WinCount $winCount)
 {
     if ($winCount->getWinner() === null) {
         return false;
     }
     if ($this->winCounts[$winCount->getWinner()] > $winCount->getWinnerCount()) {
         return false;
     }
     $this->winCounts[$winCount->getWinner()] = $winCount->getWinnerCount();
     return true;
 }
Exemple #2
0
 /**
  * Check for we have winner
  *
  * @param WinCount $winCount
  * @param $positions
  *
  * @return bool
  */
 private function checkWinner(WinCount $winCount, $positions)
 {
     if ($winCount->getWinner() === null) {
         return false;
     }
     if ($winCount->getWinnerCount() == $this->winCount) {
         $winner = $winCount->getWinner();
         // Check sequence for "at a stretch"
         $count = 0;
         foreach ($positions as $value) {
             /** @var \Ticki\Core\Model\Cell $current */
             $current = $this->kitCells[$value];
             if ($current === null) {
                 $count = 0;
                 continue;
             }
             if ($current->getType() === $winner) {
                 $count++;
             } else {
                 $count = 0;
             }
             if ($this->winCount == $count) {
                 $this->winnerType = $winner;
                 return true;
             }
         }
         return false;
     }
     return false;
 }