Beispiel #1
0
 public function play($lottery_id)
 {
     $baseURL = '../../public/';
     $user = Auth::user()->id;
     $currentLotteryJackpot = Lottery::getCurrentJackpot($lottery_id);
     $bowlers = Lottery::getUsersofLottery($lottery_id);
     /* If there are more than two bowlers */
     if (count($bowlers) > 2) {
         $allBowlers = array();
         $isGame = 1;
         foreach ($bowlers as $currentBowler) {
             $allBowlers[$currentBowler->id] = $currentBowler->name;
         }
         /* Picks a Bowler from drawing */
         $luckyBowler = $allBowlers[array_rand($allBowlers)];
         $luckyBowlerId = User::getUserIdbyName($luckyBowler);
         $bowlerId = $luckyBowlerId[0]->id;
         /* RollOut */
         $pinCount[0] = rand(0, 2);
         /* If the bowler gets a Strike */
         $jackpotAmount = Lottery::getCurrentJackpot($lottery_id);
         if ($pinCount[0] == 2) {
             $winnerAmount = $jackpotAmount[0]->balence;
             Lottery::strike($lottery_id, $bowlerId, $winnerAmount);
         } else {
             $winnerAmount = $jackpotAmount[0]->balence / 10;
             Lottery::nonstrike($lottery_id, $bowlerId, $winnerAmount);
         }
         /* If the lucky Bowler is current user */
         $isLuckyBowler = 0;
         if ($user == $luckyBowlerId[0]->id) {
             $isLuckyBowler = 1;
         }
         Lottery::jackpotAmount($lottery_id, $bowlerId, $winnerAmount);
         return \View::make('play')->with('currentLotteryJackpot', $currentLotteryJackpot)->with('luckyBowler', $luckyBowler)->with('isLuckyBowler', $isLuckyBowler)->with('pinCount', $pinCount)->with('isGame', $isGame)->with('baseURL', $baseURL);
     } else {
         $isGame = 0;
         $pinCount[0] = 0;
         return \View::make('play')->with('pinCount', $pinCount)->with('isGame', $isGame)->with('baseURL', $baseURL);
     }
 }