game - hit validation

This commit is contained in:
anon 2022-11-07 21:03:21 +01:00
parent b5f17a8d93
commit b155b1632f
3 changed files with 18 additions and 3 deletions

View File

@ -40,6 +40,20 @@ class GameController extends Controller
);
}
private function to_answer_format($str){
$str = str_replace(['_', ':'], [' '], strtolower($str));
return $str;
}
public function do_validate(Request $request, $id, $puzzle){ // this function cannot be called just "validate" cause that conflicts with Laravel definitions
$p = DB::table('game_puzzles')->join('puzzles', 'puzzle_id', '=', 'puzzles.id')->get()->where('game_id', $id)->values()->get($puzzle-1);
if($this->to_answer_format($request->tipp) == $this->to_answer_format($p->answer)){
$i = DB::table('game_puzzles')->get()->where('game_id', $id)->values()->get($puzzle-1)->id;
DB::table('game_puzzles')->where('id', $i)->update(['hit' => 1]);
}
return redirect("/play/" . $id . '/' . ($puzzle+1));
}
public function list($userID) {
if (!Auth::check()) {

View File

@ -1,8 +1,8 @@
@extends('template')
@php
//$debug = True;
$debug = False;
$debug = True;
//$debug = False;
$answer = $puzzle->answer;
$pic = $puzzle->picture;
@ -53,7 +53,7 @@
<div style="display: flex; justify-content: space-between;">
<div class=mb-4>
<h3>Tipp:</h3>
<input id="tipp" placeholder="játék név"></input>
<input id="tipp" name="tipp" placeholder="játék név"></input>
<span id=inputErrorPlaceholder class="text-danger"></span>
</div>
<div style="float: right;">

View File

@ -66,6 +66,7 @@ Route::post('/generateNewGame', [GameController::class, 'generate']);
Route::get('/play/{id}/{puzzle}', [GameController::class, 'play']);
Route::post('/play/{id}/{puzzle}/validate', [GameController::class, 'do_validate']);
Route::get('/games/{userID}/list', [GameController::class, 'list']);