2025-05-16 15:56:54 +08:00
|
|
|
|
<script setup>
|
2025-06-05 21:32:51 +08:00
|
|
|
|
import { ref, onMounted, onUnmounted } from "vue";
|
2025-05-30 16:14:17 +08:00
|
|
|
|
import { onLoad } from "@dcloudio/uni-app";
|
|
|
|
|
|
import Container from "@/components/Container.vue";
|
2025-06-04 16:26:07 +08:00
|
|
|
|
import PlayerSeats from "@/components/PlayerSeats.vue";
|
2025-05-16 15:56:54 +08:00
|
|
|
|
import Guide from "@/components/Guide.vue";
|
|
|
|
|
|
import SButton from "@/components/SButton.vue";
|
|
|
|
|
|
import BowTarget from "@/components/BowTarget.vue";
|
|
|
|
|
|
import BattleHeader from "@/components/BattleHeader.vue";
|
|
|
|
|
|
import BattleFooter from "@/components/BattleFooter.vue";
|
|
|
|
|
|
import BowPower from "@/components/BowPower.vue";
|
|
|
|
|
|
import ShootProgress from "@/components/ShootProgress.vue";
|
|
|
|
|
|
import PlayersRow from "@/components/PlayersRow.vue";
|
2025-05-30 16:14:17 +08:00
|
|
|
|
import { getRoomAPI, destroyRoomAPI, exitRoomAPI, startRoomAPI } from "@/apis";
|
|
|
|
|
|
import { MESSAGETYPES } from "@/constants";
|
|
|
|
|
|
import websocket from "@/websocket";
|
|
|
|
|
|
import useStore from "@/store";
|
|
|
|
|
|
import { storeToRefs } from "pinia";
|
|
|
|
|
|
const store = useStore();
|
|
|
|
|
|
const { user } = storeToRefs(store);
|
2025-06-04 16:26:07 +08:00
|
|
|
|
const step = ref(3);
|
2025-05-30 16:14:17 +08:00
|
|
|
|
const room = ref({});
|
|
|
|
|
|
const roomNumber = ref("");
|
2025-05-16 15:56:54 +08:00
|
|
|
|
const players = new Array(7).fill(1);
|
2025-05-30 13:58:43 +08:00
|
|
|
|
const teams = [{ name: "选手1", avatar: "../static/avatar.png" }];
|
2025-05-30 16:14:17 +08:00
|
|
|
|
onLoad(async (options) => {
|
|
|
|
|
|
if (options.roomNumber) {
|
|
|
|
|
|
roomNumber.value = options.roomNumber;
|
|
|
|
|
|
const result = await getRoomAPI(options.roomNumber);
|
|
|
|
|
|
room.value = result;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
const startGame = async () => {
|
|
|
|
|
|
const result = await startRoomAPI(room.value.number);
|
|
|
|
|
|
console.log(result);
|
|
|
|
|
|
step.value = 2;
|
2025-06-05 21:32:51 +08:00
|
|
|
|
};
|
2025-05-30 16:14:17 +08:00
|
|
|
|
|
2025-06-05 21:32:51 +08:00
|
|
|
|
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();
|
2025-05-30 16:14:17 +08:00
|
|
|
|
}
|
2025-06-05 21:32:51 +08:00
|
|
|
|
}
|
2025-05-30 16:14:17 +08:00
|
|
|
|
});
|
2025-06-05 21:32:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
uni.$on("socket-inbox", onReceiveMessage);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
uni.$off("socket-inbox", onReceiveMessage);
|
|
|
|
|
|
if (user.value.id === room.value.creator) {
|
|
|
|
|
|
destroyRoomAPI(room.value.id);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
exitRoomAPI(room.value.id);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-05-16 15:56:54 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-05-30 16:14:17 +08:00
|
|
|
|
<Container title="对战">
|
|
|
|
|
|
<view class="standby-phase" v-if="step === 1">
|
2025-05-16 15:56:54 +08:00
|
|
|
|
<Guide>
|
|
|
|
|
|
<view :style="{ display: 'flex', flexDirection: 'column' }">
|
|
|
|
|
|
<text :style="{ color: '#fed847' }">人都到齐了吗?</text>
|
|
|
|
|
|
<text>天赋异禀的弓箭手们,比赛即将开始!</text>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</Guide>
|
2025-05-30 16:14:17 +08:00
|
|
|
|
<view v-if="room.battleType === 1 && room.count === 2" class="one-on-one">
|
|
|
|
|
|
<image src="../static/1v1-bg.png" mode="widthFix" />
|
|
|
|
|
|
<view>
|
|
|
|
|
|
<image :src="user.avatarUrl" mode="widthFix" />
|
|
|
|
|
|
<image src="../static/versus.png" mode="widthFix" />
|
|
|
|
|
|
<view>
|
|
|
|
|
|
<image src="../static/question-mark.png" mode="widthFix" />
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
2025-06-04 16:26:07 +08:00
|
|
|
|
<PlayerSeats
|
|
|
|
|
|
v-if="room.battleType === 2 && room.count === 10"
|
|
|
|
|
|
:players="players"
|
|
|
|
|
|
/>
|
2025-05-30 16:14:17 +08:00
|
|
|
|
<view>
|
|
|
|
|
|
<SButton
|
|
|
|
|
|
v-if="room.battleType === 1 && room.count === 2"
|
|
|
|
|
|
:onClick="startGame"
|
|
|
|
|
|
>进入对战</SButton
|
|
|
|
|
|
>
|
|
|
|
|
|
<SButton
|
|
|
|
|
|
v-if="room.battleType === 2 && room.count === 10"
|
|
|
|
|
|
:onClick="startGame"
|
|
|
|
|
|
>进入大乱斗</SButton
|
|
|
|
|
|
>
|
|
|
|
|
|
<text class="tips">创建者点击下一步,所有人即可进入游戏。</text>
|
|
|
|
|
|
</view>
|
2025-05-16 15:56:54 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
<view v-if="step === 2">
|
|
|
|
|
|
<BattleHeader />
|
|
|
|
|
|
<Guide noBg>
|
|
|
|
|
|
<view :style="{ display: 'flex', justifyContent: 'space-between' }">
|
|
|
|
|
|
<view :style="{ display: 'flex', flexDirection: 'column' }">
|
|
|
|
|
|
<text :style="{ color: '#fed847' }">请预先射几箭测试</text>
|
|
|
|
|
|
<text>请确保射击距离只有5米</text>
|
|
|
|
|
|
</view>
|
2025-05-30 13:58:43 +08:00
|
|
|
|
<BowPower :power="45" />
|
2025-05-16 15:56:54 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
</Guide>
|
|
|
|
|
|
<BowTarget tips="本次射程5.2米,已达距离要求" />
|
|
|
|
|
|
<SButton :onClick="() => (step = 3)">开始</SButton>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
<view v-if="step === 3">
|
|
|
|
|
|
<ShootProgress tips="请红队射箭-第一轮" />
|
|
|
|
|
|
<PlayersRow :blueTeam="teams" :redTeam="teams" />
|
2025-06-04 16:26:07 +08:00
|
|
|
|
<BowTarget :power="45" :currentRound="1" :totalRound="3" debug />
|
2025-05-16 15:56:54 +08:00
|
|
|
|
<BattleFooter :blueTeam="[6, 2, 3]" :redTeam="[4, 5, 2]" />
|
|
|
|
|
|
</view>
|
2025-05-30 16:14:17 +08:00
|
|
|
|
</Container>
|
2025-05-16 15:56:54 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2025-05-30 16:14:17 +08:00
|
|
|
|
.standby-phase {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: calc(100% - 40px);
|
|
|
|
|
|
overflow-x: hidden;
|
2025-05-16 15:56:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
.founder {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
background-color: #fed847;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
color: #000;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
padding: 2px 5px;
|
|
|
|
|
|
border-top-left-radius: 10px;
|
|
|
|
|
|
border-bottom-right-radius: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.player-bg {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
width: 52px;
|
|
|
|
|
|
right: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
.tips {
|
|
|
|
|
|
color: #fff9;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.player-unknow {
|
|
|
|
|
|
width: 40px;
|
|
|
|
|
|
height: 40px;
|
|
|
|
|
|
margin: 0 10px;
|
|
|
|
|
|
border: 1px solid #fff3;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
background-color: #69686866;
|
|
|
|
|
|
}
|
|
|
|
|
|
.player-unknow > image {
|
|
|
|
|
|
width: 40%;
|
|
|
|
|
|
}
|
2025-05-30 16:14:17 +08:00
|
|
|
|
.one-on-one {
|
|
|
|
|
|
width: calc(100vw - 30px);
|
|
|
|
|
|
height: 120vw;
|
|
|
|
|
|
margin: 15px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.one-on-one > image:first-child {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
width: calc(100vw - 30px);
|
|
|
|
|
|
z-index: -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
.one-on-one > view {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
height: 95%;
|
|
|
|
|
|
}
|
|
|
|
|
|
.one-on-one > view > image:first-child {
|
|
|
|
|
|
width: 70px;
|
|
|
|
|
|
transform: translateY(-45px);
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
}
|
|
|
|
|
|
.one-on-one > view > image:nth-child(2) {
|
|
|
|
|
|
width: 120px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.one-on-one > view > view:nth-child(3) {
|
|
|
|
|
|
width: 70px;
|
|
|
|
|
|
height: 70px;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
background-color: #ccc;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
transform: translateY(45px);
|
|
|
|
|
|
}
|
|
|
|
|
|
.one-on-one > view > view:nth-child(3) > image {
|
|
|
|
|
|
width: 25px;
|
|
|
|
|
|
height: 25px;
|
|
|
|
|
|
margin-right: 2px;
|
|
|
|
|
|
}
|
2025-05-16 15:56:54 +08:00
|
|
|
|
</style>
|