Exemplo n.º 1
0
 protected function initGame($game)
 {
     $roomAlias = Utils::get('identifier');
     $roomRepository = new RoomRepository();
     $room = $roomRepository->getOneByAlias($roomAlias);
     self::$room = $room['id'];
     self::$loggedUser = LoggedUser::whoIsLogged();
     if ($game && self::$loggedUser) {
         self::$game = $game;
         foreach ($game['players'] as $player) {
             if (self::$loggedUser['id'] == $player['user']['id']) {
                 self::$player = $player;
                 break;
             }
         }
     }
 }
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
 public function getRoomObject()
 {
     $roomRepository = new RoomRepository();
     $room = $roomRepository->getOneById($this['room']);
     return $room;
 }
Exemplo n.º 5
0
<?php

require_once 'include.php';
$loggedUser = User::whoIsLogged();
if ($loggedUser === null) {
    Utils::redirect('login.php');
}
if ($_POST['create_room'] && $loggedUser['admin']) {
    $room = Room::addRoom(addslashes($_POST['title']), addslashes($_POST['description']));
    Utils::redirect('room.php?id=' . $room);
}
$roomRepository = new RoomRepository();
$rooms = $roomRepository->getAll();
$GLOBALS['smarty']->assign('loggedUser', $loggedUser);
$GLOBALS['smarty']->assign('rooms', $rooms);
$GLOBALS['smarty']->assign('content', $GLOBALS['smarty']->fetch('rooms.tpl'));
echo $GLOBALS['smarty']->fetch('content.tpl');
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
 private function __construct($params, $localizedParams, $game)
 {
     $this->params = $params;
     $this->game = $game;
     $this->localizedParams = $localizedParams;
     $this->interTurnReason = unserialize($this->game['inter_turn_reason']);
     $attackingPlayerId = $this->interTurnReason['from'];
     $playerRepository = new PlayerRepository();
     $this->attackingPlayer = $playerRepository->getOneById($attackingPlayerId);
     $cardRepository = new CardRepository();
     $this->attackingCards = $cardRepository->getById($this->interTurnReason['cards']);
     $roomRepository = new RoomRepository();
     if ($game) {
         $room = $roomRepository->getOneById($game['room']);
     } else {
         $roomAlias = Utils::get('identifier');
         $room = $roomRepository->getOneByAlias($roomAlias);
     }
     $this->room = $room;
     if ($this->game) {
         $this->players = $this->game->getAdditionalField('players');
         $attackedPlayer = $this->params['enemyPlayerUsername'];
         foreach ($this->players as $player) {
             $user = $player->getUser();
             if ($user['username'] == $attackedPlayer) {
                 $this->attackedPlayer = $player;
                 break;
             }
         }
     }
 }