Exemplo n.º 1
0
 protected function check()
 {
     $gameRepository = new GameRepository();
     $gameRepository->addAdditionalWhere(array('column' => 'room', 'value' => $this->room['id']));
     $gameRepository->addAdditionalWhere(array('column' => 'status', 'value' => array(Game::GAME_STATUS_CREATED, Game::GAME_STATUS_STARTED), 'xxx' => 'IN'));
     $count = $gameRepository->getCountAll();
     if ($count > 0) {
         $this->check = FALSE;
     } else {
         $this->check = TRUE;
     }
 }
Exemplo n.º 2
0
 protected function setup()
 {
     $loggedUser = LoggedUser::whoIsLogged();
     if (Utils::post('create_room') && $loggedUser['admin']) {
         $params = array('title' => Utils::post('title'), 'alias' => Utils::createAlias(Utils::post('title'), 'room'), 'description' => Utils::post('description'));
         $room = new Room($params);
         $room->save();
     }
     $roomRepository = new RoomRepository();
     $rooms = $roomRepository->getAll();
     $gameRepository = new GameRepository();
     $games = $gameRepository->getGamesByRooms(array_keys($rooms));
     foreach ($games as $game) {
         $rooms[$game['room']]['game'] = TRUE;
         $rooms[$game['room']]['status'] = Localize::getMessage('room_status_' . $game['status']);
     }
     MySmarty::assign('loggedUser', $loggedUser);
     MySmarty::assign('rooms', $rooms);
 }
Exemplo n.º 3
0
 public function main()
 {
     $gameId = intval(Utils::post('game'));
     $roomId = intval(Utils::post('room'));
     $gameRepository = new GameRepository();
     // $gameRepository->addAdditionalWhere(array('column' => 'status', 'value' => Game::GAME_STATUS_ENDED, 'xxx' => '!='));
     $gameRepository->addOrderBy(array('id' => 'DESC'));
     $game = $gameRepository->getOneByRoom($roomId);
     //		if ($gameId) {
     //			$game = $gameRepository->getOneById($gameId);
     //		} else {
     //
     //		}
     $roomRepository = new RoomRepository();
     $room = $roomRepository->getOneById($roomId);
     $gameBox = new GameBox();
     $gameBox->setRoom($room);
     if ($game) {
         $gameBox->setGame($game);
     }
     echo $gameBox->render();
 }
Exemplo n.º 4
0
<?php

require_once 'include.php';
$loggedUser = User::whoIsLogged();
if ($loggedUser === null) {
    Utils::redirect('login.php');
}
$actualUrl = Utils::getActualUrl();
$room = intval($_GET['id']);
if (!$room) {
    Utils::redirect('rooms.php');
}
Room::addUser($loggedUser['id'], $room);
$gameRepository = new GameRepository();
$game = $gameRepository->getOneByRoom($room);
if ($game) {
    $GLOBALS['smarty']->assign('game', $game);
}
if ($_POST && trim($_POST['message'])) {
    if (strpos($_POST['message'], '.') === 0) {
        $commandResult = Command::execute($_POST['message'], $game);
    } else {
        Chat::addMessage(trim($_POST['message']), $room);
    }
    Room::updateUserLastActivity($loggedUser['id'], $room);
    Utils::redirect($actualUrl);
}
$messages = Chat::getMessages($room, $loggedUser['id']);
$emoticons = Emoticons::getEmoticons();
$GLOBALS['smarty']->assign('loggedUser', $loggedUser);
$GLOBALS['smarty']->assign('room', $room);
Exemplo n.º 5
0
 public function main()
 {
     $gameId = intval(Utils::post('game'));
     $gameRepository = new GameRepository();
     $game = $gameRepository->getOneById($gameId);
     $commandParams = array();
     $commandParams['command'] = addslashes(Utils::post('command'));
     $commandParams['useCharacter'] = intval(Utils::post('useCharacter'));
     $commandParams['playCardId'] = intval(Utils::post('playCard'));
     if ($commandParams['playCardId']) {
         $cardRepository = new CardRepository(TRUE);
         $card = $cardRepository->getOneById($commandParams['playCardId']);
         $commandParams['playCardName'] = str_replace('-', '', $card->getItemAlias());
     }
     // TODO mozno ich niekedy bude viac
     $commandParams['additionalCardsId'] = intval(Utils::post('additionalCard'));
     if ($commandParams['additionalCardsId']) {
         $cardRepository = new CardRepository(TRUE);
         $card = $cardRepository->getOneById($commandParams['additionalCardsId']);
         $commandParams['additionalCardsName'] = str_replace('-', '', $card->getItemAlias());
     }
     $commandParams['enemyPlayerId'] = intval(Utils::post('player'));
     if ($commandParams['enemyPlayerId']) {
         $playerRepository = new PlayerRepository();
         $player = $playerRepository->getOneById($commandParams['enemyPlayerId']);
         if ($player) {
             $user = $player->getUser();
             if ($user) {
                 $commandParams['enemyPlayerUsername'] = $user['username'];
             }
         }
     }
     if ($commandParams['command'] == 'fanning') {
         $commandParams['additionalEnemyPlayerId'] = intval(Utils::post('additionalPlayer'));
         if ($commandParams['additionalEnemyPlayerId']) {
             $playerRepository = new PlayerRepository();
             $player = $playerRepository->getOneById($commandParams['additionalEnemyPlayerId']);
             if ($player) {
                 $user = $player->getUser();
                 if ($user) {
                     $commandParams['additionalEnemyPlayerUsername'] = $user['username'];
                 }
             }
         }
     }
     // TODO brawl tu dava addslashes
     if ($commandParams['command'] == 'brawl') {
         $commandParams['enemyCardsId'] = addslashes(Utils::post('card'));
     } elseif ($commandParams['command'] == 'choose_cards') {
         $commandParams['selectedCards'] = addslashes(Utils::post('card'));
     } else {
         $commandParams['enemyCardsId'] = intval(Utils::post('card'));
         if ($commandParams['enemyCardsId']) {
             $cardRepository = new CardRepository(TRUE);
             $card = $cardRepository->getOneById($commandParams['enemyCardsId']);
             $commandParams['enemyCardsName'] = str_replace('-', '', $card->getItemAlias());
         }
     }
     $commandParams['place'] = addslashes(Utils::post('place'));
     if (Utils::post('peyoteColor')) {
         $commandParams['peyoteColor'] = addslashes(Utils::post('peyoteColor'));
     }
     if (Utils::post('text')) {
         $commandParams['text'] = addslashes(Utils::post('text'));
     }
     $params = array();
     foreach ($commandParams as $key => $value) {
         $params[] = $key . '=' . $value;
     }
     $commandString = implode('&', $params);
     Log::command($commandString);
     Command::setup($commandString, $game);
 }
Exemplo n.º 6
0
 protected function setup()
 {
     $roomAlias = Utils::get('identifier');
     $roomRepository = new RoomRepository();
     $room = $roomRepository->getOneByAlias($roomAlias);
     $loggedUser = LoggedUser::whoIsLogged();
     if ($room) {
         $gameRepository = new GameRepository();
         // $gameRepository->addAdditionalWhere(array('column' => 'status', 'value' => Game::GAME_STATUS_ENDED, 'xxx' => '!='));
         $gameRepository->addOrderBy(array('id' => 'DESC'));
         $game = $gameRepository->getOneByRoom($room['id']);
         if (Utils::post()) {
             $message = addslashes(trim(Utils::post('message')));
             if ($message != '') {
                 if (strpos($message, '.') === 0) {
                     $response = Command::setup('command=' . substr($message, 1), $game);
                 } else {
                     $response = Command::setup('command=say&text=' . $message . '&room=' . $room['id'] . '&game=' . $game['id'], $game);
                 }
                 Room::updateUserLastActivity($loggedUser['id'], $room['id']);
             } elseif (Utils::post('create')) {
                 $response = Command::setup('command=create', $game);
             } elseif (Utils::post('join')) {
                 $response = Command::setup('command=join', $game);
             } elseif (Utils::post('add_ai_player')) {
                 $response = Command::setup('command=add_ai_player', $game);
             } elseif (Utils::post('start')) {
                 $response = Command::setup('command=init', $game);
             } elseif (Utils::post('choose_character')) {
                 $response = Command::setup('command=choose_character&selectedCharacter=' . Utils::post('character'), $game);
             } elseif (Utils::post('choose_cards')) {
                 $commandParams = array();
                 $commandParams['command'] = 'choose_cards';
                 $commandParams['selectedCards'] = array();
                 if (Utils::post('card')) {
                     $commandParams['selectedCards'] = implode(',', Utils::post('card'));
                 }
                 $params = array();
                 foreach ($commandParams as $key => $value) {
                     $params[] = $key . '=' . $value;
                 }
                 $commandString = implode('&', $params);
                 $response = Command::setup($commandString, $game);
             }
             Utils::redirect(Utils::getActualUrl(), FALSE);
             // TODO tu by sa mohol spravit redirect asi lebo respons bude v db
             MySmarty::assign('response', $response);
         }
         $gameBox = new GameBox();
         $gameBox->setRoom($room);
         if ($game !== NULL) {
             $gameBox->setGame($game);
         }
         MySmarty::assign('gameBox', $gameBox->render());
         $chatBox = new ChatBox();
         $chatBox->setRoom($room);
         if ($game !== NULL) {
             $chatBox->setGame($game);
         }
         MySmarty::assign('chatBox', $chatBox->render());
     } else {
         // TODO 404 room not found
     }
 }
Exemplo n.º 7
0
 protected function removePlayerFromGame()
 {
     $this->actualPlayer['actual_lifes'] = 0;
     $this->actualPlayer['position'] = 0;
     $this->actualPlayer['phase'] = 0;
     $this->actualPlayer = $this->actualPlayer->save(TRUE);
     // TODO message ze hrac zomrel
     // ak je v hre Vera Custer tak moze mat jeden z tychto charakterov
     // preto su vsetky premenne array a nie len Player
     $vultureSams = array();
     $gregDiggers = array();
     $herbHunters = array();
     foreach ($this->getPlayers() as $player) {
         // pozrieme sa na vsetkych hracov ktori este nie su mrtvi a ani nie su aktualny hrac (bohvie ako je on ulozeny v $this->players :)
         if ($player['actual_lifes'] > 0 && $this->actualPlayer['id'] != $player['id']) {
             // najprv pozrieme ci hrac nie je vera custer s charakterom zabiteho hraca, ak ano, vera uz nemoze mat jeho vlastnost
             if ($player->getIsVeraCuster($this->game)) {
                 $notices = $player->getNoticeList();
                 $actualPlayerCharacter = $this->actualPlayer->getCharacter();
                 if (isset($notices['selected_character']) && $notices['selected_character'] == $actualPlayerCharacter['id']) {
                     unset($notices['selected_character']);
                 }
                 $player->setNoticeList($notices);
                 $player->save();
             }
             if ($player->getIsVultureSam($this->game)) {
                 $vultureSams[] = $player;
             } elseif ($player->getIsGregDigger($this->game)) {
                 $gregDiggers[] = $player;
             } elseif ($player->getIsHerbHunter($this->game)) {
                 $herbHunters[] = $player;
             }
         }
     }
     // pridame vsetkym gregom diggerom 2 zivoty (resp. tolko kolko potrebuju)
     if ($gregDiggers) {
         foreach ($gregDiggers as $gregDigger) {
             $newLifes = min($gregDigger['actual_lifes'] + 2, $gregDigger['max_lifes']);
             $gregDigger['actual_lifes'] = $newLifes;
             $gregDigger->save();
         }
     }
     // potiahneme pre kazdeho herba huntera 2 karty
     if ($herbHunters) {
         foreach ($herbHunters as $herbHunter) {
             $drawnCards = GameUtils::drawCards($this->game, 2);
             $handCards = unserialize($herbHunter['hand_cards']);
             foreach ($drawnCards as $card) {
                 $handCards[] = $card;
             }
             $herbHunter['hand_cards'] = serialize($handCards);
             $herbHunter->save();
         }
     }
     if ($vultureSams) {
         if (count($vultureSams) == 1) {
             $vultureSamPlayer = $vultureSams[0];
             $retVal = GameUtils::moveCards($this->game, $this->actualPlayer->getHandCards(), $this->actualPlayer, 'hand', $vultureSamPlayer, 'hand');
             $vultureSamPlayer = $retVal['playerTo'];
             $this->actualPlayer = $retVal['playerFrom'];
             $retVal = GameUtils::moveCards($this->game, $this->actualPlayer->getTableCards(), $this->actualPlayer, 'hand', $vultureSamPlayer, 'table');
             $vultureSamPlayer = $retVal['playerTo'];
             $this->actualPlayer = $retVal['playerFrom'];
             $retVal = GameUtils::moveCards($this->game, $this->actualPlayer->getWaitCards(), $this->actualPlayer, 'hand', $vultureSamPlayer, 'wait');
             $vultureSamPlayer = $retVal['playerTo'];
             $this->actualPlayer = $retVal['playerFrom'];
         } else {
             throw new Exception("More than one Vulture Sam in a game", 1352146582);
         }
     } else {
         $retVal = GameUtils::throwCards($this->game, $this->actualPlayer, $this->actualPlayer->getHandCards(), 'hand');
         $this->game = $retVal['game'];
         $this->actualPlayer = $retVal['player'];
         $retVal = GameUtils::throwCards($this->game, $this->actualPlayer, $this->actualPlayer->getTableCards(), 'table');
         $this->game = $retVal['game'];
         $this->actualPlayer = $retVal['player'];
         $retVal = GameUtils::throwCards($this->game, $this->actualPlayer, $this->actualPlayer->getWaitCards(), 'wait');
         $this->game = $retVal['game'];
         $this->actualPlayer = $retVal['player'];
     }
     // znovunacitame game z databazy, lebo sa par veci zmenilo medzitym
     $gameRepository = new GameRepository();
     $this->game = $gameRepository->getOneById($this->game['id']);
     // TODO po zmene positions sa pravdepodobne zmeni aj pozicia hraca ktory
     // je na tahu, treba to tu na tomto mieste znovu preratat a nastavit game[position]
     // na poziciu hraca s ideckom ktore ma attacking player a rovnako aj inter_turn bude treba preratat
     $this->game = GameUtils::changePositions($this->game);
     $matrix = GameUtils::countMatrix($this->game);
     $this->game['distance_matrix'] = serialize($matrix);
     $this->game = $this->game->save(TRUE);
     // najst hraca ktory ma fazu != 0 a nastavit ho v hre ako hraca ktory je na tahu
     // znovu nacitame z databazy utociaceho hraca ( pre istotu )
     $attackingPlayerId = $this->interTurnReason['from'];
     $playerRepository = new PlayerRepository();
     $this->attackingPlayer = $playerRepository->getOneById($attackingPlayerId);
     $playerRepository = new PlayerRepository();
     $role = $this->actualPlayer->getRoleObject();
     if ($role['type'] == Role::BANDIT) {
         if ($playerRepository->getCountLivePlayersWithRoles($this->game['id'], array(Role::ROLE_BANDIT_1, Role::ROLE_BANDIT_2, Role::ROLE_BANDIT_3, Role::ROLE_RENEGARD_1, Role::ROLE_RENEGARD_2)) == 0) {
             $this->endGame(array(Role::ROLE_SHERIFF, Role::ROLE_VICE_1, Role::ROLE_VICE_2));
         } else {
             // TODO doplnit pocty kariet ak su ine pre rozne charaktery utociacich hracov
             // TODO doplnit podmienky pre typy utokov ktorych sa tieto tahania tykaju - indiani tam myslim nepatria
             // TODO message o tom ze si tento hrac potiahol 3 karty za banditu
             // za banditu dostane utocnik 3 karty - ale len ak slo o priamy utok
             if ($this->attackingPlayer) {
                 $drawnCards = GameUtils::drawCards($this->game, 3);
                 $handCards = unserialize($this->attackingPlayer['hand_cards']);
                 foreach ($drawnCards as $card) {
                     $handCards[] = $card;
                 }
                 $this->attackingPlayer['hand_cards'] = serialize($handCards);
                 $this->attackingPlayer = $this->attackingPlayer->save(TRUE);
             }
         }
     } elseif ($role['type'] == Role::SHERIFF) {
         if ($playerRepository->getCountLivePlayersWithRoles($this->game['id']) == 1) {
             if ($playerRepository->getCountLivePlayersWithRoles($this->game['id'], array(Role::ROLE_RENEGARD_1)) == 1) {
                 $this->endGame(array(Role::ROLE_RENEGARD_1));
             } elseif ($playerRepository->getCountLivePlayersWithRoles($this->game['id'], array(Role::ROLE_RENEGARD_1)) == 1) {
                 $this->endGame(array(Role::ROLE_RENEGARD_2));
             } else {
                 $this->endGame(array(Role::ROLE_BANDIT_1, Role::ROLE_BANDIT_2, Role::ROLE_BANDIT_3));
             }
         } else {
             $this->endGame(array(Role::ROLE_BANDIT_1, Role::ROLE_BANDIT_2, Role::ROLE_BANDIT_3));
         }
     } elseif ($role['type'] == Role::RENEGARD) {
         if ($playerRepository->getCountLivePlayersWithRoles($this->game['id'], array(Role::ROLE_BANDIT_1, Role::ROLE_BANDIT_2, Role::ROLE_BANDIT_3, Role::ROLE_RENEGARD_1, Role::ROLE_RENEGARD_2)) == 0) {
             $this->endGame(array(Role::ROLE_SHERIFF, Role::ROLE_VICE_1, Role::ROLE_VICE_2));
         }
     } elseif ($role['type'] == Role::VICE) {
         if ($this->attackingPlayer) {
             $attackingRole = $this->attackingPlayer->getRoleObject();
             if ($attackingRole['type'] == Role::SHERIFF) {
                 $retVal = GameUtils::throwCards($this->game, $this->attackingPlayer, $this->attackingPlayer->getHandCards(), 'hand');
                 $this->game = $retVal['game'];
                 $this->attackingPlayer = $retVal['player'];
                 $retVal = GameUtils::throwCards($this->game, $this->attackingPlayer, $this->attackingPlayer->getTableCards(), 'table');
                 $this->game = $retVal['game'];
                 $this->attackingPlayer = $retVal['player'];
                 $retVal = GameUtils::throwCards($this->game, $this->attackingPlayer, $this->attackingPlayer->getWaitCards(), 'wait');
                 $this->game = $retVal['game'];
                 $this->attackingPlayer = $retVal['player'];
                 // 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();
             }
         }
     }
 }