返回游戏流程完善
This commit is contained in:
@@ -14,7 +14,7 @@ import SButton from "@/components/SButton.vue";
|
||||
import Matching from "@/components/Matching.vue";
|
||||
import RoundEndTip from "@/components/RoundEndTip.vue";
|
||||
import TestDistance from "@/components/TestDistance.vue";
|
||||
import { matchGameAPI, readyGameAPI } from "@/apis";
|
||||
import { matchGameAPI } from "@/apis";
|
||||
import { MESSAGETYPES, roundsName, getMessageTypeName } from "@/constants";
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
@@ -36,7 +36,6 @@ const blueTeam = ref([]);
|
||||
const currentShooterId = ref(0);
|
||||
const tips = ref("即将开始...");
|
||||
const seq = ref(0);
|
||||
const timerSeq = ref(0);
|
||||
const roundResults = ref([]);
|
||||
const redPoints = ref(0);
|
||||
const bluePoints = ref(0);
|
||||
@@ -52,51 +51,61 @@ onLoad(async (options) => {
|
||||
battleId.value = battleInfo.id;
|
||||
redTeam.value = battleInfo.redTeam;
|
||||
blueTeam.value = battleInfo.blueTeam;
|
||||
if (battleInfo.startTime < 0) return;
|
||||
start.value = true;
|
||||
currentRound.value = battleInfo.currentRound;
|
||||
battleInfo.roundResults.forEach((round) => {
|
||||
if (round.blueTotal && round.redTotal) {
|
||||
if (round.blueTotal === round.redTotal) {
|
||||
bluePoints.value += 1;
|
||||
redPoints.value += 1;
|
||||
} else if (round.blueTotal > round.redTotal) {
|
||||
bluePoints.value += 2;
|
||||
} else {
|
||||
redPoints.value += 2;
|
||||
if (battleInfo.status === 0) {
|
||||
const readyRemain = Date.now() / 1000 - battleInfo.startTime;
|
||||
console.log(`当前局已进行${readyRemain}秒`);
|
||||
if (readyRemain > 0) {
|
||||
setTimeout(() => {
|
||||
uni.$emit("update-timer", 15 - readyRemain);
|
||||
}, 200);
|
||||
}
|
||||
} else {
|
||||
start.value = true;
|
||||
currentRound.value = battleInfo.currentRound;
|
||||
totalRounds.value = battleInfo.maxRound;
|
||||
roundResults.value = battleInfo.roundResults;
|
||||
battleInfo.roundResults.forEach((round) => {
|
||||
if (round.blueTotal && round.redTotal) {
|
||||
if (round.blueTotal === round.redTotal) {
|
||||
bluePoints.value += 1;
|
||||
redPoints.value += 1;
|
||||
} else if (round.blueTotal > round.redTotal) {
|
||||
bluePoints.value += 2;
|
||||
} else {
|
||||
redPoints.value += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
totalRounds.value = battleInfo.maxRound;
|
||||
roundResults.value = battleInfo.roundResults;
|
||||
setTimeout(() => {
|
||||
if (battleInfo.roundResults[battleInfo.roundResults.length - 1]) {
|
||||
scores.value = battleInfo.roundResults[
|
||||
battleInfo.roundResults.length - 1
|
||||
].redArrows.filter((item) => !!item.playerId);
|
||||
blueScores.value = battleInfo.roundResults[
|
||||
battleInfo.roundResults.length - 1
|
||||
].blueArrows.filter((item) => !!item.playerId);
|
||||
}
|
||||
}, 300);
|
||||
if (
|
||||
battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] ||
|
||||
battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound]
|
||||
) {
|
||||
roundResults.value.push({
|
||||
redArrows: battleInfo.redTeam[0].shotHistory[
|
||||
battleInfo.currentRound
|
||||
].filter((item) => !!item.playerId),
|
||||
blueArrows: battleInfo.blueTeam[0].shotHistory[
|
||||
battleInfo.currentRound
|
||||
].filter((item) => !!item.playerId),
|
||||
});
|
||||
} else if (battleInfo.currentRound < 5) {
|
||||
roundResults.value.push({
|
||||
redArrows: [],
|
||||
blueArrows: [],
|
||||
});
|
||||
setTimeout(() => {
|
||||
if (battleInfo.roundResults[battleInfo.roundResults.length - 1]) {
|
||||
scores.value = battleInfo.roundResults[
|
||||
battleInfo.roundResults.length - 1
|
||||
].redArrows.filter((item) => !!item.playerId);
|
||||
blueScores.value = battleInfo.roundResults[
|
||||
battleInfo.roundResults.length - 1
|
||||
].blueArrows.filter((item) => !!item.playerId);
|
||||
}
|
||||
}, 300);
|
||||
if (
|
||||
battleInfo.redTeam[0].shotHistory[battleInfo.currentRound] ||
|
||||
battleInfo.blueTeam[0].shotHistory[battleInfo.currentRound]
|
||||
) {
|
||||
roundResults.value.push({
|
||||
redArrows: battleInfo.redTeam[0].shotHistory[
|
||||
battleInfo.currentRound
|
||||
].filter((item) => !!item.playerId),
|
||||
blueArrows: battleInfo.blueTeam[0].shotHistory[
|
||||
battleInfo.currentRound
|
||||
].filter((item) => !!item.playerId),
|
||||
});
|
||||
} else if (battleInfo.currentRound < 5) {
|
||||
roundResults.value.push({
|
||||
redArrows: [],
|
||||
blueArrows: [],
|
||||
});
|
||||
}
|
||||
}
|
||||
if (battleInfo.status !== 11) return;
|
||||
if (battleInfo.firePlayerIndex) {
|
||||
currentShooterId.value = battleInfo.firePlayerIndex;
|
||||
if (redTeam.value[0].id === currentShooterId.value) {
|
||||
@@ -127,13 +136,6 @@ onLoad(async (options) => {
|
||||
async function stopMatch() {
|
||||
uni.$showHint(3);
|
||||
}
|
||||
async function readyToGo() {
|
||||
if (battleId.value) {
|
||||
await readyGameAPI(battleId.value);
|
||||
start.value = true;
|
||||
timerSeq.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
async function onReceiveMessage(messages = []) {
|
||||
messages.forEach((msg) => {
|
||||
@@ -147,7 +149,6 @@ async function onReceiveMessage(messages = []) {
|
||||
if (msg.constructor === MESSAGETYPES.WaitForAllReady) {
|
||||
// 这里会掉多次;
|
||||
onComplete.value = () => {
|
||||
timerSeq.value += 1;
|
||||
battleId.value = msg.id;
|
||||
redTeam.value = msg.groupUserStatus.redTeam;
|
||||
blueTeam.value = msg.groupUserStatus.blueTeam;
|
||||
@@ -157,8 +158,6 @@ async function onReceiveMessage(messages = []) {
|
||||
if (msg.id !== battleId.value) return;
|
||||
if (msg.constructor === MESSAGETYPES.AllReady) {
|
||||
start.value = true;
|
||||
timerSeq.value = 0;
|
||||
scores.value = [];
|
||||
totalRounds.value = msg.groupUserStatus.config.maxRounds;
|
||||
roundResults.value.push({
|
||||
redArrows: [],
|
||||
@@ -166,10 +165,6 @@ async function onReceiveMessage(messages = []) {
|
||||
});
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
|
||||
if (!start.value) {
|
||||
start.value = true;
|
||||
step.value = 3;
|
||||
}
|
||||
if (currentShooterId.value !== msg.userId) {
|
||||
seq.value += 1;
|
||||
currentShooterId.value = msg.userId;
|
||||
@@ -314,7 +309,7 @@ onUnmounted(() => {
|
||||
:redPoints="redPoints"
|
||||
:bluePoints="bluePoints"
|
||||
/>
|
||||
<Timer :seq="timerSeq" :callBack="readyToGo" />
|
||||
<Timer v-if="!start" />
|
||||
<ScreenHint
|
||||
:show="showRoundTip"
|
||||
:onClose="() => (showRoundTip = false)"
|
||||
@@ -342,9 +337,6 @@ onUnmounted(() => {
|
||||
/>
|
||||
</block>
|
||||
</view>
|
||||
<!-- <view :style="{ marginBottom: '20px' }">
|
||||
<SButton v-if="battleId && !start" :onClick="readyToGo">准备完毕</SButton>
|
||||
</view> -->
|
||||
</Container>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user