protected function run() { if ($this->check == self::OK) { $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer); foreach ($this->players as $player) { if ($player->getIsAlive()) { if ($player['id'] == $this->actualPlayer['id']) { $this->actualPlayer['phase'] = Player::PHASE_WAITING; if ($this->actualPlayer->getIsBelleStar($this->game)) { $notices = $this->actualPlayer->getNoticeList(); $notices['character_used'] = 1; $this->actualPlayer->setNoticeList($notices); } $this->actualPlayer->save(); } else { if ($player['id'] == $nextPositionPlayer['id']) { $player['phase'] = Player::PHASE_UNDER_ATTACK; } MySmarty::assign('card', $this->cards[0]); $response = MySmarty::fetch($this->template); $player['command_response'] = $response; $player->save(); } } } $this->game['inter_turn_reason'] = serialize(array('action' => 'gatling', 'from' => $this->actualPlayer['id'], 'to' => $nextPositionPlayer['id'])); $this->game['inter_turn'] = $nextPositionPlayer['id']; $this->game->save(); GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards); } }
protected function run() { if ($this->check == self::OK) { if ($this->params['playCardName'] == 'jail') { // TODO tieto karty treba najprv ukazat hracom cez log a aby sa dali vyhodit, musia byt najprv v ruke aktualneho hraca a potom ich vyhodi $count = 1; if ($this->actualPlayer->getIsLuckyDuke($this->game)) { $count = 2; } $drawnCards = GameUtils::drawCards($this->game, $count); // TODO pocet zavisi aj od charakteru $isHeart = FALSE; $cardRepository = new CardRepository(); $thrownCards = array(); foreach ($drawnCards as $drawnCardId) { $drawnCard = $cardRepository->getOneById($drawnCardId); $thrownCards[] = $drawnCard; if ($drawnCard->getIsHearts($this->game)) { $isHeart = TRUE; // break tu nie je lebo musime prejst cez vsetky karty // aby sme vyrobili pole kariet ktore treba vyhodit } } $this->moveDrawnCards($thrownCards); if ($isHeart) { $this->drawResult = self::OK; $this->actualPlayer['phase'] = Player::PHASE_DRAW; $this->actualPlayer->save(); GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards, 'table'); } else { $this->drawResult = self::KO; $this->actualPlayer['phase'] = Player::PHASE_NONE; $this->actualPlayer->save(); GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards, 'table'); $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer); $this->game['turn'] = $nextPositionPlayer['id']; $this->game->save(); $nextPositionPlayer['phase'] = $this->getNextPhase($nextPositionPlayer); $nextPositionPlayer->save(); } } elseif ($this->params['playCardName'] == 'dynamite') { $count = 1; if ($this->actualPlayer->getIsLuckyDuke($this->game)) { $count = 2; } $drawnCards = GameUtils::drawCards($this->game, $count); $isSafe = FALSE; $cardRepository = new CardRepository(); $thrownCards = array(); foreach ($drawnCards as $drawnCardId) { $drawnCard = $cardRepository->getOneById($drawnCardId); $thrownCards[] = $drawnCard; if (!$drawnCard->getIsSpades($this->game) || in_array($drawnCard['value'], array('10', 'J', 'Q', 'K', 'A'))) { $isSafe = TRUE; // break tu nie je lebo musime prejst cez vsetky karty // aby sme vyrobili pole kariet ktore treba vyhodit } } $dynamite = $this->actualPlayer->getHasDynamiteOnTheTable($this->game); if ($isSafe === TRUE) { $this->moveDrawnCards($thrownCards); $this->drawResult = self::OK; // posunieme dynamit dalsiemu hracovi $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer); if ($nextPositionPlayer->getHasDynamiteOnTheTable($this->game)) { // ak dalsi hrac uz ma na stole dynamit, musim sa pozriet na hraca za nim $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $nextPositionPlayer); } if ($nextPositionPlayer['id'] != $this->actualPlayer['id']) { // v pripade dvoch hracov a dvoch dynamitov sa dynamity neposuvaju $retVal = GameUtils::moveCards($this->game, array($dynamite), $this->actualPlayer, 'table', $nextPositionPlayer, 'table'); $this->actualPlayer = $retVal['playerFrom']; } $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer); $this->actualPlayer = $this->actualPlayer->save(TRUE); } else { $this->drawResult = self::KO; // zahodime dynamit $retVal = GameUtils::throwCards($this->game, $this->actualPlayer, array($dynamite), 'table'); $this->actualPlayer = $retVal['player']; $this->game = $retVal['game']; // stiahneme hracovi tri zivoty $newLifes = $this->actualPlayer['actual_lifes'] - 3; $this->actualPlayer['actual_lifes'] = $newLifes; $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer); $this->actualPlayer = $this->actualPlayer->save(TRUE); $this->moveDrawnCards($thrownCards); if ($newLifes <= 0) { // TODO check ci nema na ruke pivo / piva a ak ano automaticky ich pouzit na zachranu // aspon dokym nebude na 1 zivote // nezabudnut na tequilla joe $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer); $this->game['turn'] = $nextPositionPlayer['id']; $this->game->save(); $nextPositionPlayer['phase'] = $this->getNextPhase($nextPositionPlayer); $nextPositionPlayer->save(); $this->removePlayerFromGame(); } } } elseif ($this->params['playCardName'] == 'rattlesnake') { $count = 1; if ($this->actualPlayer->getIsLuckyDuke($this->game)) { $count = 2; } $drawnCards = GameUtils::drawCards($this->game, $count); $isSafe = FALSE; $cardRepository = new CardRepository(); $thrownCards = array(); foreach ($drawnCards as $drawnCardId) { $drawnCard = $cardRepository->getOneById($drawnCardId); $thrownCards[] = $drawnCard; if (!$drawnCard->getIsSpades($this->game)) { $isSafe = TRUE; // break tu nie je lebo musime prejst cez vsetky karty // aby sme vyrobili pole kariet ktore treba vyhodit } } if ($isSafe === TRUE) { $this->moveDrawnCards($thrownCards); $this->drawResult = self::OK; $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer, TRUE); $this->actualPlayer = $this->actualPlayer->save(TRUE); } else { $this->drawResult = self::KO; // stiahneme hracovi jeden zivot $newLifes = $this->actualPlayer['actual_lifes'] - 1; $this->actualPlayer['actual_lifes'] = $newLifes; $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer, TRUE); $this->actualPlayer = $this->actualPlayer->save(TRUE); $this->moveDrawnCards($thrownCards); if ($newLifes <= 0) { // TODO check ci nema na ruke pivo / piva a ak ano automaticky ich pouzit na zachranu // aspon dokym nebude na 1 zivote // nezabudnut na tequilla joe $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer); $this->game['turn'] = $nextPositionPlayer['id']; $this->game->save(); $nextPositionPlayer['phase'] = $this->getNextPhase($nextPositionPlayer); $nextPositionPlayer->save(); $this->removePlayerFromGame(); } } } elseif ($this->params['playCardName'] == 'barrel') { $count = 1; if ($this->actualPlayer->getIsLuckyDuke($this->game)) { $count = 2; } $drawnCards = GameUtils::drawCards($this->game, $count); $isHeart = FALSE; $cardRepository = new CardRepository(); $thrownCards = array(); foreach ($drawnCards as $drawnCardId) { $drawnCard = $cardRepository->getOneById($drawnCardId); $thrownCards[] = $drawnCard; if ($drawnCard->getIsHearts($this->game)) { $isHeart = TRUE; // break tu nie je lebo musime prejst cez vsetky karty // aby sme vyrobili pole kariet ktore treba vyhodit } } $notices = $this->actualPlayer->getNoticeList(); if ($this->drawType == 'barrel') { $notices['barrel_used'] = 1; } elseif ($this->drawType == 'character') { $notices['character_jourdonnais_used'] = 1; } $this->actualPlayer->setNoticeList($notices); $this->actualPlayer = $this->actualPlayer->save(TRUE); if ($isHeart) { $this->drawResult = self::OK; $this->changeInterturn(); } else { $this->drawResult = self::KO; } $this->moveDrawnCards($thrownCards); } else { if ($this->useCharacter === TRUE && $this->actualPlayer->getIsVeraCuster($this->game)) { $notices = $this->actualPlayer->getNoticeList(); $selectedCharacter = $this->enemyPlayer->getCharacter(); $notices['selected_character'] = $selectedCharacter['id']; $this->actualPlayer->setNoticeList($notices); $this->actualPlayer = $this->actualPlayer->save(TRUE); // kedze je mozne ze si vyberieme nejaky charakter, ktory ovplyvnuje vzdialenost, preratame maticu $matrix = GameUtils::countMatrix($this->game); $this->game['distance_matrix'] = serialize($matrix); $this->game = $this->game->save(TRUE); } $counts = $this->getCountCards(); if ($this->actualPlayer->getIsYoulGrinner($this->game)) { $youlHandCardsCount = count($this->actualPlayer->getHandCards()); foreach ($this->getPlayers() as $player) { if ($player->getIsAlive() && $player['id'] != $this->actualPlayer['id']) { $playersHandCardsCount = count($player->getHandCards()); if ($playersHandCardsCount > $youlHandCardsCount) { $movedCard = $player->getCardWithId(); GameUtils::moveCards($this->game, array($movedCard), $player, 'hand', $this->actualPlayer, 'hand'); } } } } elseif ($this->useCharacter === TRUE) { if ($this->actualPlayer->getIsJesseJones($this->game)) { $retVal = GameUtils::moveCards($this->game, $this->enemyPlayersCards[$this->enemyPlayer['id']], $this->enemyPlayer, 'hand', $this->actualPlayer, $this->place); $this->actualPlayer = $retVal['playerTo']; $this->game = $retVal['game']; } elseif ($this->actualPlayer->getIsPatBrennan($this->game)) { $retVal = GameUtils::moveCards($this->game, $this->enemyPlayersCards[$this->enemyPlayer['id']], $this->enemyPlayer, 'hand', $this->actualPlayer, $this->place); $this->actualPlayer = $retVal['playerTo']; $this->game = $retVal['game']; // kedze je mozne ze rusime nejaku modru kartu ktora ovplyvnuje vzdialenost, preratame maticu // ak to bude velmi pomale, budeme to robit len ak je medzi zrusenymi kartami fakt takato karta $matrix = GameUtils::countMatrix($this->game); $this->game['distance_matrix'] = serialize($matrix); $this->game->save(); } elseif ($this->actualPlayer->getIsPedroRamirez($this->game)) { $throwPile = unserialize($this->game['throw_pile']); $card = array_pop($throwPile); $this->game['throw_pile'] = serialize($throwPile); $handCards = unserialize($this->actualPlayer['hand_cards']); $handCards[] = $card; $this->actualPlayer['hand_cards'] = serialize($handCards); } elseif ($this->actualPlayer->getIsEvelynTheBang($this->game)) { MySmarty::assign('card', NULL); // TODO select random bang card or evelyn character card $response = MySmarty::fetch('you-are-attacked.tpl'); $this->enemyPlayer['phase'] = Player::PHASE_UNDER_ATTACK; $this->enemyPlayer['command_response'] = $response; $this->enemyPlayer->save(); $this->game['inter_turn'] = $this->enemyPlayer['id']; $this->game['inter_turn_reason'] = serialize(array('action' => 'bang', 'from' => $this->actualPlayer['id'], 'to' => $this->enemyPlayer['id'])); $this->game->save(); } } $drawnCards = GameUtils::drawCards($this->game, $counts['draw']); // len hrac ktory musi vratit kartu nazad bude vyberat karty if ($counts['rest_action'] == 'back_to_deck') { $possibleChoices = array('drawn_cards' => $drawnCards, 'possible_pick_count' => $counts['pick'], 'rest_action' => $counts['rest_action']); $this->actualPlayer['possible_choices'] = serialize($possibleChoices); } else { // ostatnym sa rovno pridaju do ruky $handCards = unserialize($this->actualPlayer['hand_cards']); foreach ($drawnCards as $drawnCard) { $handCards[] = $drawnCard; } $this->actualPlayer['hand_cards'] = serialize($handCards); } if ($this->useCharacter === TRUE && $this->actualPlayer->getIsEvelynTheBang($this->game)) { $this->actualPlayer['phase'] = Player::PHASE_WAITING; } else { $this->actualPlayer['phase'] = Player::PHASE_PLAY; } $this->actualPlayer->save(); } } elseif ($this->check == self::PEYOTE_OK) { $color = $this->params['peyoteColor']; $method = 'getIs' . ucfirst($color); $drawnCards = GameUtils::drawCards($this->game, 1); // TODO messages, ukazat kartu ktora bola potiahnuta $cardRepository = new CardRepository(TRUE); $drawnCardId = $drawnCards[0]; $drawnCard = $cardRepository->getOneById($drawnCardId); if ($drawnCard->{$method}($this->game)) { $handCards = unserialize($this->actualPlayer['hand_cards']); $handCards[] = $drawnCardId; $this->actualPlayer['hand_cards'] = serialize($handCards); } else { GameUtils::throwCards($this->game, NULL, array($drawnCard)); $this->actualPlayer['phase'] = Player::PHASE_PLAY; } $this->actualPlayer->save(); } }
protected function getNextPositionPlayer($game, $actualPlayer) { $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($game, $actualPlayer); if ($nextPositionPlayer['id'] == $this->attackingPlayer['id']) { return $nextPositionPlayer; } else { if ($nextPositionPlayer->getIsApacheKid($this->game)) { $isDiamonds = FALSE; foreach ($this->attackingCards as $attackingCard) { if ($attackingCard->getIsDiamonds($this->game)) { $isDiamonds = TRUE; break; } } if ($isDiamonds) { $nextPositionPlayer = $this->getNextPositionPlayer($game, $nextPositionPlayer); } } return $nextPositionPlayer; } }
protected function run() { if ($this->check == self::OK) { $possibleChoices = unserialize($this->actualPlayer['possible_choices']); $possibleCards = $possibleChoices['drawn_cards']; $restAction = $possibleChoices['rest_action']; $handCards = unserialize($this->actualPlayer['hand_cards']); $drawPile = unserialize($this->game['draw_pile']); $throwPile = unserialize($this->game['throw_pile']); $nextPlayerPossibleCards = array(); foreach ($possibleCards as $possibleCard) { if (in_array($possibleCard, $this->params['selectedCards'])) { $handCards[] = $possibleCard; } else { if ($restAction == 'back_to_deck') { $drawPile[] = $possibleCard; } elseif ($restAction == 'general_store') { $nextPlayerPossibleCards[] = $possibleCard; } elseif ($restAction == 'throw') { $throwPile[] = $possibleCard; } } } if ($this->interTurnReason['action'] == 'general_store') { $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer); if ($nextPositionPlayer['id'] == $this->attackingPlayer['id']) { $this->game['inter_turn_reason'] = ''; $this->game['inter_turn'] = 0; $this->attackingPlayer['phase'] = Player::PHASE_PLAY; $this->attackingPlayer->save(); } else { if ($this->actualPlayer['id'] == $this->attackingPlayer['id']) { $this->actualPlayer['phase'] = Player::PHASE_WAITING; } else { $this->actualPlayer['phase'] = Player::PHASE_NONE; } $this->game['inter_turn'] = $nextPositionPlayer['id']; $cardRepository = new CardRepository(); $possibleCards = array(); foreach ($nextPlayerPossibleCards as $cardId) { $possibleCards[] = $cardRepository->getOneById($cardId); } MySmarty::assign('possiblePickCount', 1); MySmarty::assign('possibleCards', $possibleCards); MySmarty::assign('possibleCardsCount', count($possibleCards)); MySmarty::assign('game', $this->game); $response = MySmarty::fetch($this->template); $playerPossibleChoices = array('drawn_cards' => $nextPlayerPossibleCards, 'possible_pick_count' => 1, 'rest_action' => 'general_store'); $nextPositionPlayer['phase'] = Player::PHASE_UNDER_ATTACK; $nextPositionPlayer['possible_choices'] = serialize($playerPossibleChoices); $nextPositionPlayer['command_response'] = $response; $nextPositionPlayer->save(); } } else { $this->actualPlayer['phase'] = Player::PHASE_PLAY; } $this->actualPlayer['hand_cards'] = serialize($handCards); $this->actualPlayer['command_response'] = ''; $this->actualPlayer['possible_choices'] = ''; $this->actualPlayer = $this->actualPlayer->save(TRUE); $this->game['draw_pile'] = serialize($drawPile); $this->game['throw_pile'] = serialize($throwPile); $this->game = $this->game->save(TRUE); } }
protected function run() { if ($this->check == self::OK) { $passTurn = TRUE; if ($this->game->getIsHNVendetta() && !$this->actualPlayer->getPlayedVendetta()) { // TODO mozno by toto mohla byt metoda $count = 1; // neviem ci lucky duke pri vendete taha dve karty if ($this->actualPlayer->getIsLuckyDuke($this->game)) { $count = 2; } $drawnCards = GameUtils::drawCards($this->game, $count); $isHeart = FALSE; $cardRepository = new CardRepository(); $thrownCards = array(); foreach ($drawnCards as $drawnCardId) { $drawnCard = $cardRepository->getOneById($drawnCardId); $thrownCards[] = $drawnCard; if ($drawnCard->getIsHearts($this->game)) { $isHeart = TRUE; // break tu nie je lebo musime prejst cez vsetky karty // aby sme vyrobili pole kariet ktore treba vyhodit } } GameUtils::throwCards($this->game, NULL, $thrownCards); if ($isHeart) { $passTurn = FALSE; } } if ($passTurn) { $this->actualPlayer['phase'] = Player::PHASE_NONE; $this->actualPlayer['bang_used'] = 0; $tableCards = unserialize($this->actualPlayer['table_cards']); $waitCards = unserialize($this->actualPlayer['wait_cards']); $this->actualPlayer['table_cards'] = serialize(array_merge($tableCards, $waitCards)); $this->actualPlayer['wait_cards'] = serialize(array()); // znulujeme notices $notices = $this->actualPlayer->getNoticeList(); if (isset($notices['barrel_used'])) { unset($notices['barrel_used']); } if (isset($notices['character_jourdonnais_used'])) { unset($notices['character_jourdonnais_used']); } if (isset($notices['character_used'])) { unset($notices['character_used']); } // spravime zalohu premennej ghost $isGhost = $this->actualPlayer->getIsGhost(); // zrusime ghosta if (isset($notices['ghost'])) { unset($notices['ghost']); } if (isset($notices['vendetta'])) { unset($notices['vendetta']); } if (isset($notices['blood_brothers'])) { unset($notices['blood_brothers']); } $this->actualPlayer->setNoticeList($notices); $this->actualPlayer = $this->actualPlayer->save(TRUE); if ($this->game->getIsHNGhostTown() && $isGhost === TRUE) { // odstranime ghosta $this->removePlayerFromGame(); } $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer, TRUE); $this->game['turn'] = $nextPositionPlayer['id']; $this->game->save(); if ($this->game->getIsHNGhostTown() && $nextPositionPlayer['actual_lifes'] == 0) { $notices = $nextPositionPlayer->getNoticeList(); $notices['ghost'] = 1; $nextPositionPlayer->setNoticeList($notices); } $nextPositionPlayer['phase'] = $this->getNextPhase($nextPositionPlayer); $nextPositionPlayer->save(); // preratame maticu $matrix = GameUtils::countMatrix($this->game); $this->game['distance_matrix'] = serialize($matrix); $this->game->save(); } else { $notices = $this->actualPlayer->getNoticeList(); $notices['vendetta'] = 1; $this->actualPlayer->setNoticeList($notices); $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer); $this->actualPlayer = $this->actualPlayer->save(TRUE); // TODO message } } }