Exemplo n.º 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);
     }
 }
Exemplo n.º 2
0
 public function drawTicketforJackpot($leagueId, $lotteryId)
 {
     $isValidToken = User::checkAuth();
     if ($isValidToken != 0) {
         $bowlers = Lottery::getUsersofLottery($lotteryId);
         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, 10);
             /* If the bowler gets a Strike */
             $jackpotAmount = Lottery::getCurrentJackpot($lotteryId);
             if ($pinCount[0] == 10) {
                 $winnerAmount = $jackpotAmount[0]->balence;
                 $jackpot = Lottery::getstrike($lotteryId, $bowlerId, $winnerAmount);
                 return \Response::json($jackpot, 200);
             } else {
                 $winnerAmount = $jackpotAmount[0]->balence / 10;
                 $jackpot = Lottery::getnonstrike($lotteryId, $bowlerId, $winnerAmount, $pinCount[0]);
                 return \Response::json($jackpot, 200);
             }
             return $pinCount[0];
         } else {
             return json_encode("Sorry! There should be minimum 3 players to draw a lottery.");
         }
         return $bowlers;
     } else {
         return json_encode("Please enter valid Authentication Token");
     }
 }