初步完成返回游戏功能,待测试完善
This commit is contained in:
@@ -172,4 +172,12 @@ button::after {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.modal {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from "vue";
|
import { ref, onMounted } from "vue";
|
||||||
|
import { onShow } from "@dcloudio/uni-app";
|
||||||
import AppBackground from "@/components/AppBackground.vue";
|
import AppBackground from "@/components/AppBackground.vue";
|
||||||
import Header from "@/components/Header.vue";
|
import Header from "@/components/Header.vue";
|
||||||
import ScreenHint from "@/components/ScreenHint.vue";
|
import ScreenHint from "@/components/ScreenHint.vue";
|
||||||
import { getCurrentGameAPI } from "@/apis";
|
import { getCurrentGameAPI } from "@/apis";
|
||||||
|
import { debounce } from "@/util";
|
||||||
defineProps({
|
defineProps({
|
||||||
title: {
|
title: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -29,20 +31,21 @@ defineProps({
|
|||||||
const isIos = ref(true);
|
const isIos = ref(true);
|
||||||
const showHint = ref(false);
|
const showHint = ref(false);
|
||||||
const hintType = ref(0);
|
const hintType = ref(0);
|
||||||
onMounted(() => {
|
|
||||||
const deviceInfo = uni.getDeviceInfo();
|
|
||||||
isIos.value = deviceInfo.osName === "ios";
|
|
||||||
});
|
|
||||||
const showGlobalHint = (type) => {
|
const showGlobalHint = (type) => {
|
||||||
hintType.value = type;
|
hintType.value = type;
|
||||||
showHint.value = true;
|
showHint.value = true;
|
||||||
};
|
};
|
||||||
uni.$showHint = showGlobalHint;
|
onMounted(() => {
|
||||||
|
const deviceInfo = uni.getDeviceInfo();
|
||||||
const backToGame = async () => {
|
isIos.value = deviceInfo.osName === "ios";
|
||||||
|
});
|
||||||
|
onShow(() => {
|
||||||
|
uni.$showHint = showGlobalHint;
|
||||||
|
showHint.value = false;
|
||||||
|
});
|
||||||
|
const backToGame = debounce(async () => {
|
||||||
const result = await getCurrentGameAPI();
|
const result = await getCurrentGameAPI();
|
||||||
console.log(111, result);
|
});
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const props = defineProps({
|
|||||||
const getContentHeight = () => {
|
const getContentHeight = () => {
|
||||||
if (props.mode === "tall") return "47vw";
|
if (props.mode === "tall") return "47vw";
|
||||||
if (props.mode === "square") return "74vw";
|
if (props.mode === "square") return "74vw";
|
||||||
return '36vw'
|
return "36vw";
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch, onUnmounted } from "vue";
|
import { ref, watch, onMounted, onUnmounted } from "vue";
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
start: {
|
start: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@@ -33,11 +33,14 @@ watch(
|
|||||||
(newVal) => {
|
(newVal) => {
|
||||||
if (newVal.includes("红队")) barColor.value = "#FF6060";
|
if (newVal.includes("红队")) barColor.value = "#FF6060";
|
||||||
if (newVal.includes("蓝队")) barColor.value = "#5FADFF";
|
if (newVal.includes("蓝队")) barColor.value = "#5FADFF";
|
||||||
|
},
|
||||||
|
{
|
||||||
|
immediate: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.seq,
|
() => [props.seq, props.total],
|
||||||
() => {
|
() => {
|
||||||
if (timer.value) clearInterval(timer.value);
|
if (timer.value) clearInterval(timer.value);
|
||||||
remain.value = props.total;
|
remain.value = props.total;
|
||||||
@@ -77,7 +80,16 @@ watch(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const updateRemain = (value) => {
|
||||||
|
remain.value = Math.floor(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
uni.$on("update-ramain", updateRemain);
|
||||||
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
uni.$off("update-ramain", updateRemain);
|
||||||
if (timer.value) clearInterval(timer.value);
|
if (timer.value) clearInterval(timer.value);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -67,6 +67,14 @@ onLoad(async (options) => {
|
|||||||
redPoints.value = battleInfo.redScore;
|
redPoints.value = battleInfo.redScore;
|
||||||
totalRounds.value = battleInfo.maxRound;
|
totalRounds.value = battleInfo.maxRound;
|
||||||
roundResults.value = battleInfo.roundResults;
|
roundResults.value = battleInfo.roundResults;
|
||||||
|
currentShooterId.value = battleInfo.firePlayerIndex;
|
||||||
|
const remain = Date.now() / 1000 - battleInfo.fireTime;
|
||||||
|
if (remain > 0 && remain < 15) {
|
||||||
|
// 等渲染好再通知
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.$emit("update-ramain", remain);
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options.roomNumber) {
|
if (options.roomNumber) {
|
||||||
|
|||||||
@@ -43,7 +43,12 @@ const enterRoom = debounce(async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const onCreateRoom = () => {
|
const onCreateRoom = async () => {
|
||||||
|
const isGaming = await isGamingAPI();
|
||||||
|
if (isGaming) {
|
||||||
|
uni.$showHint(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
warnning.value = "";
|
warnning.value = "";
|
||||||
showModal.value = true;
|
showModal.value = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const { user } = storeToRefs(store);
|
|||||||
const gameType = ref(0);
|
const gameType = ref(0);
|
||||||
const teamSize = ref(0);
|
const teamSize = ref(0);
|
||||||
const start = ref(false);
|
const start = ref(false);
|
||||||
const startCount = ref(false);
|
const countDown = ref(90);
|
||||||
const battleId = ref("");
|
const battleId = ref("");
|
||||||
const currentRound = ref(1);
|
const currentRound = ref(1);
|
||||||
const totalRounds = ref(0);
|
const totalRounds = ref(0);
|
||||||
@@ -39,10 +39,43 @@ const onComplete = ref(null);
|
|||||||
const showModal = ref(false);
|
const showModal = ref(false);
|
||||||
|
|
||||||
onLoad(async (options) => {
|
onLoad(async (options) => {
|
||||||
gameType.value = options.gameType;
|
if (options.battleId) {
|
||||||
teamSize.value = options.teamSize;
|
const battleInfo = uni.getStorageSync(`battle-${options.battleId}`);
|
||||||
if (gameType.value && teamSize.value) {
|
console.log("----battleInfo", battleInfo);
|
||||||
await matchGameAPI(true, gameType.value, teamSize.value);
|
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() {
|
async function stopMatch() {
|
||||||
@@ -83,11 +116,11 @@ async function onReceiveMessage(messages = []) {
|
|||||||
if (msg.id !== battleId.value) return;
|
if (msg.id !== battleId.value) return;
|
||||||
if (msg.constructor === MESSAGETYPES.MeleeAllReady) {
|
if (msg.constructor === MESSAGETYPES.MeleeAllReady) {
|
||||||
start.value = true;
|
start.value = true;
|
||||||
startCount.value = true;
|
|
||||||
seq.value += 1;
|
seq.value += 1;
|
||||||
timerSeq.value = 0;
|
timerSeq.value = 0;
|
||||||
tips.value = "请连续射出6支箭";
|
tips.value = "请连续射出6支箭";
|
||||||
scores.value = [];
|
scores.value = [];
|
||||||
|
countDown.value = 90;
|
||||||
}
|
}
|
||||||
if (msg.constructor === MESSAGETYPES.ShootResult) {
|
if (msg.constructor === MESSAGETYPES.ShootResult) {
|
||||||
if (msg.userId === user.value.id) {
|
if (msg.userId === user.value.id) {
|
||||||
@@ -97,8 +130,8 @@ async function onReceiveMessage(messages = []) {
|
|||||||
playersScores.value[msg.userId].push(msg.target);
|
playersScores.value[msg.userId].push(msg.target);
|
||||||
}
|
}
|
||||||
if (msg.constructor === MESSAGETYPES.HalfTimeOver) {
|
if (msg.constructor === MESSAGETYPES.HalfTimeOver) {
|
||||||
startCount.value = false;
|
|
||||||
halfTimeTip.value = true;
|
halfTimeTip.value = true;
|
||||||
|
countDown.value = 20;
|
||||||
tips.value = "准备下半场";
|
tips.value = "准备下半场";
|
||||||
}
|
}
|
||||||
if (msg.constructor === MESSAGETYPES.MatchOver) {
|
if (msg.constructor === MESSAGETYPES.MatchOver) {
|
||||||
@@ -142,8 +175,9 @@ onUnmounted(() => {
|
|||||||
<ShootProgress
|
<ShootProgress
|
||||||
v-if="start"
|
v-if="start"
|
||||||
:seq="seq"
|
:seq="seq"
|
||||||
:start="startCount"
|
:start="start"
|
||||||
:tips="tips"
|
:tips="tips"
|
||||||
|
:total="countDown"
|
||||||
/>
|
/>
|
||||||
<view v-if="start" class="infos">
|
<view v-if="start" class="infos">
|
||||||
<Avatar :src="user.avatar" :size="35" />
|
<Avatar :src="user.avatar" :size="35" />
|
||||||
@@ -220,7 +254,6 @@ onUnmounted(() => {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding-top: 52px;
|
|
||||||
}
|
}
|
||||||
.half-time-tip > text:last-child {
|
.half-time-tip > text:last-child {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
|
|||||||
@@ -46,10 +46,41 @@ const onComplete = ref(null);
|
|||||||
const showModal = ref(false);
|
const showModal = ref(false);
|
||||||
|
|
||||||
onLoad(async (options) => {
|
onLoad(async (options) => {
|
||||||
gameType.value = options.gameType;
|
if (options.battleId) {
|
||||||
teamSize.value = options.teamSize;
|
const battleInfo = uni.getStorageSync(`battle-${options.battleId}`);
|
||||||
if (gameType.value && teamSize.value) {
|
console.log("----battleInfo", battleInfo);
|
||||||
await matchGameAPI(true, gameType.value, teamSize.value);
|
if (battleInfo) {
|
||||||
|
battleId.value = battleInfo.id;
|
||||||
|
start.value = true;
|
||||||
|
redTeam.value = battleInfo.redTeam;
|
||||||
|
blueTeam.value = battleInfo.blueTeam;
|
||||||
|
currentRound.value = battleInfo.currentRound;
|
||||||
|
bluePoints.value = battleInfo.blueScore;
|
||||||
|
redPoints.value = battleInfo.redScore;
|
||||||
|
totalRounds.value = battleInfo.maxRound;
|
||||||
|
roundResults.value = battleInfo.roundResults;
|
||||||
|
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]}轮`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const remain = Date.now() / 1000 - battleInfo.fireTime;
|
||||||
|
if (remain > 0 && remain <= 15) {
|
||||||
|
// 等渲染好再通知
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.$emit("update-ramain", remain);
|
||||||
|
}, 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() {
|
async function stopMatch() {
|
||||||
@@ -227,11 +258,4 @@ onUnmounted(() => {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
.modal {
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user