Files
shoot-miniprograms/src/pages/battle-room.vue

829 lines
24 KiB
Vue
Raw Normal View History

2025-05-16 15:56:54 +08:00
<script setup>
2025-07-11 12:03:55 +08:00
import { ref, watch, onMounted, onUnmounted } from "vue";
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
2025-05-30 16:14:17 +08:00
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";
2025-06-13 14:05:30 +08:00
import Timer from "@/components/Timer.vue";
2025-05-16 15:56:54 +08:00
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-06-17 16:42:53 +08:00
import SModal from "@/components/SModal.vue";
2025-06-22 15:04:10 +08:00
import ScreenHint from "@/components/ScreenHint.vue";
2025-07-02 15:57:58 +08:00
import RoundEndTip from "@/components/RoundEndTip.vue";
2025-07-05 14:52:41 +08:00
import TestDistance from "@/components/TestDistance.vue";
2025-07-15 17:10:41 +08:00
import PlayerScore from "@/components/PlayerScore.vue";
import {
getRoomAPI,
destroyRoomAPI,
exitRoomAPI,
startRoomAPI,
getCurrentGameAPI,
} from "@/apis";
import { isGameEnded } from "@/util";
2025-06-22 15:04:10 +08:00
import { MESSAGETYPES, roundsName, getMessageTypeName } from "@/constants";
2025-05-30 16:14:17 +08:00
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
2025-06-11 23:57:17 +08:00
const step = ref(1);
2025-06-13 14:05:30 +08:00
const seq = ref(0);
const battleId = ref("");
2025-05-30 16:14:17 +08:00
const room = ref({});
const roomNumber = ref("");
2025-06-13 14:05:30 +08:00
const owner = ref({});
2025-06-11 23:57:17 +08:00
const opponent = ref({});
2025-06-13 14:05:30 +08:00
const redTeam = ref([]);
const blueTeam = ref([]);
const currentShooterId = ref(0);
const players = ref([]);
2025-07-11 12:03:55 +08:00
const playersSorted = ref([]);
2025-06-13 14:05:30 +08:00
const currentRound = ref(1);
const totalRounds = ref(0);
2025-06-11 23:57:17 +08:00
const start = ref(false);
2025-07-17 17:02:05 +08:00
const startCount = ref(true);
2025-06-11 23:57:17 +08:00
const power = ref(0);
const scores = ref([]);
2025-06-26 22:54:17 +08:00
const blueScores = ref([]);
2025-06-13 14:05:30 +08:00
const tips = ref("即将开始...");
const roundResults = ref([]);
const redPoints = ref(0);
const bluePoints = ref(0);
2025-06-22 15:04:10 +08:00
const currentRedPoint = ref(0);
const currentBluePoint = ref(0);
const showRoundTip = ref(false);
2025-06-13 14:05:30 +08:00
const playersScores = ref({});
2025-06-17 16:42:53 +08:00
const showModal = ref(false);
2025-06-26 22:54:17 +08:00
const halfTimeTip = ref(false);
2025-07-06 00:42:10 +08:00
const isFinalShoot = ref(false);
2025-07-15 17:10:41 +08:00
const total = ref(15);
2025-07-16 12:09:27 +08:00
const battleType = ref(0);
const isEnded = ref(false);
2025-06-26 22:54:17 +08:00
2025-07-11 12:03:55 +08:00
watch(
() => [players.value, playersScores.value],
([n_players, n_scores]) => {
if (n_players.length) {
playersSorted.value = Object.keys(n_scores)
.sort((a, b) => n_scores[b].length - n_scores[a].length)
.map((pid) => n_players.find((p) => p.id == pid));
}
},
{
deep: true, // 添加深度监听
immediate: true,
}
);
function recoverData(battleInfo) {
2025-07-23 11:18:47 +08:00
uni.removeStorageSync("last-awake-time");
battleId.value = battleInfo.id;
battleType.value = battleInfo.config.mode;
step.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);
}
return;
} else {
step.value = 3;
start.value = true;
}
if (battleInfo.config.mode === 1) {
redTeam.value = battleInfo.redTeam;
blueTeam.value = battleInfo.blueTeam;
if (battleInfo.status !== 0) {
2025-07-23 11:51:53 +08:00
bluePoints.value = 0;
redPoints.value = 0;
currentRound.value = battleInfo.currentRound;
totalRounds.value = battleInfo.maxRound;
roundResults.value = battleInfo.roundResults;
battleInfo.roundResults.forEach((round) => {
2025-07-23 16:01:16 +08:00
const blueTotal = round.blueArrows.reduce(
(last, next) => last + next.ring,
0
);
const redTotal = round.redArrows.reduce(
(last, next) => last + next.ring,
0
);
if (blueTotal === redTotal) {
bluePoints.value += 1;
redPoints.value += 1;
} else if (blueTotal > redTotal) {
bluePoints.value += 2;
} else {
redPoints.value += 2;
2025-07-13 21:06:48 +08:00
}
});
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);
2025-07-13 21:06:48 +08:00
}
}, 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: [],
2025-07-13 21:06:48 +08:00
});
}
2025-07-03 21:13:55 +08:00
}
2025-07-23 11:18:47 +08:00
// 这个状态不准
// if (battleInfo.status !== 11) return;
if (battleInfo.firePlayerIndex) {
currentShooterId.value = battleInfo.firePlayerIndex;
if (redTeam.value[0].id === currentShooterId.value) {
tips.value = `请红队射箭-第${roundsName[currentRound.value]}`;
} else {
tips.value = `请蓝队射箭-第${roundsName[currentRound.value]}`;
}
}
if (battleInfo.fireTime > 0) {
const remain = Date.now() / 1000 - battleInfo.fireTime;
console.log(`当前箭已过${remain}`);
if (remain > 0 && remain < 15) {
// 等渲染好再通知
setTimeout(() => {
uni.$emit("update-ramain", 15 - remain);
}, 300);
}
}
} else if (battleInfo.config.mode === 2) {
total.value = 90;
players.value = [...battleInfo.blueTeam, ...battleInfo.redTeam];
players.value.forEach((p) => {
playersScores.value[p.id] = [...p.arrows];
2025-07-22 17:58:22 +08:00
if (p.id === user.value.id) scores.value = [...p.arrows];
});
if (battleInfo.status === 2) {
startCount.value = true;
const remain = Date.now() / 1000 - battleInfo.startTime;
console.log(`当前局已进行${remain}`);
tips.value = battleInfo.halfGame
? "下半场请再射6箭"
: "上半场请先射6箭";
setTimeout(() => {
uni.$emit("update-ramain", 90 - remain);
}, 300);
} else if (battleInfo.status === 9) {
startCount.value = false;
tips.value = "准备下半场";
setTimeout(() => {
uni.$emit("update-ramain", 0);
}, 300);
}
}
}
onLoad(async (options) => {
if (options.battleId) {
const battleInfo = uni.getStorageSync("current-battle");
2025-07-23 11:18:47 +08:00
if (battleInfo) recoverData(battleInfo);
setTimeout(getCurrentGameAPI, 2000);
2025-07-03 21:13:55 +08:00
}
2025-06-13 14:05:30 +08:00
if (options.roomNumber) {
2025-05-30 16:14:17 +08:00
roomNumber.value = options.roomNumber;
2025-06-13 14:05:30 +08:00
const result = await getRoomAPI(options.roomNumber);
2025-05-30 16:14:17 +08:00
room.value = result;
2025-07-16 12:09:27 +08:00
battleType.value = result.battleType;
2025-06-13 14:05:30 +08:00
result.members.some((m) => {
if (m.userInfo.id === result.creator) {
owner.value = {
id: m.userInfo.id,
name: m.userInfo.name,
avatar: m.userInfo.avatar,
};
return true;
}
return false;
});
2025-06-16 22:43:39 +08:00
if (result.battleType === 1) {
2025-06-13 14:05:30 +08:00
if (user.value.id !== owner.value.id) {
opponent.value = {
id: user.value.id,
name: user.value.nickName,
2025-06-17 13:47:33 +08:00
avatar: user.value.avatar,
2025-06-13 14:05:30 +08:00
};
} else if (result.members.length > 1) {
result.members.some((m) => {
if (m.userInfo.id !== owner.value.id) {
opponent.value = {
id: m.userInfo.id,
name: m.userInfo.name,
avatar: m.userInfo.avatar,
};
return true;
}
return false;
});
}
2025-06-16 22:43:39 +08:00
} else if (result.battleType === 2) {
2025-07-15 17:10:41 +08:00
const ownerIndex = result.members.findIndex(
(m) => m.userInfo.id === result.creator
);
if (ownerIndex !== -1) {
players.value.push(result.members[ownerIndex].userInfo);
} else {
players.value.push({});
}
result.members.forEach((m, index) => {
if (ownerIndex !== index) players.value.push(m.userInfo);
2025-06-16 22:43:39 +08:00
});
2025-06-13 14:05:30 +08:00
}
2025-05-30 16:14:17 +08:00
}
});
2025-07-15 17:10:41 +08:00
2025-05-30 16:14:17 +08:00
const startGame = async () => {
const result = await startRoomAPI(room.value.number);
step.value = 2;
2025-06-05 21:32:51 +08:00
};
2025-05-30 16:14:17 +08:00
2025-06-19 21:03:33 +08:00
async function onReceiveMessage(messages = []) {
2025-06-05 21:32:51 +08:00
messages.forEach((msg) => {
2025-06-13 14:05:30 +08:00
if (
msg.roomNumber === roomNumber.value ||
2025-06-16 12:01:11 +08:00
(battleId.value && msg.id === battleId.value) ||
2025-06-13 14:05:30 +08:00
msg.constructor === MESSAGETYPES.WaitForAllReady
) {
2025-06-22 15:04:10 +08:00
console.log("收到消息:", getMessageTypeName(msg.constructor), msg);
2025-06-13 14:05:30 +08:00
}
if (msg.constructor === MESSAGETYPES.WaitForAllReady) {
// 这里会掉多次;
battleId.value = msg.id;
2025-07-15 17:10:41 +08:00
step.value = 2;
2025-07-16 12:09:27 +08:00
if (battleType.value === 1) {
2025-06-16 22:43:39 +08:00
redTeam.value = msg.groupUserStatus.redTeam;
blueTeam.value = msg.groupUserStatus.blueTeam;
2025-07-16 12:09:27 +08:00
} else if (battleType.value === 2) {
2025-07-15 17:10:41 +08:00
players.value = [
...msg.groupUserStatus.redTeam,
...msg.groupUserStatus.blueTeam,
];
players.value.forEach((p) => {
playersScores.value[p.id] = [];
});
2025-06-16 22:43:39 +08:00
}
2025-06-13 14:05:30 +08:00
}
if (msg.roomNumber === roomNumber.value) {
if (msg.constructor === MESSAGETYPES.UserEnterRoom) {
2025-07-16 12:09:27 +08:00
if (battleType.value === 1) {
2025-06-26 01:27:23 +08:00
if (msg.userId === room.value.creator) {
owner.value = {
id: msg.userId,
name: msg.name,
avatar: msg.avatar,
};
} else {
opponent.value = {
id: msg.userId,
name: msg.name,
avatar: msg.avatar,
};
}
2025-06-13 14:05:30 +08:00
}
2025-07-16 12:09:27 +08:00
if (battleType.value === 2) {
2025-07-15 17:10:41 +08:00
if (room.value.creator === msg.userId) {
players.value[0] = {
id: msg.userId,
name: msg.name,
avatar: msg.avatar,
};
} else {
players.value.push({
id: msg.userId,
name: msg.name,
avatar: msg.avatar,
});
}
2025-06-16 22:43:39 +08:00
}
2025-06-13 14:05:30 +08:00
}
2025-06-16 12:01:11 +08:00
if (!start.value && msg.constructor === MESSAGETYPES.UserExitRoom) {
2025-07-16 12:09:27 +08:00
if (battleType.value === 1) {
2025-06-26 01:27:23 +08:00
if (msg.userId === room.value.creator) {
owner.value = {
id: "",
};
} else {
opponent.value = {
id: "",
};
}
2025-06-13 14:05:30 +08:00
}
2025-07-16 12:09:27 +08:00
if (battleType.value === 2) {
2025-06-16 22:43:39 +08:00
players.value = players.value.filter((p) => p.id !== msg.userId);
}
2025-06-13 14:05:30 +08:00
}
2025-06-26 22:54:17 +08:00
if (msg.constructor === MESSAGETYPES.RoomDestroy && !battleId.value) {
2025-06-13 14:05:30 +08:00
uni.showToast({
title: "房间已解散",
icon: "none",
});
2025-06-16 12:01:11 +08:00
roomNumber.value = "";
2025-06-13 14:05:30 +08:00
setTimeout(() => {
uni.navigateBack();
}, 1000);
}
}
if (msg.id === battleId.value) {
if (msg.constructor === MESSAGETYPES.AllReady) {
start.value = true;
totalRounds.value = msg.groupUserStatus.config.maxRounds;
step.value = 3;
2025-07-18 11:21:19 +08:00
roundResults.value.push({
redArrows: [],
blueArrows: [],
});
2025-07-15 17:10:41 +08:00
total.value = 15;
2025-06-13 14:05:30 +08:00
}
2025-06-26 22:54:17 +08:00
if (msg.constructor === MESSAGETYPES.MeleeAllReady) {
start.value = true;
2025-07-17 17:02:05 +08:00
startCount.value = true;
2025-07-15 17:10:41 +08:00
step.value = 3;
2025-06-26 22:54:17 +08:00
seq.value += 1;
2025-07-21 10:40:43 +08:00
tips.value = scores.value.length
? "下半场请再射6箭"
: "上半场请先射6箭";
2025-07-15 17:10:41 +08:00
total.value = 90;
2025-07-16 17:55:11 +08:00
halfTimeTip.value = false;
2025-06-26 22:54:17 +08:00
}
2025-06-13 14:05:30 +08:00
if (msg.constructor === MESSAGETYPES.ToSomeoneShoot) {
2025-07-16 12:09:27 +08:00
if (battleType.value === 1) {
2025-06-28 12:03:33 +08:00
if (currentShooterId.value !== msg.userId) {
seq.value += 1;
currentShooterId.value = msg.userId;
if (redTeam.value[0].id === currentShooterId.value) {
2025-07-06 00:42:10 +08:00
tips.value = "请红队射箭-";
2025-06-28 12:03:33 +08:00
} else {
2025-07-06 00:42:10 +08:00
tips.value = "请蓝队射箭-";
}
if (isFinalShoot.value) {
tips.value += "决金箭";
} else {
tips.value += `${roundsName[currentRound.value]}`;
2025-06-28 12:03:33 +08:00
}
2025-06-16 22:43:39 +08:00
}
2025-06-13 14:05:30 +08:00
}
}
if (msg.constructor === MESSAGETYPES.ShootResult) {
2025-07-16 12:09:27 +08:00
if (battleType.value === 1) {
2025-07-23 11:18:47 +08:00
// 会有蓝队射箭时间,红队射箭也有结果返回的情况
if (currentShooterId.value !== msg.userId) return;
2025-06-26 22:54:17 +08:00
const isRed = redTeam.value.find((item) => item.id === msg.userId);
2025-07-16 09:33:33 +08:00
if (isRed) scores.value.push(msg.target);
else blueScores.value.push(msg.target);
2025-07-11 12:03:55 +08:00
if (roundResults.value[currentRound.value - 1]) {
if (isRed && roundResults.value[currentRound.value - 1].redArrows) {
roundResults.value[currentRound.value - 1].redArrows.push(
msg.target
);
}
if (
!isRed &&
roundResults.value[currentRound.value - 1].blueArrows
) {
roundResults.value[currentRound.value - 1].blueArrows.push(
msg.target
);
}
2025-07-13 14:57:16 +08:00
} else {
roundResults.value.push({
redArrows: [],
blueArrows: [],
});
2025-07-11 12:03:55 +08:00
}
2025-06-16 22:43:39 +08:00
}
2025-07-18 15:04:29 +08:00
if (battleType.value === 2 && msg.userId === user.value.id) {
2025-07-19 16:16:53 +08:00
scores.value.push({ ...msg.target });
2025-06-16 22:43:39 +08:00
power.value = msg.target.battery;
}
2025-06-22 15:04:10 +08:00
if (playersScores.value[msg.userId])
2025-07-19 16:16:53 +08:00
playersScores.value[msg.userId].push({ ...msg.target });
2025-06-13 14:05:30 +08:00
}
if (msg.constructor === MESSAGETYPES.CurrentRoundEnded) {
2025-07-16 12:09:27 +08:00
if (battleType.value === 1) {
2025-06-26 22:54:17 +08:00
const result = msg.preRoundResult;
scores.value = [];
blueScores.value = [];
currentShooterId.value = 0;
currentBluePoint.value = result.blueScore;
currentRedPoint.value = result.redScore;
bluePoints.value += result.blueScore;
redPoints.value += result.redScore;
2025-07-06 00:42:10 +08:00
currentRound.value = result.currentRound + 1;
2025-07-16 12:09:27 +08:00
uni.$emit("update-ramain", 0);
2025-07-11 22:21:34 +08:00
if (result.currentRound < 5) {
roundResults.value.push({
redArrows: [],
blueArrows: [],
});
showRoundTip.value = true;
}
2025-06-13 14:05:30 +08:00
}
}
2025-07-06 00:42:10 +08:00
if (msg.constructor === MESSAGETYPES.FinalShoot) {
2025-07-10 19:55:30 +08:00
if (!isFinalShoot.value) {
isFinalShoot.value = true;
showRoundTip.value = true;
tips.value = "准备开始决金箭";
}
2025-07-06 00:42:10 +08:00
}
2025-06-26 22:54:17 +08:00
if (msg.constructor === MESSAGETYPES.HalfTimeOver) {
2025-07-17 16:14:30 +08:00
uni.$emit("update-ramain", 0);
2025-07-16 18:18:02 +08:00
[
...msg.groupUserStatus.redTeam,
...msg.groupUserStatus.blueTeam,
].forEach((player) => {
2025-07-22 17:58:22 +08:00
playersScores.value[player.id] = [...player.arrows];
if (player.id === user.value.id) scores.value = [...player.arrows];
2025-07-16 18:18:02 +08:00
});
2025-06-26 22:54:17 +08:00
startCount.value = false;
halfTimeTip.value = true;
tips.value = "准备下半场";
}
2025-06-13 14:05:30 +08:00
if (msg.constructor === MESSAGETYPES.MatchOver) {
2025-07-23 14:31:21 +08:00
if (msg.endStatus.noSaved) {
2025-07-25 09:59:54 +08:00
// uni.showToast({
// title: "本场比赛无人射箭,已取消",
// icon: "none",
// });
currentBluePoint.value = 0;
currentRedPoint.value = 0;
2025-07-23 16:01:16 +08:00
setTimeout(() => {
uni.navigateBack();
}, 1500);
2025-07-16 16:09:10 +08:00
} else {
isEnded.value = true;
2025-07-25 09:59:54 +08:00
uni.setStorageSync("last-battle", msg.endStatus);
2025-07-23 16:01:16 +08:00
setTimeout(() => {
uni.redirectTo({
2025-07-23 20:47:31 +08:00
url: "/pages/battle-result",
2025-07-23 16:01:16 +08:00
});
}, 1500);
2025-07-16 16:09:10 +08:00
}
2025-05-30 16:14:17 +08:00
}
if (msg.constructor === MESSAGETYPES.BackToGame) {
2025-07-23 11:18:47 +08:00
uni.$emit("update-header-loading", false);
if (msg.battleInfo) recoverData(msg.battleInfo);
}
2025-06-05 21:32:51 +08:00
}
2025-05-30 16:14:17 +08:00
});
2025-06-05 21:32:51 +08:00
}
2025-06-17 16:42:53 +08:00
const destroyRoom = async () => {
2025-06-22 15:04:10 +08:00
if (roomNumber.value) await destroyRoomAPI(roomNumber.value);
2025-06-17 16:42:53 +08:00
};
const exitRoom = async () => {
uni.navigateBack();
};
2025-07-07 14:39:11 +08:00
const setClipboardData = () => {
uni.setClipboardData({
data: roomNumber.value,
success() {
uni.showToast({ title: "复制成功" });
},
});
};
2025-07-11 00:47:34 +08:00
const onBack = () => {
if (battleId.value) {
uni.$showHint(2);
} else {
showModal.value = true;
}
};
2025-06-05 21:32:51 +08:00
onMounted(() => {
2025-07-13 11:21:19 +08:00
uni.setKeepScreenOn({
keepScreenOn: true,
});
2025-06-05 21:32:51 +08:00
uni.$on("socket-inbox", onReceiveMessage);
});
onUnmounted(() => {
2025-07-13 11:21:19 +08:00
uni.setKeepScreenOn({
keepScreenOn: false,
});
2025-06-05 21:32:51 +08:00
uni.$off("socket-inbox", onReceiveMessage);
2025-07-23 17:10:34 +08:00
if (roomNumber.value && owner.value.id !== user.value.id && !battleId.value) {
2025-06-15 20:55:34 +08:00
exitRoomAPI(roomNumber.value);
2025-06-05 21:32:51 +08:00
}
});
2025-07-23 20:47:31 +08:00
2025-07-23 11:18:47 +08:00
const refreshTimer = ref(null);
onShow(async () => {
if (battleId.value) {
2025-07-25 09:59:54 +08:00
if (!isEnded.value && (await isGameEnded(battleId.value))) return;
2025-07-23 11:18:47 +08:00
getCurrentGameAPI();
const refreshData = () => {
const lastAwakeTime = uni.getStorageSync("last-awake-time");
if (lastAwakeTime) {
getCurrentGameAPI();
} else {
clearInterval(refreshTimer.value);
}
};
refreshTimer.value = setInterval(refreshData, 2000);
}
});
onHide(() => {
2025-07-23 11:18:47 +08:00
if (refreshTimer.value) clearInterval(refreshTimer.value);
uni.setStorageSync("last-awake-time", Date.now());
});
2025-05-16 15:56:54 +08:00
</script>
<template>
<Container title="对战" :onBack="onBack" :bgType="battleId ? 1 : 0">
2025-05-30 16:14:17 +08:00
<view class="standby-phase" v-if="step === 1">
2025-05-16 15:56:54 +08:00
<Guide>
2025-07-07 14:39:11 +08:00
<view class="battle-guide">
<view :style="{ display: 'flex', flexDirection: 'column' }">
<text :style="{ color: '#fed847' }">弓箭手们人都到齐了吗?</text>
2025-07-16 12:09:27 +08:00
<text v-if="battleType === 1">1v1比赛即将开始! </text>
<text v-if="battleType === 2">大乱斗即将开始! </text>
2025-07-07 14:39:11 +08:00
</view>
<view @click="setClipboardData">邀请好友</view>
2025-05-16 15:56:54 +08:00
</view>
</Guide>
2025-07-16 12:09:27 +08:00
<view v-if="battleType === 1" class="team-mode">
2025-05-30 16:14:17 +08:00
<image src="../static/1v1-bg.png" mode="widthFix" />
<view>
2025-06-13 14:05:30 +08:00
<view class="player" :style="{ transform: 'translateY(-60px)' }">
2025-07-11 22:21:34 +08:00
<image
:src="owner.avatar || '../static/user-icon.png'"
mode="widthFix"
/>
2025-06-13 14:05:30 +08:00
<text>{{ owner.name }}</text>
2025-05-30 16:14:17 +08:00
</view>
2025-06-13 14:05:30 +08:00
<image src="../static/versus.png" mode="widthFix" />
<block v-if="opponent.id">
<view class="player" :style="{ transform: 'translateY(60px)' }">
2025-07-11 22:21:34 +08:00
<image
:src="opponent.avatar || '../static/user-icon.png'"
mode="widthFix"
/>
2025-06-13 14:05:30 +08:00
<text v-if="opponent.name">{{ opponent.name }}</text>
</view>
</block>
<block v-else>
<view class="no-player">
<image src="../static/question-mark.png" mode="widthFix" />
</view>
</block>
2025-05-30 16:14:17 +08:00
</view>
</view>
2025-06-04 16:26:07 +08:00
<PlayerSeats
2025-07-16 12:09:27 +08:00
v-if="battleType === 2"
2025-06-16 22:43:39 +08:00
:total="room.count || 10"
2025-06-04 16:26:07 +08:00
:players="players"
/>
2025-06-13 14:05:30 +08:00
<view>
2025-05-30 16:14:17 +08:00
<SButton
2025-07-16 12:09:27 +08:00
v-if="user.id === owner.id && battleType === 1"
2025-06-16 12:01:11 +08:00
:disabled="!opponent.id"
2025-05-30 16:14:17 +08:00
:onClick="startGame"
>进入对战</SButton
>
<SButton
2025-07-16 12:09:27 +08:00
v-if="user.id === owner.id && battleType === 2"
2025-07-15 17:10:41 +08:00
:disabled="players.length < 3"
2025-05-30 16:14:17 +08:00
:onClick="startGame"
>进入大乱斗</SButton
>
2025-06-13 14:05:30 +08:00
<SButton v-if="user.id !== owner.id" disabled>等待房主开启对战</SButton>
2025-05-30 16:14:17 +08:00
<text class="tips">创建者点击下一步所有人即可进入游戏</text>
</view>
2025-05-16 15:56:54 +08:00
</view>
2025-06-13 14:05:30 +08:00
<view v-if="step === 2" :style="{ width: '100%' }">
<BattleHeader
:blueTeam="blueTeam"
:redTeam="redTeam"
:players="players"
/>
2025-07-05 14:52:41 +08:00
<TestDistance :guide="false" />
2025-07-21 10:40:43 +08:00
<Timer />
2025-05-16 15:56:54 +08:00
</view>
2025-07-15 17:10:41 +08:00
<view v-if="step === 3" :style="{ width: '100%' }">
2025-06-26 22:54:17 +08:00
<ShootProgress
:tips="tips"
:seq="seq"
2025-07-23 11:18:47 +08:00
:start="players.length > 0 && start && startCount"
2025-06-26 22:54:17 +08:00
:total="total"
2025-07-14 22:39:53 +08:00
:currentRound="currentRound"
:battleId="battleId"
2025-07-15 18:14:59 +08:00
:melee="players.length > 0"
2025-06-26 22:54:17 +08:00
/>
2025-06-13 14:05:30 +08:00
<PlayersRow
2025-07-15 18:14:59 +08:00
v-if="blueTeam.length && redTeam.length"
2025-06-13 14:05:30 +08:00
:blueTeam="blueTeam"
:redTeam="redTeam"
:currentShooterId="currentShooterId"
/>
<BowTarget
2025-07-18 15:04:29 +08:00
:mode="battleType === 1 ? 'team' : 'solo'"
2025-06-26 22:54:17 +08:00
:power="start ? power : 0"
2025-07-23 16:01:16 +08:00
:currentRound="scores.length"
:totalRound="battleType === 1 ? 3 : totalRounds"
2025-06-13 14:05:30 +08:00
:scores="scores"
2025-06-26 22:54:17 +08:00
:blueScores="blueScores"
2025-07-18 15:04:29 +08:00
:stop="!startCount"
2025-06-13 14:05:30 +08:00
/>
<BattleFooter
2025-07-15 17:10:41 +08:00
v-if="roundResults.length"
2025-06-13 14:05:30 +08:00
:roundResults="roundResults"
:redPoints="redPoints"
:bluePoints="bluePoints"
/>
<PlayerScore
2025-07-15 17:10:41 +08:00
v-if="playersSorted.length"
2025-07-11 12:03:55 +08:00
v-for="(player, index) in playersSorted"
2025-06-13 14:05:30 +08:00
:key="index"
:name="player.name"
:avatar="player.avatar"
2025-06-28 12:03:33 +08:00
:scores="playersScores[player.id] || []"
2025-06-13 14:05:30 +08:00
/>
2025-05-16 15:56:54 +08:00
</view>
2025-07-07 14:39:11 +08:00
<ScreenHint
:show="showRoundTip"
:onClose="() => (showRoundTip = false)"
:mode="isFinalShoot ? 'tall' : 'normal'"
>
2025-07-02 15:57:58 +08:00
<RoundEndTip
2025-07-06 00:42:10 +08:00
:isFinal="isFinalShoot"
2025-07-02 15:57:58 +08:00
:round="currentRound - 1"
:bluePoint="currentBluePoint"
:redPoint="currentRedPoint"
2025-07-14 13:39:10 +08:00
:roundData="
roundResults[roundResults.length - 2]
? roundResults[roundResults.length - 2]
: []
"
2025-07-06 00:42:10 +08:00
:onAutoClose="() => (showRoundTip = false)"
2025-07-02 15:57:58 +08:00
/>
2025-06-22 15:04:10 +08:00
</ScreenHint>
2025-06-26 22:54:17 +08:00
<ScreenHint
:show="halfTimeTip"
mode="small"
:onClose="() => (halfTimeTip = false)"
>
<view class="half-time-tip">
<text>上半场结束休息一下吧:</text>
<text>20秒后开始下半场</text>
</view>
</ScreenHint>
2025-06-17 16:42:53 +08:00
<SModal :show="showModal" :onClose="() => (showModal = false)">
<view class="btns">
2025-06-28 12:46:41 +08:00
<block v-if="!battleId">
<SButton :onClick="exitRoom" width="200px" :rounded="20">
暂时离开
</SButton>
<block v-if="owner.id === user.id">
<view :style="{ height: '20px' }"></view>
<SButton :onClick="destroyRoom" width="200px" :rounded="20">
解散房间
</SButton>
</block>
</block>
<block v-else>
<SButton :onClick="exitRoom" width="200px" :rounded="20">
退出比赛
</SButton>
</block>
2025-06-17 16:42:53 +08:00
</view>
</SModal>
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
}
.tips {
color: #fff9;
width: 100%;
text-align: center;
display: block;
margin-top: 10px;
2025-06-16 22:43:39 +08:00
font-size: 12px;
2025-05-16 15:56:54 +08:00
}
.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-06-11 23:57:17 +08:00
.team-mode {
2025-05-30 16:14:17 +08:00
width: calc(100vw - 30px);
2025-07-07 14:39:11 +08:00
height: 125vw;
2025-05-30 16:14:17 +08:00
margin: 15px;
}
2025-06-11 23:57:17 +08:00
.team-mode > image:first-child {
2025-05-30 16:14:17 +08:00
position: absolute;
width: calc(100vw - 30px);
z-index: -1;
}
2025-06-11 23:57:17 +08:00
.team-mode > view {
2025-05-30 16:14:17 +08:00
display: flex;
justify-content: center;
align-items: center;
height: 95%;
}
2025-06-13 14:05:30 +08:00
.player {
2025-05-30 16:14:17 +08:00
width: 70px;
2025-06-13 14:05:30 +08:00
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
transform: translateY(-60px);
color: #fff9;
font-size: 14px;
}
.player > image {
width: 70px;
height: 70px;
2025-05-30 16:14:17 +08:00
border-radius: 50%;
2025-06-13 14:05:30 +08:00
background-color: #ccc;
margin-bottom: 5px;
2025-05-30 16:14:17 +08:00
}
2025-06-17 13:47:33 +08:00
.player > text {
width: 100px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: center;
}
2025-06-11 23:57:17 +08:00
.team-mode > view > image:nth-child(2) {
2025-05-30 16:14:17 +08:00
width: 120px;
}
2025-06-13 14:05:30 +08:00
.no-player {
2025-05-30 16:14:17 +08:00
width: 70px;
height: 70px;
border-radius: 50%;
background-color: #ccc;
display: flex;
justify-content: center;
align-items: center;
2025-06-13 14:05:30 +08:00
transform: translateY(60px);
2025-05-30 16:14:17 +08:00
}
2025-06-13 14:05:30 +08:00
.no-player > image {
width: 20px;
2025-05-30 16:14:17 +08:00
margin-right: 2px;
}
2025-06-17 16:42:53 +08:00
.btns {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
2025-07-07 14:39:11 +08:00
.battle-guide {
display: flex;
align-items: center;
justify-content: space-between;
}
.battle-guide > view:last-child {
color: #fed847;
border: 1px solid #fed847;
margin-right: 10px;
padding: 5px 12px;
border-radius: 20px;
position: relative;
}
2025-05-16 15:56:54 +08:00
</style>