/** * @test */ public function shouldSetScoreWhenIsExactly101() { //given $this->gameUser->updateAttributes(['score' => 99]); $hit = Hit::createFor('2s', $this->gameUser); //when $isScored = $hit->handleScore(); //then $this->gameUser->reload(); $this->assertTrue($isScored); $this->assertEquals(101, $this->gameUser->score); }
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 shouldCalculateIsNotShittyRound() { //given $user = User::create(['login' => 'A']); $game = Game::create(['type' => 'cricket']); $gameUser = GameUser::create(['game_id' => $game->id, 'user_id' => $user->getId()]); $game->updateAttributes(['current_game_user_id' => $gameUser->getId()]); Hit::createFor('15t', $gameUser); Hit::createFor('16t', $gameUser); Hit::createFor('17t', $gameUser); //when $isShittyRound = $gameUser->isShittyRound(); //then $this->assertFalse($isShittyRound); }
/** * @test */ public function shouldGetHitsOnlyForPlayersInCurrentGame() { //given $user = User::create(['login' => 'test', 'password' => 'a']); $game1 = Game::create(); $game1->addPlayer($user->getId()); /** @var GameUser $gameUser1 */ $gameUser1 = Arrays::first($game1->game_users); $game2 = Game::create(); $game2->addPlayer($user->getId()); /** @var GameUser $gameUser2 */ $gameUser2 = Arrays::first($game2->game_users); Hit::createFor('4d', $gameUser1); Hit::createFor('15t', $gameUser2); //when $hits = Hit::findForGame($game1); //then Assert::thatArray($hits)->onProperty('field')->containsExactly('4'); }
/** * @test * @dataProvider hits */ public function shouldReturnIsScoredIfFieldIsInRange($hit, $isScored) { //given $user = User::create(['login' => 'A']); $game = Game::create(['type' => 'cricket']); $gameUser = GameUser::create(['game_id' => $game->id, 'user_id' => $user->getId()]); $game->updateAttributes(['current_game_user_id' => $gameUser->getId()]); //when $hit = Hit::createFor($hit, $gameUser); //then $this->assertEquals($isScored, $hit->isScored()); }
/** * @test */ public function shouldReturnMostFrequentlyHitField() { //given $user = User::create(['login' => 'A']); $game = Game::create(['type' => 'cricket']); $gameUser = $game->addPlayer($user->getId()); Hit::createFor('15t', $gameUser); Hit::createFor('16s', $gameUser); Hit::createFor('16s', $gameUser); //when $field = $user->mostFrequentlyHitField(); //then $this->assertEquals('16', $field); }