1v1流程调试完成
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup>
|
||||
import { ref, onUnmounted } from "vue";
|
||||
import { ref, onMounted, onUnmounted } from "vue";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import Container from "@/components/Container.vue";
|
||||
import PlayerSeats from "@/components/PlayerSeats.vue";
|
||||
@@ -30,33 +30,37 @@ onLoad(async (options) => {
|
||||
room.value = result;
|
||||
}
|
||||
});
|
||||
const startGame = async () => {
|
||||
const result = await startRoomAPI(room.value.number);
|
||||
console.log(result);
|
||||
step.value = 2;
|
||||
};
|
||||
|
||||
async function onReceiveMessage(content) {
|
||||
const messages = JSON.parse(content).data.updates || [];
|
||||
messages.forEach((msg) => {
|
||||
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
scores.value.push(msg.target);
|
||||
if (scores.value.length === total) {
|
||||
showScore.value = true;
|
||||
websocket.closeWebSocket();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
uni.$on("socket-inbox", onReceiveMessage);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
websocket.closeWebSocket();
|
||||
uni.$off("socket-inbox", onReceiveMessage);
|
||||
if (user.value.id === room.value.creator) {
|
||||
destroyRoomAPI(room.value.id);
|
||||
} else {
|
||||
exitRoomAPI(room.value.id);
|
||||
}
|
||||
});
|
||||
const startGame = async () => {
|
||||
const result = await startRoomAPI(room.value.number);
|
||||
console.log(result);
|
||||
step.value = 2;
|
||||
const token = uni.getStorageSync("token");
|
||||
|
||||
websocket.createWebSocket(token, (content) => {
|
||||
const messages = JSON.parse(content).data.updates || [];
|
||||
messages.forEach((msg) => {
|
||||
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
scores.value.push(msg.target);
|
||||
if (scores.value.length === total) {
|
||||
showScore.value = true;
|
||||
websocket.closeWebSocket();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user