add indicator for move timer

For #11.
This commit is contained in:
Branden J Brown 2024-02-03 22:29:07 -06:00
parent 36475c0a9b
commit a38bf9631f
3 changed files with 27 additions and 3 deletions

View File

@ -67,7 +67,7 @@ const loading = computed(() => status.value === 'CONNECTING' || status.value ===
function clickPlay() {
if (local) {
data.value = JSON.stringify({
game.value = {
action: "Start",
damage: 1,
dealer: false,
@ -77,9 +77,12 @@ function clickPlay() {
],
previous: null,
round: 1,
deadline: Date.now() + 15000,
blank: 3,
live: 2,
});
}
data.value = JSON.stringify(game.value);
dealer.value = false;
return;
}
open();
@ -89,6 +92,7 @@ function clickPlay() {
function action(evt: Action) {
if (local && game.value != null) {
game.value.dealer = !game.value.dealer;
game.value.deadline = Date.now() + 15000;
return;
}
if (evt.action === 'quit') {

View File

@ -2,6 +2,7 @@
<v-container>
<v-row class="d-flex justify-center">
<v-sheet :elevation="2" width="800">
<v-progress-linear :model-value="timeLeft" :max="initTimeLeft" :color="moveColor"></v-progress-linear>
<v-row class="d-flex justify-center">
<v-col cols="auto">
<GameStatus :game="props.game" />
@ -49,7 +50,8 @@
<script setup lang="ts">
import type { Game, Action } from '@/lib/game';
import { computed } from 'vue';
import { computed, ref, watch } from 'vue';
import { useTimestamp } from '@vueuse/core';
export interface Props {
/**
@ -76,6 +78,19 @@ const currentTurn = computed(() => props.game.dealer ? 'DEALER' : 'CHALLENGER');
const dealerTarget = computed(() => props.dealer ? 'YOURSELF' : 'THE DEALER');
const challTarget = computed(() => props.dealer ? 'THE CHALLENGER' : 'YOURSELF');
const initTimeLeft = ref(15000);
const timeLeft = ref(15000);
const timestamp = useTimestamp({
callback: (t) => {
timeLeft.value = props.game.deadline - t;
},
interval: 60,
});
watch(props.game, (now) => {
initTimeLeft.value = now.deadline - timestamp.value;
});
const moveColor = computed(() => timeLeft.value > 3000 ? 'primary' : 'red');
function attack(left: boolean) {
const action = left === props.dealer ? 'self' : 'across';
emit('action', { action });

View File

@ -30,6 +30,11 @@ export interface Game {
* Damage that a live round will deal this turn.
*/
damage: number;
/**
* Deadline for the current player's next action in milliseconds since the
* Unix epoch.
*/
deadline: number;
/**
* The current shell if it is revealed for the player receiving this state.
*/