Improve guessing
This commit is contained in:
@ -34,7 +34,23 @@
|
||||
It is your turn! <br>
|
||||
Round: {{ currentRound.number + 1 }} <br>
|
||||
Turn: {{ currentTurn ? currentTurn.number : 1 }} <br>
|
||||
Throws: {{ currentRound.myRolls }}
|
||||
Throws: {{ currentRound.myRolls }} <br>
|
||||
Players: <br>
|
||||
<template v-for="player in gameStateObject.players">
|
||||
- {{ player.name }} <br>
|
||||
</template>
|
||||
<br>
|
||||
|
||||
<md-field>
|
||||
<label>Dice count</label>
|
||||
<md-input type="number" v-model="diceCount"></md-input>
|
||||
</md-field>
|
||||
<md-field>
|
||||
<label>Die value</label>
|
||||
<md-input type="number" v-model="dieValue"></md-input>
|
||||
</md-field>
|
||||
<md-button @click="makeGuess" class="md-raised md-primary">Guess</md-button>
|
||||
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@ -42,14 +58,7 @@
|
||||
<script lang="ts">
|
||||
import {Component, Vue} from 'vue-property-decorator'
|
||||
import PerudoApi from "@/services/PerudoApi";
|
||||
import {
|
||||
ApiObject,
|
||||
GameState,
|
||||
GameStateObject,
|
||||
IsStartedObject,
|
||||
JoinCreateGameObject,
|
||||
MyTurnObject, RoundObject, TurnObject
|
||||
} from "@/objects/objects"; // @ is an alias to /src
|
||||
import {ApiObject, GameState, GameStateObject, IsStartedObject, JoinCreateGameObject, MyTurnObject, RoundObject, TurnObject} from "@/objects/objects"; // @ is an alias to /src
|
||||
|
||||
@Component({
|
||||
components: {}
|
||||
@ -66,6 +75,9 @@ export default class Home extends Vue {
|
||||
private playerId: string | null = null;
|
||||
private gameTimer: number | null = null;
|
||||
|
||||
private diceCount: number = 0;
|
||||
private dieValue: number = 1;
|
||||
|
||||
private get gameJoined(): boolean {
|
||||
return this.gameState >= GameState.Joined;
|
||||
}
|
||||
@ -130,7 +142,24 @@ export default class Home extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
private makeGuess(): void {
|
||||
if (this.myTurn && this.playerId) {
|
||||
PerudoApi.instance.makeGuess(this.playerId, {
|
||||
diceCount: parseInt(this.diceCount),
|
||||
dieValue: parseInt(this.dieValue),
|
||||
}).then((response: MyTurnObject) => {
|
||||
this.gameState = GameState.Started;
|
||||
this.gameTimer = setInterval(() => {
|
||||
this.checkTurn();
|
||||
}, 1000);
|
||||
}).catch((reason => {
|
||||
this.error = reason;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private checkStarted(): void {
|
||||
console.log("Check started");
|
||||
if (this.gameJoined && this.playerId) {
|
||||
PerudoApi.instance.gameStarted(this.playerId).then((response: IsStartedObject) => {
|
||||
if (response.started) {
|
||||
@ -147,11 +176,12 @@ export default class Home extends Vue {
|
||||
}
|
||||
|
||||
private checkTurn(): void {
|
||||
console.log("Check turn");
|
||||
if (this.gameStarted && this.playerId) {
|
||||
PerudoApi.instance.myTurn(this.playerId).then((response: MyTurnObject) => {
|
||||
if (response.turn) {
|
||||
console.log(response.gameState);
|
||||
this.gameStateObject = response.gameState;
|
||||
console.log(this.gameStateObject);
|
||||
this.gameState = GameState.MyTurn;
|
||||
this.clearGameTimer();
|
||||
}
|
||||
|
Reference in New Issue
Block a user