初步完成返回游戏功能,待测试完善
This commit is contained in:
@@ -23,7 +23,7 @@ const { user } = storeToRefs(store);
|
||||
const gameType = ref(0);
|
||||
const teamSize = ref(0);
|
||||
const start = ref(false);
|
||||
const startCount = ref(false);
|
||||
const countDown = ref(90);
|
||||
const battleId = ref("");
|
||||
const currentRound = ref(1);
|
||||
const totalRounds = ref(0);
|
||||
@@ -39,10 +39,43 @@ const onComplete = ref(null);
|
||||
const showModal = ref(false);
|
||||
|
||||
onLoad(async (options) => {
|
||||
gameType.value = options.gameType;
|
||||
teamSize.value = options.teamSize;
|
||||
if (gameType.value && teamSize.value) {
|
||||
await matchGameAPI(true, gameType.value, teamSize.value);
|
||||
if (options.battleId) {
|
||||
const battleInfo = uni.getStorageSync(`battle-${options.battleId}`);
|
||||
console.log("----battleInfo", battleInfo);
|
||||
if (battleInfo) {
|
||||
battleId.value = battleInfo.id;
|
||||
start.value = true;
|
||||
tips.value = "请连续射出6支箭";
|
||||
players.value = [...battleInfo.blueTeam, ...battleInfo.redTeam];
|
||||
players.value.forEach((p) => {
|
||||
playersScores.value[p.id] = p.arrows;
|
||||
});
|
||||
if (battleInfo.startTime) {
|
||||
const remain = Date.now() / 1000 - battleInfo.startTime;
|
||||
if (remain <= 90) {
|
||||
setTimeout(() => {
|
||||
uni.$emit("update-ramain", remain);
|
||||
}, 300);
|
||||
} else if (remain > 90 && remain <= 110) {
|
||||
halfTimeTip.value = true;
|
||||
countDown.value = 20;
|
||||
tips.value = "准备下半场";
|
||||
setTimeout(() => {
|
||||
uni.$emit("update-ramain", 110 - remain);
|
||||
}, 300);
|
||||
} else if (remain > 110) {
|
||||
setTimeout(() => {
|
||||
uni.$emit("update-ramain", remain - 110);
|
||||
}, 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gameType.value = options.gameType;
|
||||
teamSize.value = options.teamSize;
|
||||
if (gameType.value && teamSize.value) {
|
||||
await matchGameAPI(true, gameType.value, teamSize.value);
|
||||
}
|
||||
}
|
||||
});
|
||||
async function stopMatch() {
|
||||
@@ -83,11 +116,11 @@ async function onReceiveMessage(messages = []) {
|
||||
if (msg.id !== battleId.value) return;
|
||||
if (msg.constructor === MESSAGETYPES.MeleeAllReady) {
|
||||
start.value = true;
|
||||
startCount.value = true;
|
||||
seq.value += 1;
|
||||
timerSeq.value = 0;
|
||||
tips.value = "请连续射出6支箭";
|
||||
scores.value = [];
|
||||
countDown.value = 90;
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.ShootResult) {
|
||||
if (msg.userId === user.value.id) {
|
||||
@@ -97,8 +130,8 @@ async function onReceiveMessage(messages = []) {
|
||||
playersScores.value[msg.userId].push(msg.target);
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.HalfTimeOver) {
|
||||
startCount.value = false;
|
||||
halfTimeTip.value = true;
|
||||
countDown.value = 20;
|
||||
tips.value = "准备下半场";
|
||||
}
|
||||
if (msg.constructor === MESSAGETYPES.MatchOver) {
|
||||
@@ -142,8 +175,9 @@ onUnmounted(() => {
|
||||
<ShootProgress
|
||||
v-if="start"
|
||||
:seq="seq"
|
||||
:start="startCount"
|
||||
:start="start"
|
||||
:tips="tips"
|
||||
:total="countDown"
|
||||
/>
|
||||
<view v-if="start" class="infos">
|
||||
<Avatar :src="user.avatar" :size="35" />
|
||||
@@ -220,7 +254,6 @@ onUnmounted(() => {
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding-top: 52px;
|
||||
}
|
||||
.half-time-tip > text:last-child {
|
||||
margin-top: 20px;
|
||||
|
||||
Reference in New Issue
Block a user