返回游戏流程完善

This commit is contained in:
kron
2025-07-21 10:40:43 +08:00
parent 9e83bf89f7
commit 200c05a288
9 changed files with 185 additions and 207 deletions

View File

@@ -13,7 +13,7 @@ import Avatar from "@/components/Avatar.vue";
import ScreenHint from "@/components/ScreenHint.vue";
import Matching from "@/components/Matching.vue";
import TestDistance from "@/components/TestDistance.vue";
import { matchGameAPI, readyGameAPI } from "@/apis";
import { matchGameAPI } from "@/apis";
import { MESSAGETYPES, getMessageTypeName } from "@/constants";
import useStore from "@/store";
import { storeToRefs } from "pinia";
@@ -29,7 +29,6 @@ const power = ref(0);
const scores = ref([]);
const tips = ref("即将开始...");
const seq = ref(0);
const timerSeq = ref(0);
const players = ref([]);
const playersSorted = ref([]);
const playersScores = ref({});
@@ -58,8 +57,6 @@ onLoad(async (options) => {
if (battleInfo) {
battleId.value = battleInfo.id;
players.value = [...battleInfo.blueTeam, ...battleInfo.redTeam];
if (battleInfo.startTime <= 0) return;
start.value = true;
players.value.forEach((p) => {
playersScores.value[p.id] = [...p.arrows];
if (p.id === user.value.id) {
@@ -67,18 +64,30 @@ onLoad(async (options) => {
}
});
const remain = Date.now() / 1000 - battleInfo.startTime;
// 这里的开始时间不是游戏开始时间,而是上半场或者下半场或者中场的开始时间,还要根据状态来判断
console.log(`当前局已进行${remain}`);
if (battleInfo.status === 0) {
if (remain > 0) {
setTimeout(() => {
uni.$emit("update-timer", 15 - remain);
}, 200);
}
} else {
start.value = true;
}
if (battleInfo.status === 2) {
tips.value = `${
battleInfo.halfGame ? "下半场-" : "上半场-"
}请连续射6箭`;
// 这里的开始时间不是游戏开始时间,而是上半场或者下半场或者中场的开始时间,还要根据状态来判断
tips.value = battleInfo.halfGame
? "下半场请再射6箭"
: "上半场请先射6箭";
setTimeout(() => {
uni.$emit("update-ramain", 90 - remain);
}, 300);
}, 200);
} else if (battleInfo.status === 9) {
startCount.value = false;
tips.value = "准备下半场";
setTimeout(() => {
uni.$emit("update-ramain", 0);
}, 200);
}
}
} else {
@@ -89,17 +98,10 @@ onLoad(async (options) => {
}
}
});
async function stopMatch() {
uni.$showHint(3);
}
async function readyToGo() {
if (battleId.value) {
await readyGameAPI(battleId.value);
scores.value = [];
start.value = true;
timerSeq.value = 0;
}
}
async function onReceiveMessage(messages = []) {
messages.forEach((msg) => {
@@ -113,7 +115,6 @@ async function onReceiveMessage(messages = []) {
if (msg.constructor === MESSAGETYPES.WaitForAllReady) {
onComplete.value = () => {
// 这里会掉多次;
timerSeq.value += 1;
battleId.value = msg.id;
players.value = [
...msg.groupUserStatus.redTeam,
@@ -130,8 +131,9 @@ async function onReceiveMessage(messages = []) {
start.value = true;
startCount.value = true;
seq.value += 1;
timerSeq.value = 0;
tips.value = `${scores.value.length ? "下半场-" : "上半场-"}请连续射6箭`;
tips.value = scores.value.length
? "下半场请再射6箭"
: "上半场请先射6箭";
halfTimeTip.value = false;
}
if (msg.constructor === MESSAGETYPES.ShootResult) {
@@ -218,7 +220,7 @@ onUnmounted(() => {
<BowTarget
v-if="start"
:currentRound="scores.length"
:totalRound="start ? 12 : 0"
:totalRound="12"
:scores="scores"
:stop="!startCount"
/>
@@ -232,7 +234,7 @@ onUnmounted(() => {
:scores="playersScores[player.id] || []"
/>
</view>
<Timer :seq="timerSeq" :callBack="readyToGo" />
<Timer v-if="!start" />
<ScreenHint
:show="halfTimeTip"
mode="small"
@@ -252,9 +254,6 @@ onUnmounted(() => {
/>
</block>
</view>
<!-- <view :style="{ marginBottom: '20px' }">
<SButton v-if="battleId && !start" :onClick="readyToGo">准备完毕</SButton>
</view> -->
</Container>
</template>