diff --git a/src/algo.ts b/src/algo.ts index 90dd560..70ad931 100644 --- a/src/algo.ts +++ b/src/algo.ts @@ -1,8 +1,5 @@ -import { reactive, ref, watch } from 'vue' - -import { operators, pool } from './globals' -import { Operation, OperatorType, Plaquette } from './types' -import { randRange } from './utils' +import { operators } from './globals' +import { Operation, OperatorType } from './types' type HistoryType = { a: number; b: number; op: OperatorType }[] diff --git a/src/components/OperationsList.vue b/src/components/OperationsList.vue index 38abf8f..8557da9 100644 --- a/src/components/OperationsList.vue +++ b/src/components/OperationsList.vue @@ -72,11 +72,11 @@ import { isOperationResultValid, operate, } from '@/algo' +import { operations, plaquettes } from '@/game-state' import { GameState, gameState } from '@/globals' -import { operations, plaquettes } from '@/store' import { Operation } from '@/types' -import IconSad from '~icons/bx/bx-sad' import IconUndo from '~icons/bx/bx-undo' +import IconSad from '~icons/ph/smiley-sad' import PlaquetteBox from './common/PlaquetteBox.vue' diff --git a/src/components/common/PlaquetteBox.vue b/src/components/common/PlaquetteBox.vue index 9cbc1f7..c394938 100644 --- a/src/components/common/PlaquetteBox.vue +++ b/src/components/common/PlaquetteBox.vue @@ -13,7 +13,7 @@ import { ref, watch } from 'vue' const props = withDefaults( - defineProps<{ dynamicSize: boolean; is?: string }>(), + defineProps<{ dynamicSize?: boolean; is?: string }>(), { is: 'div', dynamicSize: false, diff --git a/src/store.ts b/src/game-state.ts similarity index 52% rename from src/store.ts rename to src/game-state.ts index 1891ed6..0f067c8 100644 --- a/src/store.ts +++ b/src/game-state.ts @@ -1,9 +1,9 @@ import { computed, reactive, ref } from 'vue' -import { isOperationReady } from './algo' +import { getEmptyOperation, isOperationReady } from './algo' import { Operation, Plaquette } from './types' -export const operations = reactive([]) +export const operations = reactive([getEmptyOperation()]) export const plaquettes = ref([]) export const result = ref(0) @@ -13,9 +13,11 @@ export const currentOperation = computed( ) export const isEndGame = computed( - () => operations.length === 5 && isOperationReady(currentOperation.value), + () => + (operations.length === 5 && isOperationReady(currentOperation.value)) || + isResultPerfect.value, ) export const isResultPerfect = computed( - () => currentOperation.value.result!.value === result.value, + () => !!operations.some(o => o.result?.value === result.value), ) diff --git a/src/globals.ts b/src/globals.ts index 31568dd..936a6d1 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -1,9 +1,16 @@ import { ref } from 'vue' export const operators = ['+', '-', 'x', '/'] as const -export const pool = [ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, 75, 100, -] as const + +export const pools = { + 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25], + 2: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, 75], + 3: [ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, 75, + 100, + ], + 4: [2, 2, 3, 3, 5, 5, 7, 11, 13, 17, 19, 23], +} as const export enum GameState { Undefined = 0, diff --git a/src/locales/fr.json b/src/locales/fr.json index b8ac2b6..06f8680 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -1,6 +1,10 @@ { "playAgain": "Rejouer", - "endGame.victoryLabel": "Bien joué !", - "endGame.failureLabel": "Presque", - "startGame": "Démarrer" + "endGame.victoryLabel": "Le compte est bon !", + "endGame.failureLabel": "Dommage...
Une autre partie ?", + "startGame": "Démarrer", + "easy": "facile", + "medium": "moyen", + "hard": "difficile", + "impossible": "☠" } diff --git a/src/views/GameView.vue b/src/views/GameView.vue index 949ee19..f165668 100644 --- a/src/views/GameView.vue +++ b/src/views/GameView.vue @@ -10,7 +10,8 @@ :class="{ 'text-green-400': difficultyLevel === 1, 'text-amber-400': difficultyLevel === 2, - 'text-red-400': difficultyLevel === 3, + 'text-orange-400': difficultyLevel === 3, + 'text-red-500': difficultyLevel === 4, }"> {{ result }} @@ -24,8 +25,23 @@
Combinez les nombres imposés afin de trouver le résultat ci-dessus, ou de vous en approcher le plus possible.
- Le compteur démarre quand vous cliquez sur le bouton.
Partagez vos - meilleurs temps ! + Le compteur démarre quand vous cliquez sur le bouton.
Partagez + vos meilleurs temps ! +
+ +
+ Niveau de difficulté : + {{ difficultyLabel }} +