From fe69ec62ab9d2d31bbcfaf84f322ea5e12c45d5f Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 11 Jul 2021 16:58:49 +0200 Subject: [PATCH] Add timer to check if game is started and its your turn and implement gameStateObject from api --- src/objects/objects.ts | 45 +++++++++++++++++++--- src/services/PerudoApi.ts | 12 +++++- src/views/Home.vue | 80 +++++++++++++++++++++++++++++++-------- 3 files changed, 115 insertions(+), 22 deletions(-) diff --git a/src/objects/objects.ts b/src/objects/objects.ts index 0c5ff3c..d7fbdda 100644 --- a/src/objects/objects.ts +++ b/src/objects/objects.ts @@ -2,18 +2,20 @@ export enum GameState { Setup, Joined, Started, + MyTurn, Ended, } +export enum GameStateState { + Setup = 'setup', + Running = 'running', + Ended = 'ended', +} + export interface ApiObject { errors?: string[], } -export interface PlayerObject extends ApiObject { - id: string, - name: string, -} - export interface JoinCreateGameObject extends ApiObject { player: PlayerObject, code: string, @@ -22,3 +24,36 @@ export interface JoinCreateGameObject extends ApiObject { export interface IsStartedObject extends ApiObject { started: boolean, } + +export interface MyTurnObject extends ApiObject { + gameState: GameStateObject, + turn: boolean, +} + +export interface GameStateObject { + state: GameStateState, + code: string, + rounds: RoundObject[], + players: PlayerObject[], + currentPlayer: PlayerObject, + owningPlayer: PlayerObject, +} + +export interface RoundObject { + number: number, + turns: TurnObject[], + loser?: PlayerObject, + myRolls: number[], +} + +export interface TurnObject { + number: number, + player: PlayerObject, + diceCount: number, + dieValue: number, +} + +export interface PlayerObject { + id: string, + name: string, +} diff --git a/src/services/PerudoApi.ts b/src/services/PerudoApi.ts index dd1297a..dd764fc 100644 --- a/src/services/PerudoApi.ts +++ b/src/services/PerudoApi.ts @@ -1,5 +1,5 @@ import axios, {AxiosPromise, AxiosRequestConfig, AxiosResponse} from 'axios' -import {JoinCreateGameObject, IsStartedObject, ApiObject} from "@/objects/objects"; +import {JoinCreateGameObject, IsStartedObject, ApiObject, GameStateObject, MyTurnObject} from "@/objects/objects"; export default class PerudoApi { private static baseUrl = 'http://localhost:8000/' @@ -27,7 +27,7 @@ export default class PerudoApi { }) } - public startedGame(playerId: string): Promise { + public gameStarted(playerId: string): Promise { return this.get(PerudoApi.baseUrl + 'game/started/' + playerId) .then((response: AxiosResponse) => { return response.data; @@ -41,8 +41,16 @@ export default class PerudoApi { }); } + public myTurn(playerId: string): Promise { + return this.get(PerudoApi.baseUrl + 'player/turn/' + playerId) + .then((response: AxiosResponse) => { + return response.data; + }) + } + private get(url: string, getParameters?: Record): AxiosPromise { return axios.get(url).then((response: AxiosResponse) => { + // @ts-ignore if (response?.data?.errors?.length > 0) { throw response.data.errors?.join(); } diff --git a/src/views/Home.vue b/src/views/Home.vue index a398697..236c20a 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -19,35 +19,43 @@ - +