Improve ui overview and abstract certain components
This commit is contained in:
parent
46ee666437
commit
f91f7ea7ed
@ -5,11 +5,7 @@
|
|||||||
<!-- <router-link to="/about">About</router-link>-->
|
<!-- <router-link to="/about">About</router-link>-->
|
||||||
<!-- </div>-->
|
<!-- </div>-->
|
||||||
<div class="page-container">
|
<div class="page-container">
|
||||||
<md-app>
|
<router-view/>
|
||||||
<md-app-content>
|
|
||||||
<router-view/>
|
|
||||||
</md-app-content>
|
|
||||||
</md-app>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
29
src/components/Round.vue
Normal file
29
src/components/Round.vue
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<template>
|
||||||
|
<table v-if="round.loser">
|
||||||
|
<tr>
|
||||||
|
<td>Round: {{ round.number + 1 }}</td>
|
||||||
|
<td>Loser: {{ round.loser.name }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr v-for="(playerRoll, pId) in round.rolls">
|
||||||
|
<td>{{ players[pId].name }}:</td>
|
||||||
|
<td>
|
||||||
|
<template v-for="(count, number) in playerRoll">
|
||||||
|
<die v-for="n in count" :number="number" :key="'r'+pId+round.number+n+number"></die>
|
||||||
|
</template>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import {Component, Prop, Vue} from 'vue-property-decorator'
|
||||||
|
import {RoundObject, PlayerObject} from "@/objects/objects";
|
||||||
|
import Die from "@/components/Die.vue";
|
||||||
|
@Component({
|
||||||
|
components: {Die}
|
||||||
|
})
|
||||||
|
export default class Round extends Vue {
|
||||||
|
@Prop() private round!: RoundObject;
|
||||||
|
@Prop() private players!: Record<string, PlayerObject>;
|
||||||
|
}
|
||||||
|
</script>
|
@ -23,11 +23,12 @@ export interface JoinCreateGameObject extends ApiObject {
|
|||||||
|
|
||||||
export interface IsStartedObject extends ApiObject {
|
export interface IsStartedObject extends ApiObject {
|
||||||
started: boolean,
|
started: boolean,
|
||||||
|
gameState: GameStateObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MyTurnObject extends ApiObject {
|
export interface MyTurnObject extends ApiObject {
|
||||||
gameState: GameStateObject,
|
|
||||||
turn: boolean,
|
turn: boolean,
|
||||||
|
gameState: GameStateObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GameStateObject {
|
export interface GameStateObject {
|
||||||
|
@ -1,100 +1,115 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="home">
|
<div class="md-layout">
|
||||||
<div v-if="error">
|
<div class="md-layout-item">
|
||||||
Errors: <br>
|
<md-app>
|
||||||
{{ error }}
|
<md-app-content>
|
||||||
|
<div v-if="error">
|
||||||
|
Errors: <br>
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
|
<md-field>
|
||||||
|
<label>Name</label>
|
||||||
|
<md-input v-model="name" :readonly="gameJoined"></md-input>
|
||||||
|
</md-field>
|
||||||
|
<md-field v-if="!gameStarted">
|
||||||
|
<label>Game code</label>
|
||||||
|
<md-input v-model="code" :readonly="gameJoined"></md-input>
|
||||||
|
</md-field>
|
||||||
|
<template v-if="!gameJoined">
|
||||||
|
<md-button @click="createGame" class="md-raised">Create</md-button>
|
||||||
|
<md-button @click="joinGame" class="md-raised">Join</md-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-if="gameJoined && !gameStarted && owner">
|
||||||
|
<md-button @click="startGame" class="md-raised md-primary">Start</md-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-if="myTurn && !gameEnded">
|
||||||
|
It is your turn, make a guess: <br>
|
||||||
|
<md-field>
|
||||||
|
<label>Dice count</label>
|
||||||
|
<md-input type="number" v-model="diceCount"></md-input>
|
||||||
|
</md-field>
|
||||||
|
Die value: <br>
|
||||||
|
<span v-for="n in 6" :key="'v'+n" @click="dieValue = n" :class="(dieValue === n) ? 'inverted' : ''">
|
||||||
|
<die :number="n"></die>
|
||||||
|
</span> <br><br>
|
||||||
|
<md-button @click="makeGuess" class="md-raised md-primary">Guess</md-button>
|
||||||
|
<md-button @click="callBluff" class="md-raised md-accent">Call</md-button>
|
||||||
|
</template>
|
||||||
|
</md-app-content>
|
||||||
|
</md-app>
|
||||||
</div>
|
</div>
|
||||||
<md-field>
|
|
||||||
<label>Name</label>
|
|
||||||
<md-input v-model="name" :readonly="gameJoined"></md-input>
|
|
||||||
</md-field>
|
|
||||||
<md-field v-if="!gameStarted">
|
|
||||||
<label>Game code</label>
|
|
||||||
<md-input v-model="code" :readonly="gameJoined"></md-input>
|
|
||||||
</md-field>
|
|
||||||
<template v-if="!gameJoined">
|
|
||||||
<md-button @click="createGame" class="md-raised">Create</md-button>
|
|
||||||
<md-button @click="joinGame" class="md-raised">Join</md-button>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template v-if="gameJoined && !gameStarted">
|
<div class="md-layout-item">
|
||||||
<span v-if="owner">Game created!</span>
|
<md-app>
|
||||||
<span v-else>Game joined, now waiting or game to start</span>
|
<md-app-content>
|
||||||
<br>
|
<template v-if="gameJoined && !gameStarted">
|
||||||
PlayerId: {{ playerId }} <br>
|
<span v-if="owner">Game created!</span>
|
||||||
|
<span v-else>Game joined, now waiting or game to start</span>
|
||||||
<md-button v-if="owner" @click="startGame" class="md-raised md-primary">Start</md-button>
|
<br>
|
||||||
</template>
|
PlayerId: {{ playerId }} <br>
|
||||||
|
<template v-if="gameStateObject">
|
||||||
<template v-if="gameStarted && !gameEnded">
|
Players: <br>
|
||||||
The game has started, lets go! <br>
|
<template v-for="player in gameStateObject.players">
|
||||||
</template>
|
- {{ player.name }}<br>
|
||||||
|
|
||||||
<template v-if="gameStateObject">
|
|
||||||
<span v-if="previousRound && previousRound.loser.name === name">You lost the previous round! <br></span>
|
|
||||||
Round: {{ currentRound.number + 1 }} <br>
|
|
||||||
Turn: {{ lastTurn ? lastTurn.number + 2 : 1 }} <br>
|
|
||||||
<template v-if="lastTurn">
|
|
||||||
Last guess: <br>
|
|
||||||
{{ lastTurn.diceCount }} dice of value {{ lastTurn.dieValue }}<br>
|
|
||||||
<die v-for="n in lastTurn.diceCount" :number="lastTurn.dieValue" :key="'g'+n+lastTurn.dieValue"></die>
|
|
||||||
<br>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
Your throw: <br>
|
|
||||||
<template v-for="(count, number) in currentRound.myRolls">
|
|
||||||
<die v-for="n in count" :number="number" :key="'t'+n+number"></die>
|
|
||||||
</template>
|
|
||||||
<br>
|
|
||||||
<template v-if="!myTurn">Someone else is playing, waiting for your turn<br></template>
|
|
||||||
Players: <br>
|
|
||||||
<template v-for="player in gameStateObject.players">
|
|
||||||
- {{ player.name }} <span v-if="player.id === gameStateObject.currentPlayer.id"><--</span> <br>
|
|
||||||
</template>
|
|
||||||
<br>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template v-if="myTurn && !gameEnded">
|
|
||||||
It is your turn, make a guess: <br>
|
|
||||||
<md-field>
|
|
||||||
<label>Dice count</label>
|
|
||||||
<md-input type="number" v-model="diceCount"></md-input>
|
|
||||||
</md-field>
|
|
||||||
Die value: <br>
|
|
||||||
<span v-for="n in 6" :key="'v'+n" @click="dieValue = n" :class="(dieValue === n) ? 'inverted' : ''">
|
|
||||||
<die :number="n"></die>
|
|
||||||
</span> <br><br>
|
|
||||||
<md-button @click="makeGuess" class="md-raised md-primary">Guess</md-button>
|
|
||||||
<md-button @click="callBluff" class="md-raised md-accent">Call</md-button>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template v-if="gameEnded">
|
|
||||||
The game is over, the winner is: {{ gameStateObject.currentPlayer.name }}<br>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
<div class="home">
|
|
||||||
<template v-if="gameStateObject">
|
|
||||||
History: <br>
|
|
||||||
<table v-for="round in gameStateObject.rounds.slice().reverse()">
|
|
||||||
<template v-if="round.loser">
|
|
||||||
<tr>
|
|
||||||
<td>Round: {{ round.number + 1 }}</td>
|
|
||||||
<td>Loser: {{ round.loser.name }}</td>
|
|
||||||
</tr>
|
|
||||||
<tr v-for="(playerRoll, pId) in round.rolls">
|
|
||||||
<td>{{ playersKeyedById[pId].name }}: </td>
|
|
||||||
<td>
|
|
||||||
<template v-for="(count, number) in playerRoll">
|
|
||||||
<die v-for="n in count" :number="number" :key="'r'+pId+round.number+n+number"></die>
|
|
||||||
</template>
|
</template>
|
||||||
</td>
|
</template>
|
||||||
</tr>
|
</template>
|
||||||
<br>
|
|
||||||
</template>
|
<template v-if="gameRunning">
|
||||||
</table>
|
The game has started, lets go! <br>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template v-if="gameStateObject && gameRunning">
|
||||||
|
<span v-if="previousRound && previousRound.loser.name === name">You lost the previous round!<br></span>
|
||||||
|
Round: {{ currentRound.number + 1 }} <br>
|
||||||
|
Turn: {{ lastTurn ? lastTurn.number + 2 : 1 }} <br>
|
||||||
|
|
||||||
|
Your throw: <br>
|
||||||
|
<template v-for="(count, number) in currentRound.myRolls">
|
||||||
|
<die v-for="n in count" :number="number" :key="'t'+n+number"></die>
|
||||||
|
</template>
|
||||||
|
<br><br>
|
||||||
|
<template v-if="lastTurn">
|
||||||
|
Last guesses: <br>
|
||||||
|
<table>
|
||||||
|
<tr v-for="turn in currentRound.turns">
|
||||||
|
<td>{{ turn.player.name }} ({{ turn.number + 1 }}):</td>
|
||||||
|
<td>
|
||||||
|
<die v-for="n in turn.diceCount" :number="turn.dieValue" :key="'g'+n+turn.dieValue"></die>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</template>
|
||||||
|
<br>
|
||||||
|
<template v-if="!myTurn">Someone else is playing, waiting for your turn<br></template>
|
||||||
|
Players: <br>
|
||||||
|
<template v-for="player in gameStateObject.players">
|
||||||
|
-{{ player.id === gameStateObject.currentPlayer.id ? '>' : '-' }}{{ player.name }}<br>
|
||||||
|
</template>
|
||||||
|
<br>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-if="gameEnded">
|
||||||
|
The game is over, the winner is: {{ gameStateObject.currentPlayer.name }}<br>
|
||||||
|
</template>
|
||||||
|
</md-app-content>
|
||||||
|
</md-app>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
|
<md-app>
|
||||||
|
<md-app-content>
|
||||||
|
<template v-if="gameStateObject && gameStarted">
|
||||||
|
History: <br>
|
||||||
|
<template v-for="round in gameStateObject.rounds.slice().reverse()">
|
||||||
|
<round :round="round" :players="playersKeyedById" />
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</md-app-content>
|
||||||
|
</md-app>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -102,10 +117,11 @@
|
|||||||
import {Component, Vue} from 'vue-property-decorator'
|
import {Component, Vue} from 'vue-property-decorator'
|
||||||
import PerudoApi from "@/services/PerudoApi";
|
import PerudoApi from "@/services/PerudoApi";
|
||||||
import Die from "@/components/Die.vue";
|
import Die from "@/components/Die.vue";
|
||||||
import {ApiObject, GameState, GameStateObject, IsStartedObject, JoinCreateGameObject, MyTurnObject, RoundObject, TurnObject, GameStateState, PlayerObject} from "@/objects/objects"; // @ is an alias to /src
|
import {ApiObject, GameState, GameStateObject, IsStartedObject, JoinCreateGameObject, MyTurnObject, RoundObject, TurnObject, GameStateState, PlayerObject} from "@/objects/objects";
|
||||||
|
import Round from "@/components/Round.vue"; // @ is an alias to /src
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {Die}
|
components: {Round, Die}
|
||||||
})
|
})
|
||||||
export default class Home extends Vue {
|
export default class Home extends Vue {
|
||||||
private gameState: GameState = GameState.Setup;
|
private gameState: GameState = GameState.Setup;
|
||||||
@ -130,6 +146,10 @@ export default class Home extends Vue {
|
|||||||
return this.gameState >= GameState.Started;
|
return this.gameState >= GameState.Started;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get gameRunning(): boolean {
|
||||||
|
return this.gameStarted && !this.gameEnded;
|
||||||
|
}
|
||||||
|
|
||||||
private get gameEnded(): boolean {
|
private get gameEnded(): boolean {
|
||||||
return this.gameState === GameState.Ended;
|
return this.gameState === GameState.Ended;
|
||||||
}
|
}
|
||||||
@ -175,6 +195,9 @@ export default class Home extends Vue {
|
|||||||
this.owner = true;
|
this.owner = true;
|
||||||
|
|
||||||
this.gameState = GameState.Joined;
|
this.gameState = GameState.Joined;
|
||||||
|
this.gameTimer = setInterval(() => {
|
||||||
|
this.checkStarted();
|
||||||
|
}, 1000);
|
||||||
}).catch((reason => {
|
}).catch((reason => {
|
||||||
this.error = reason;
|
this.error = reason;
|
||||||
}));
|
}));
|
||||||
@ -205,9 +228,7 @@ export default class Home extends Vue {
|
|||||||
if (this.gameJoined && this.playerId) {
|
if (this.gameJoined && this.playerId) {
|
||||||
PerudoApi.instance.startGame(this.playerId).then((response: ApiObject) => {
|
PerudoApi.instance.startGame(this.playerId).then((response: ApiObject) => {
|
||||||
this.gameState = GameState.Started;
|
this.gameState = GameState.Started;
|
||||||
this.gameTimer = setInterval(() => {
|
this.gameStateObject = null; // Bug fix because checkStarted gameStateObject misses some properties
|
||||||
this.checkTurn();
|
|
||||||
}, 1000);
|
|
||||||
}).catch((reason => {
|
}).catch((reason => {
|
||||||
this.error = reason;
|
this.error = reason;
|
||||||
}));
|
}));
|
||||||
@ -224,6 +245,7 @@ export default class Home extends Vue {
|
|||||||
this.gameTimer = setInterval(() => {
|
this.gameTimer = setInterval(() => {
|
||||||
this.checkTurn();
|
this.checkTurn();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
this.checkTurn();
|
||||||
}).catch((reason => {
|
}).catch((reason => {
|
||||||
this.error = reason;
|
this.error = reason;
|
||||||
}));
|
}));
|
||||||
@ -237,6 +259,7 @@ export default class Home extends Vue {
|
|||||||
this.gameTimer = setInterval(() => {
|
this.gameTimer = setInterval(() => {
|
||||||
this.checkTurn();
|
this.checkTurn();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
this.checkTurn();
|
||||||
}).catch((reason => {
|
}).catch((reason => {
|
||||||
this.error = reason;
|
this.error = reason;
|
||||||
}));
|
}));
|
||||||
@ -247,8 +270,10 @@ export default class Home extends Vue {
|
|||||||
console.log("Check started");
|
console.log("Check started");
|
||||||
if (this.gameJoined && this.playerId) {
|
if (this.gameJoined && this.playerId) {
|
||||||
PerudoApi.instance.gameStarted(this.playerId).then((response: IsStartedObject) => {
|
PerudoApi.instance.gameStarted(this.playerId).then((response: IsStartedObject) => {
|
||||||
|
this.gameStateObject = response.gameState;
|
||||||
if (response.started) {
|
if (response.started) {
|
||||||
this.gameState = GameState.Started;
|
this.gameState = GameState.Started;
|
||||||
|
|
||||||
this.clearGameTimer();
|
this.clearGameTimer();
|
||||||
this.gameTimer = setInterval(() => {
|
this.gameTimer = setInterval(() => {
|
||||||
this.checkTurn();
|
this.checkTurn();
|
||||||
|
Loading…
Reference in New Issue
Block a user