From a63315e44c941d5af8b633a921f5f5cff92d112d Mon Sep 17 00:00:00 2001 From: Moritz Ruth Date: Sun, 23 Apr 2023 21:08:04 +0200 Subject: [PATCH] commit #8 --- src/App.vue | 2 +- src/clientGame.ts | 11 ++- src/components/Game.vue | 79 +++++++++++++-------- src/components/InputField.vue | 26 ------- src/components/PlayerCards.vue | 26 +++++-- src/components/SpecialCard.vue | 16 +++-- src/components/input/TextInput.vue | 22 ------ src/components/input/TextualInput.vue | 26 ------- src/icons.ts | 11 ++- src/server/game.ts | 44 +++++++++--- src/server/trpc/game.ts | 4 -- src/shared/constants.ts | 3 +- src/shared/game/cards.ts | 40 +++++++---- src/shared/game/state.ts | 98 +++++++++++++++++++++------ tsconfig.json | 2 +- 15 files changed, 236 insertions(+), 174 deletions(-) delete mode 100644 src/components/InputField.vue delete mode 100644 src/components/input/TextInput.vue delete mode 100644 src/components/input/TextualInput.vue diff --git a/src/App.vue b/src/App.vue index 4a50731..90daf48 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,7 +2,7 @@
-
+
Loading…
diff --git a/src/clientGame.ts b/src/clientGame.ts index 07ac7d7..9891588 100644 --- a/src/clientGame.ts +++ b/src/clientGame.ts @@ -5,7 +5,6 @@ import { computed, reactive, readonly, ref } from "vue" import { GameState, getNumberCardsSum, getUninitializedGameState, produceNewState } from "./shared/game/state" import { trpcClient } from "./trpc" import { useAuth } from "./auth" -import { read } from "fs" import type { SpecialCardId } from "./shared/game/cards" const gameActionsBusKey = Symbol() as EventBusKey @@ -60,12 +59,20 @@ export const useGame = defineStore("game", () => { }) } + const ownNumberCardsSum = computed(() => getNumberCardsSum(state.value.players.find(p => p.id === auth.requiredUser.id)!.numberCards)) + const isForcedToHit = computed( + () => state.value.activeSpecialCards.find(c => c.id === "force-hit" && c.ownerId !== auth.requiredUser.id) !== undefined + ) + return { lobbyCode: readonly(lobbyCode), isActive: computed(() => lobbyCode.value !== null), isOwnGame: computed(() => state.value.players.findIndex(p => p.id === (auth.authenticatedUser?.id ?? "")) === 0), isYourTurn: computed(() => state.value.activePlayerId === auth.requiredUser.id), - isBust: computed(() => getNumberCardsSum(state.value.players.find(p => p.id === auth.requiredUser.id)!.numberCards) > state.value.targetSum), + isBust: computed(() => ownNumberCardsSum.value > state.value.targetSum), + mayHit: computed(() => ownNumberCardsSum.value < state.value.targetSum || isForcedToHit.value), + isForcedToHit, + ownNumberCardsSum, state: readonly(state), actions: readonly(actions), join, diff --git a/src/components/Game.vue b/src/components/Game.vue index 1479795..64f55d8 100644 --- a/src/components/Game.vue +++ b/src/components/Game.vue @@ -1,35 +1,54 @@