This commit is contained in:
@@ -34,19 +34,7 @@ class TlaController extends Controller
|
|||||||
|
|
||||||
if ( !in_array($language, $allowedLanguages) ) $language = 'en';
|
if ( !in_array($language, $allowedLanguages) ) $language = 'en';
|
||||||
|
|
||||||
$tla = Tla::where('used', date("Y-m-d"))
|
$tla = Tla::GetCurrentTla($language);
|
||||||
->where('language', $language)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if ( is_null($tla) ) {
|
|
||||||
$tla = Tla::where('language', $language)
|
|
||||||
->where('used', NULL)
|
|
||||||
->inRandomOrder()
|
|
||||||
->first();
|
|
||||||
|
|
||||||
$tla->used = date("Y-m-d");
|
|
||||||
$tla->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'hint' => $tla->hint,
|
'hint' => $tla->hint,
|
||||||
@@ -62,18 +50,41 @@ class TlaController extends Controller
|
|||||||
|
|
||||||
$guess = $request->all()['guess'];
|
$guess = $request->all()['guess'];
|
||||||
|
|
||||||
$guess_array = explode(' ', $guess);
|
$tla = explode(' ', Tla::GetCurrentTla($language)->abbreviation);
|
||||||
|
|
||||||
|
$guess_array = explode(' ', $guess);
|
||||||
|
$proposal = [];
|
||||||
|
|
||||||
|
for ($i = 0; $i < 3; $i++) {
|
||||||
|
for ($j = 0; $j < 3; $j++) {
|
||||||
|
if ( $guess_array[$j] == $tla[$i] ) {
|
||||||
|
$proposal[$i][$j] = $i-$j != 0 ? 3 : 4;
|
||||||
|
}
|
||||||
|
else if ( $guess_array[$j][0] == $tla[$i][0] ) {
|
||||||
|
$proposal[$i][$j] = $i-$j != 0 ? 1 : 2;
|
||||||
|
}
|
||||||
|
else $proposal[$i][$j] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($proposal[$i][0] <= $proposal[$i][1] || $proposal[$i][0] <= $proposal[$i][2]) $proposal[$i][0] = 0;
|
||||||
|
if ($proposal[$i][1] <= $proposal[$i][2] || $proposal[$i][1] <= $proposal[$i][0]) $proposal[$i][1] = 0;
|
||||||
|
if ($proposal[$i][2] <= $proposal[$i][0] || $proposal[$i][2] <= $proposal[$i][1]) $proposal[$i][2] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i = 0; $i < 3; $i++) {
|
||||||
|
array_push($guess_array, max($proposal[0][$i], $proposal[1][$i], $proposal[2][$i]));
|
||||||
|
}
|
||||||
|
|
||||||
array_push($guess_array, 1);
|
|
||||||
array_push($guess_array, 2);
|
|
||||||
array_push($guess_array, 3);
|
|
||||||
|
|
||||||
if ( $request->session()->get('guesses-'.$language, NULL) == NULL ) $request->session()->put('guesses-'.$language, [$guess_array]);
|
if ( $request->session()->get('guesses-'.$language, NULL) == NULL ) $request->session()->put('guesses-'.$language, [$guess_array]);
|
||||||
else $request->session()->push('guesses-'.$language, $guess_array);
|
else $request->session()->push('guesses-'.$language, $guess_array);
|
||||||
|
|
||||||
$guesses = $request->session()->get('guesses-'.$language, NULL);
|
$guesses = $request->session()->get('guesses-'.$language, NULL);
|
||||||
|
|
||||||
return $guesses;
|
return response()->json([
|
||||||
|
'guesses' => $request->session()->get('guesses-'.$language, NULL),
|
||||||
|
'real' => $tla
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(Request $request, Tla $tla): RedirectResponse
|
public function update(Request $request, Tla $tla): RedirectResponse
|
||||||
|
|||||||
@@ -12,4 +12,23 @@ class Tla extends Model
|
|||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = ['abbreviation', 'hint', 'used'];
|
protected $fillable = ['abbreviation', 'hint', 'used'];
|
||||||
|
|
||||||
|
public static function GetCurrentTla( string $language ) : Tla {
|
||||||
|
$tla = Tla::where('used', date("Y-m-d"))
|
||||||
|
->where('language', $language)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ( is_null($tla) ) {
|
||||||
|
$tla = Tla::where('language', $language)
|
||||||
|
->where('used', NULL)
|
||||||
|
->inRandomOrder()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$tla->used = date("Y-m-d");
|
||||||
|
$tla->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $tla;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class TlaFactory extends Factory
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'abbreviation' => fake()->word() . ' ' . fake()->word() . ' ' . fake()->word(),
|
'abbreviation' => fake()->word() . ' ' . fake()->word() . ' ' . fake()->word(),
|
||||||
'hint' => fake()->word(),
|
'hint' => fake()->sentence(),
|
||||||
'language' => fake()->randomElement(['hu', 'en']),
|
'language' => fake()->randomElement(['hu', 'en']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,3 +8,11 @@
|
|||||||
--font-sans: 'Instrument Sans', ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
|
--font-sans: 'Instrument Sans', ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
|
||||||
'Segoe UI Symbol', 'Noto Color Emoji';
|
'Segoe UI Symbol', 'Noto Color Emoji';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.main {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
font-size: 3vh;
|
||||||
|
font-weight: bolder;
|
||||||
|
}
|
||||||
|
|||||||
+13
-1
@@ -20,7 +20,19 @@
|
|||||||
<template>
|
<template>
|
||||||
|
|
||||||
<UApp>
|
<UApp>
|
||||||
<UMain>
|
<UHeader>
|
||||||
|
<template #title>
|
||||||
|
TLAdle
|
||||||
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
<template #right>
|
||||||
|
<UColorModeButton />
|
||||||
|
|
||||||
|
|
||||||
|
</template>
|
||||||
|
</UHeader>
|
||||||
|
<UMain class="main">
|
||||||
<NuxtLayout>
|
<NuxtLayout>
|
||||||
<router-view v-slot="{ Component,route }">
|
<router-view v-slot="{ Component,route }">
|
||||||
<component :is="Component" />
|
<component :is="Component" />
|
||||||
|
|||||||
@@ -1,16 +1,36 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="gw-div">
|
<div class="gw-div" :class="{ 'default': correctness==0, 'cw-cp': correctness==4, 'cw-ip': correctness==3, 'cf-cp': correctness==2, 'cf-ip': correctness==1 }">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
correctness: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
|
.gw-div::first-letter {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
.gw-div {
|
.gw-div {
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
background-color: grey;
|
background-color: grey;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.default {
|
||||||
|
background-color: red;
|
||||||
}
|
}
|
||||||
.cw-cp {
|
.cw-cp {
|
||||||
background-color: rgb(0, 122, 2);
|
background-color: rgb(0, 122, 2);
|
||||||
|
|||||||
@@ -31,10 +31,11 @@
|
|||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log(response.data);
|
console.log(response.data);
|
||||||
|
this.guesses = response.data.guesses;
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onkeyup() {
|
onkeyup() {
|
||||||
this.words = this.guess.split(" ");
|
this.words = this.guess.trim().split(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,19 +45,26 @@
|
|||||||
<template>
|
<template>
|
||||||
<UCard>
|
<UCard>
|
||||||
<template #header>
|
<template #header>
|
||||||
|
<h1>Motto:</h1>
|
||||||
{{ hint }}
|
{{ hint }}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-for="guess in guesses">
|
<template v-for="guess in guesses">
|
||||||
{{ guess }}
|
<div class="flex-container">
|
||||||
|
<template v-for="i in 3">
|
||||||
|
<GuessWord :correctness="Number(guess[i+2])">
|
||||||
|
{{ guess[i-1] }}
|
||||||
|
</GuessWord>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
|
|
||||||
<div style="display: flex; flex-direction: row;">
|
<div class="flex-container">
|
||||||
<template v-for="word in words">
|
<template v-for="word in words">
|
||||||
<GuessWord>
|
<GuessWord :correctness="-1">
|
||||||
{{ word }}
|
{{ word }}
|
||||||
</GuessWord>
|
</GuessWord>
|
||||||
</template>
|
</template>
|
||||||
@@ -67,4 +75,16 @@
|
|||||||
|
|
||||||
</template>
|
</template>
|
||||||
</UCard>
|
</UCard>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.flex-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.hidden {
|
||||||
|
color: transparent;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user