fix(Fishing.vue): 修复钓鱼逻辑并优化动画效果
修复钓鱼逻辑中的等待时间和提竿判断,移除不必要的点击计数逻辑。优化钓鱼成功后的动画效果,增加多条鱼时的特殊动画和提示信息。
This commit is contained in:
+107
-100
@@ -1,5 +1,4 @@
|
||||
<template>
|
||||
<<<<<<< HEAD
|
||||
<div class="fishing-page">
|
||||
<div class="fishing-container">
|
||||
<div class="fishing-area">
|
||||
@@ -12,27 +11,36 @@
|
||||
>
|
||||
<div class="fishing-scene" @click="handleFish"></div>
|
||||
<div class="ripple"></div>
|
||||
=======
|
||||
<div class="fishing-page">
|
||||
<div class="fishing-container">
|
||||
<div class="fishing-area">
|
||||
<div class="fishing-animation" :class="{ 'fishing-active': isFishing }">
|
||||
<div class="fishing-scene" @click="handleFish"></div>
|
||||
<div class="ripple"></div>
|
||||
</div>
|
||||
<div class="result" v-if="resultMessage || nextPullTime">
|
||||
<el-alert v-if="resultMessage" :title="resultMessage" :type="currentCatch.length>0 ? 'success' : 'info'"
|
||||
:closable="false" show-icon />
|
||||
<el-alert v-if="nextPullTime" :title="`下次可钓鱼时间:${nextPullTime}`" type="warning" :closable="false" show-icon />
|
||||
<el-alert
|
||||
v-if="resultMessage"
|
||||
:title="resultMessage"
|
||||
:type="currentCatch.length > 0 ? 'success' : 'info'"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<el-alert
|
||||
v-if="nextPullTime"
|
||||
:title="`下次可钓鱼时间:${nextPullTime}`"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="log-area">
|
||||
<FishingLog :logs="fishingLogs" />
|
||||
<div class="back-button">
|
||||
<el-button @click="goHome" size="small" type="default" icon="ArrowLeft">返回</el-button>
|
||||
<el-button
|
||||
@click="goHome"
|
||||
size="small"
|
||||
type="default"
|
||||
icon="ArrowLeft"
|
||||
>返回</el-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
>>>>>>> 4a4857fa8239db297faeeaf348f16654927c8bb7
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -50,8 +58,6 @@ const nextPullTime = ref("");
|
||||
const isFishing = ref(false);
|
||||
const currentCatch = ref([]); // 改为数组
|
||||
const fishingLogs = ref([]);
|
||||
const clickCount = ref(0);
|
||||
const targetClicks = ref(0);
|
||||
const isWaiting = ref(false);
|
||||
const isReeling = ref(false);
|
||||
const fishEscapeTimer = ref(null);
|
||||
@@ -69,12 +75,6 @@ const saveLogs = () => {
|
||||
localStorage.setItem("fishingLogs", JSON.stringify(fishingLogs.value));
|
||||
};
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 生成随机点击阈值(1-5秒内的随机次数)
|
||||
const generateRandomTarget = () => {
|
||||
return Math.floor(Math.random() * 15) + 5; // 5-20次随机点击
|
||||
};
|
||||
|
||||
// 生成随机等待时间(1-3秒)
|
||||
const generateWaitTime = () => {
|
||||
return Math.floor(Math.random() * 2000) + 1000;
|
||||
@@ -91,13 +91,10 @@ const willReelFail = () => {
|
||||
};
|
||||
|
||||
// 组件挂载时加载缓存的日志
|
||||
=======
|
||||
>>>>>>> 4a4857fa8239db297faeeaf348f16654927c8bb7
|
||||
onMounted(() => {
|
||||
loadCachedLogs();
|
||||
});
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 组件卸载时清除定时器
|
||||
onBeforeUnmount(() => {
|
||||
if (fishEscapeTimer.value) {
|
||||
@@ -106,56 +103,50 @@ onBeforeUnmount(() => {
|
||||
});
|
||||
|
||||
const handleFish = async () => {
|
||||
// 如果正在钓鱼中,不允许操作
|
||||
if (isFishing.value) return;
|
||||
// 下杆前校验:如果设置了下次钓鱼时间,则判断当前时间是否在等待中
|
||||
if (nextPullTime.value) {
|
||||
// 尝试将 nextPullTime 转换为 Date 对象
|
||||
const nextTime = new Date(nextPullTime.value);
|
||||
if (Date.now() < nextTime.getTime()) {
|
||||
ElMessage.warning(
|
||||
`还未到下杆时间,请在 ${nextTime.toLocaleTimeString()} 后尝试`
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 如果正在钓鱼且还处于等待上钩阶段,不允许操作
|
||||
if (isFishing.value && !isWaiting.value) return;
|
||||
|
||||
// 第一阶段:开始钓鱼
|
||||
if (!isWaiting.value) {
|
||||
isFishing.value = true;
|
||||
resultMessage.value = "放下鱼竿,等待中...";
|
||||
resultMessage.value = "放下鱼竿,等待不知好歹的🐟";
|
||||
|
||||
// 随机等待时间后判断是否有鱼上钩
|
||||
setTimeout(() => {
|
||||
if (willFishEscape()) {
|
||||
resultMessage.value = "鱼儿警觉地游走了...";
|
||||
ElMessage.info("鱼儿游走了 🐟");
|
||||
resultMessage.value = "鱼儿警觉地游走了... 🐟";
|
||||
isFishing.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
isWaiting.value = true;
|
||||
clickCount.value = 0;
|
||||
targetClicks.value = generateRandomTarget();
|
||||
resultMessage.value = "发现鱼儿上钩了!快点击收杆!";
|
||||
resultMessage.value = "鱼儿上钩啦!速速收杆!速速速速速速";
|
||||
|
||||
isReeling.value = true;
|
||||
|
||||
// 设置逃跑计时器
|
||||
fishEscapeTimer.value = setTimeout(() => {
|
||||
if (isWaiting.value) {
|
||||
if (isWaiting.value && isFishing.value) {
|
||||
isWaiting.value = false;
|
||||
isFishing.value = false;
|
||||
resultMessage.value = "鱼儿挣脱逃走了!";
|
||||
ElMessage.warning("鱼儿逃走了 🎣");
|
||||
}
|
||||
}, 5000); // 5秒内必须完成提竿
|
||||
}, generateWaitTime());
|
||||
return;
|
||||
}
|
||||
|
||||
// 增加点击计数并添加提竿动画效果
|
||||
clickCount.value++;
|
||||
isReeling.value = true;
|
||||
setTimeout(() => {
|
||||
isReeling.value = false;
|
||||
}, 200);
|
||||
|
||||
// 如果点击次数未达到目标,更新提示信息
|
||||
if (clickCount.value < targetClicks.value) {
|
||||
const remainingClicks = targetClicks.value - clickCount.value;
|
||||
resultMessage.value = `继续点击!还需要${remainingClicks}次!`;
|
||||
ElMessage.info(`还需点击${remainingClicks}次!`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 清除逃跑计时器
|
||||
if (fishEscapeTimer.value) {
|
||||
clearTimeout(fishEscapeTimer.value);
|
||||
@@ -164,29 +155,17 @@ const handleFish = async () => {
|
||||
|
||||
// 第二阶段:达到目标点击次数,判断是否提竿成功
|
||||
isWaiting.value = false;
|
||||
isReeling.value = false;
|
||||
|
||||
if (willReelFail()) {
|
||||
isFishing.value = false;
|
||||
resultMessage.value = "提竿时机不对,鱼儿溜走了!";
|
||||
ElMessage.warning("提竿失败 🎣");
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用钓鱼接口
|
||||
currentCatch.value = null;
|
||||
resultMessage.value = "正在钓鱼中...";
|
||||
=======
|
||||
onBeforeUnmount(() => {
|
||||
localStorage.removeItem("fishingLogs");
|
||||
});
|
||||
|
||||
const handleFish = async () => {
|
||||
if (isFishing.value) return;
|
||||
|
||||
isFishing.value = true;
|
||||
currentCatch.value = [];
|
||||
resultMessage.value = "正在钓鱼中...";
|
||||
>>>>>>> 4a4857fa8239db297faeeaf348f16654927c8bb7
|
||||
|
||||
try {
|
||||
const res = await fishingClick();
|
||||
@@ -200,14 +179,37 @@ const handleFish = async () => {
|
||||
currentCatch.value = items;
|
||||
|
||||
// 构建展示信息
|
||||
const messageList = items.map(fish =>
|
||||
`「${fish.isRare ? "稀有的" : ""}${fish.fishName}」,重量 ${fish.weight}`
|
||||
const messageList = items.map(
|
||||
(fish) =>
|
||||
`「${fish.isRare ? "稀有的" : ""}${fish.fishName}」,重量 ${
|
||||
fish.weight
|
||||
}`
|
||||
);
|
||||
resultMessage.value = `你钓到了:\n${messageList.join("\n")}`;
|
||||
// 根据钓到的鱼的数量显示不同的消息和动画效果
|
||||
if (items.length > 1) {
|
||||
ElMessage({
|
||||
message: `太棒了!一次钓到${items.length}条鱼!🎣✨`,
|
||||
type: "success",
|
||||
duration: 5000,
|
||||
showClose: true,
|
||||
customClass: "multi-catch-message",
|
||||
});
|
||||
// 添加额外的动画类
|
||||
document
|
||||
.querySelector(".fishing-animation")
|
||||
.classList.add("multi-catch");
|
||||
setTimeout(() => {
|
||||
document
|
||||
.querySelector(".fishing-animation")
|
||||
.classList.remove("multi-catch");
|
||||
}, 3000);
|
||||
} else {
|
||||
ElMessage.success("钓鱼成功!🎣");
|
||||
}
|
||||
|
||||
// 添加所有钓到的鱼到日志
|
||||
const newLogs = items.map(fish => ({
|
||||
const newLogs = items.map((fish) => ({
|
||||
time: new Date(),
|
||||
fishName: fish.fishName,
|
||||
weight: fish.weight,
|
||||
@@ -238,7 +240,6 @@ const handleFish = async () => {
|
||||
const goHome = () => {
|
||||
router.push("/");
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -288,7 +289,6 @@ const goHome = () => {
|
||||
}
|
||||
|
||||
.fishing-animation {
|
||||
<<<<<<< HEAD
|
||||
height: 500px;
|
||||
position: relative;
|
||||
margin: 20px 0;
|
||||
@@ -296,7 +296,6 @@ const goHome = () => {
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.fishing-scene {
|
||||
@@ -308,28 +307,9 @@ const goHome = () => {
|
||||
background: url("@/assets/fishing-scene.svg") no-repeat center;
|
||||
background-size: cover;
|
||||
transition: transform 0.2s ease;
|
||||
pointer-events: auto;
|
||||
=======
|
||||
height: 500px;
|
||||
position: relative;
|
||||
margin: 20px 0;
|
||||
overflow: hidden;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.fishing-scene {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
background: url("@/assets/fishing-scene.svg") no-repeat center;
|
||||
background-size: cover;
|
||||
>>>>>>> 4a4857fa8239db297faeeaf348f16654927c8bb7
|
||||
}
|
||||
|
||||
.fishing-active .fishing-scene {
|
||||
animation: scene-active 3s ease-in-out infinite;
|
||||
}
|
||||
@@ -354,13 +334,6 @@ const goHome = () => {
|
||||
animation: ripple 2s infinite;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
.fishing-controls {
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
>>>>>>> 4a4857fa8239db297faeeaf348f16654927c8bb7
|
||||
.result {
|
||||
margin-top: 20px;
|
||||
}
|
||||
@@ -379,25 +352,59 @@ const goHome = () => {
|
||||
@keyframes scene-active {
|
||||
0%,
|
||||
100% {
|
||||
transform: scale(1);
|
||||
transform: scale(1) rotate(0deg);
|
||||
filter: brightness(1);
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.02);
|
||||
25% {
|
||||
transform: scale(1.05) rotate(-2deg);
|
||||
filter: brightness(1.2);
|
||||
}
|
||||
75% {
|
||||
transform: scale(1.05) rotate(2deg);
|
||||
filter: brightness(1.2);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes reel {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
transform: rotate(0deg) scale(1);
|
||||
}
|
||||
50% {
|
||||
transform: rotate(-5deg);
|
||||
transform: rotate(-8deg) scale(1.1);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(0deg);
|
||||
transform: rotate(0deg) scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* 多条鱼时的特殊动画效果 */
|
||||
@keyframes multi-catch {
|
||||
0%,
|
||||
100% {
|
||||
transform: scale(1) rotate(0deg);
|
||||
filter: brightness(1) contrast(1);
|
||||
}
|
||||
25% {
|
||||
transform: scale(1.15) rotate(-5deg);
|
||||
filter: brightness(1.3) contrast(1.1);
|
||||
}
|
||||
75% {
|
||||
transform: scale(1.15) rotate(5deg);
|
||||
filter: brightness(1.3) contrast(1.1);
|
||||
}
|
||||
}
|
||||
|
||||
.multi-catch {
|
||||
animation: multi-catch 1s ease-in-out 3 !important;
|
||||
}
|
||||
|
||||
.multi-catch-message {
|
||||
font-size: 16px !important;
|
||||
font-weight: bold !important;
|
||||
background: linear-gradient(45deg, #4caf50, #2196f3) !important;
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.fishing-scene:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user