Exemple #1
0
 public function lastwinner()
 {
     $last_winner = \DB::table('games')->where('status', '=', 3)->orderBy('id', 'desc')->take(1)->get();
     foreach ($last_winner as $last) {
         $user = User::find($last->winner_id);
         $last->username = $user->username;
         $last->avatar = $user->avatar;
         $last->steamid64 = $user->steamid64;
         $last->percent = GameController::_getUserChanceOfGame($user, $last);
     }
     $returnValue = ['username' => preg_replace('/' . \App\Game::zapretsite() . '/i', '', $last->username), 'avatar' => $last->avatar, 'steamid64' => $last->steamid64, 'percent' => $last->percent, 'price' => $last->price];
     return response()->json($returnValue);
 }
Exemple #2
0
 private function _getChancesOfGame($game, $is_object = false)
 {
     $chances = [];
     foreach ($game->users() as $user) {
         if ($is_object) {
             $chances[] = (object) ['chance' => GameController::_getUserChanceOfGame($user, $game), 'avatar' => $user->avatar, 'items' => User::find($user->id)->itemsCountByGame($game), 'steamid64' => $user->steamid64];
         } else {
             $chances[] = ['chance' => GameController::_getUserChanceOfGame($user, $game), 'avatar' => $user->avatar, 'items' => User::find($user->id)->itemsCountByGame($game), 'steamid64' => $user->steamid64];
         }
     }
     return $chances;
 }
Exemple #3
0
 public function asyncGuess(AjaxGuessRequest $request)
 {
     if (GameController::isGameEnded()) {
         return response()->json(['result' => 'error', 'reason' => 'Game ended.']);
     }
     $guess = $request->input('guess');
     $studentId = $request->getStudentIdFromSession();
     $currentGame = $request->getGameFromSession();
     $guessResult = $currentGame->guess($guess);
     $roundCount = $currentGame->getRoundCount();
     $guessCount = $currentGame->getRoundGuessCount();
     $correctness = $currentGame->getCorrectness();
     $roundPoints = 0;
     $totalPoints = $currentGame->getTotalPoints();
     if ($correctness || $roundCount < 5 && $guessCount == 10) {
         $currentGame->completeCurrentRound();
         $roundPoints = $currentGame->getRoundPoints();
         $totalPoints = $currentGame->getTotalPoints();
         $currentGame->newRound();
         // update points record and find out ranking info.
         // Retrieve the student entity from database.
         $student = Student::find($studentId);
         if (!$student) {
             return response()->json(['result' => 'error', 'reason' => 'student data do not exist.']);
         }
         if ($student['highestMark'] < $totalPoints) {
             // update
             if (!in_array($studentId, ['a1203212', 'a1165070'])) {
                 $student['highestMark'] = $totalPoints;
                 $student['recordDate'] = Carbon::now();
                 $student->save();
             }
         }
     }
     $jsonResponse = ['result' => 'guessResult', 'roundData' => ['roundCount' => $roundCount, 'resultText' => $guessResult, 'guessCount' => $guessCount, 'roundPoints' => $roundPoints, 'totalPoints' => $totalPoints, 'correctness' => $correctness]];
     if (GameController::isDebug()) {
         $jsonResponse['roundData']['secret'] = $currentGame->getRoundSecret();
     }
     return response()->json($jsonResponse);
 }
Exemple #4
0
 public function jump(Request $request)
 {
     UserGame::updateReady($request->gameid, \Auth::User()->id, 'J');
     GameController::pass_turn($request);
 }