public function index() { $game = Game::currentGame(); if ($game && $game->isStarted()) { $this->redirect(gameGamesPath()); } else { $this->view->render(); } }
public function index() { $field = $this->params['field']; $game = Game::currentGame(); $currentGameUser = $game->current_game_user; $leftShoots = $currentGameUser->getLeftShoots(); if ($leftShoots) { $hit = Hit::createFor($field, $currentGameUser); $params = Json::encode(['game' => $game->type, 'field' => $hit->field, 'multiplier' => $hit->multiplier, 'scored' => $hit->handleScore(), 'winner' => $currentGameUser->isWinner(), 'shots_left' => $leftShoots - 1, 'shitty_round' => $currentGameUser->isShittyRound()]); Event::create(['name' => 'hit', 'params' => $params]); } else { Event::create(['name' => 'next_player', 'params' => '']); } }
/** * @test */ public function shouldSetGameEndedByCurrentUser() { //given /** @var User $user1 */ $user1 = User::create(['login' => 'A']); /** @var User $user2 */ $user2 = User::create(['login' => 'B']); /** @var Game $game */ $game = Game::create(); $game->addPlayer($user1->getId()); $game->addPlayer($user2->getId()); $currentGame = Game::currentGame(); $currentGame->nextPlayer(); //when $currentGame->endedByCurrentGameUser(); //then $game->reload(); $this->assertTrue($game->finished); $this->assertEquals($user2->getId(), $game->winner_game_user->user_id); }
public function end_game() { $this->layout->setLayout('ajax_layout'); $game = Game::currentGame(); $game->endedByCurrentGameUser(); $this->view->game = $game; $this->view->render(); }