Exemplo n.º 1
0
 /**
  * Handle the event.
  *
  * @param  PlayerWonSet  $event
  * @return void
  */
 public function handle(PlayerWonSet $event)
 {
     $match = Match::find($event->player->match->id);
     $player = Player::find($event->player->id);
     $player->sets_won += 1;
     $player->save();
 }
Exemplo n.º 2
0
 function test_new_set()
 {
     $this->dummyData();
     $response = $this->call('GET', '/match/startnewset');
     $this->assertEquals(200, $response->status());
     $this->assertEquals(2, Match::find($this->match->id)->currentSet());
 }
Exemplo n.º 3
0
 public function test_player1_wins_match()
 {
     $player1 = new Player(['points' => 10, 'sets_won' => 1]);
     $player2 = new Player(['points' => 9, 'sets_won' => 1]);
     $match = Match::create();
     $match->players()->saveMany([$player1, $player2]);
     $match->addPointFor($player1);
     $this->assertEquals($player1->id, Match::find($match->id)->won_by);
     $this->assertEquals(2, Player::find($player1->id)->sets_won);
 }
 function test_it_works()
 {
     $player = new Player(['nickname' => 'Stefan', 'points' => 10]);
     $opponent = new Player(['nickname' => 'Fredrik', 'points' => 9]);
     $match = Match::create(['set' => 2]);
     $match->players()->saveMany([$player, $opponent]);
     Event::fire(new App\Events\PlayerWonSet($player));
     $this->assertEquals(2, Match::find($match->id)->currentSet());
     $this->assertEquals(1, Player::find($player->id)->sets_won);
 }
Exemplo n.º 5
0
 function test_it_works()
 {
     $player = new Player(['nickname' => 'Stefan', 'points' => 11]);
     $opponent = new Player(['nickname' => 'Fredrik', 'points' => 9]);
     $match = Match::create();
     $match->players()->saveMany([$player, $opponent]);
     $this->assertEquals(1, $match->currentSet());
     Event::fire(new App\Events\StartNewSet($match));
     $expected = (object) array('Stefan' => 0, 'Fredrik' => 0);
     $this->assertEquals(2, Match::find($match->id)->currentSet());
     $this->assertEquals($expected, Match::find($match->id)->getScore());
 }
Exemplo n.º 6
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $user = \Auth::user();
     $match = Match::find(\Request::input('match'));
     $sheet = $user->getPrimarySheet();
     return \Response::json(['message' => 'You have already be ton this match!'], 422);
     // Status code here
     $this->validate($request, ['match' => 'required', 'team' => 'required', 'amount' => 'required|numeric|between:0,' . $sheet->amount]);
     $bet = new Bet();
     $bet->match_id = \Request::input('match');
     $bet->amount = \Request::input('amount');
     $bet->user()->associate($user);
     $bet->match()->associate($match);
     $bet->sheet()->associate($sheet);
     $bet->save();
     $sheet->amount = $sheet->amount - \Request::input('amount');
     $sheet->save();
     /*return \Auth::check() ? 'authenticated': "NO biiish!";*/
     /*return \Response::json($bet);*/
 }
Exemplo n.º 7
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroyMatch(Request $request)
 {
     $league_id = Input::get('league_id');
     $match_id = Input::get('match_id');
     //Delete match and cascade delete its games
     $match = Match::find($match_id);
     if (!is_null($match)) {
         $match->delete();
     }
     //Delete match from the current league
     $league_match = LeagueMatch::find($league_id)->where('match_id', '=', $match_id);
     $league_match->delete();
     return \Redirect::route('tools.league.show', array($league_id));
 }
Exemplo n.º 8
0
 /**
  * Handle the event.
  *
  * @param  PlayerScoredPoint  $event
  * @return void
  */
 public function handle(PlayerScoredPoint $event)
 {
     $player = $event->player;
     $match = Match::find($player->match->id);
     $match->addPointFor($player);
 }
Exemplo n.º 9
0
 /**
  * Display the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     return Match::find($id);
 }
Exemplo n.º 10
0
 public function test_player1_wins_set_and_player2_scores_first_in_second_set()
 {
     $player1 = new Player(['nickname' => 'Stefan', 'points' => 10]);
     $player2 = new Player(['nickname' => 'Fredrik', 'points' => 9]);
     $match = Match::create();
     $match->players()->saveMany([$player1, $player2]);
     $match->addPointFor($player1);
     $expected = (object) array('Stefan' => 11, 'Fredrik' => 9);
     $this->assertEquals($expected, $match->getScore());
     $this->assertEquals(1, Player::find($player1->id)->sets_won);
     $this->assertEquals(0, Player::find($player2->id)->sets_won);
     $match->startNewSet();
     $match->resetPlayerPoints();
     $expected = (object) array('Stefan' => 0, 'Fredrik' => 0);
     $this->assertEquals(2, Match::find($match->id)->currentSet());
     $this->assertEquals($expected, $match->getScore());
     $this->assertEquals(1, Player::find($player1->id)->sets_won);
     $this->assertEquals(0, Player::find($player2->id)->sets_won);
 }
Exemplo n.º 11
0
 /**
  * Singel match
  */
 public function show($id)
 {
     $match = Match::find($id);
     return view('match', ['match' => $match, 'players' => $match->players]);
 }
Exemplo n.º 12
0
 /**
  * Handle the event.
  *
  * @param  PlayerWonMatch  $event
  * @return void
  */
 public function handle(PlayerWonMatch $event)
 {
     $match = Match::find($event->player->match->id);
     $match->won_by = $event->player->id;
     $match->save();
 }