|
@@ -1,30 +1,139 @@
|
|
|
<template>
|
|
|
<custom-dialog :visible.sync="dialogVisible" title="我的农场" @close="onClose">
|
|
|
- <view class="farm-container">
|
|
|
- <view class="farm-grid">
|
|
|
- <view v-for="(plot, index) in plots" :key="index" class="farm-plot" @click="onPlotClick(index)">
|
|
|
- <view class="plot-content" :class="getPlotClass(plot)">
|
|
|
- <view v-if="plot.crop" class="crop-stage">
|
|
|
- <image :src="getCropImage(plot)" mode="aspectFit" class="crop-image"></image>
|
|
|
+ <view class="farm-container" @click="onContainerClick">
|
|
|
+ <view class="farm-beds">
|
|
|
+ <view class="farm-grid upper-bed">
|
|
|
+ <view class="row row-1">
|
|
|
+ <view v-for="index in 3" :key="index-1"
|
|
|
+ class="farm-plot"
|
|
|
+ :class="getPlotClass(plots[index-1])"
|
|
|
+ @click.stop="onPlotClick(index-1)">
|
|
|
+ <view class="plot-content">
|
|
|
+ <view v-if="plots[index-1].state !== 'locked'" class="crop-stage">
|
|
|
+ <image v-if="plots[index-1].state === 'growing' || plots[index-1].state === 'harvestable'"
|
|
|
+ :src="getCropImage(plots[index-1])"
|
|
|
+ mode="aspectFit"
|
|
|
+ class="crop-image">
|
|
|
+ </image>
|
|
|
+ </view>
|
|
|
+ <view class="plot-state-text" :class="{ 'state-changed': plots[index-1].stateChanged }">
|
|
|
+ {{ getPlotStateText(plots[index-1].state) }}
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="row row-2">
|
|
|
+ <view v-for="index in 4" :key="index+2"
|
|
|
+ class="farm-plot"
|
|
|
+ :class="getPlotClass(plots[index+2])"
|
|
|
+ @click.stop="onPlotClick(index+2)">
|
|
|
+ <view class="plot-content">
|
|
|
+ <view v-if="plots[index+2].state !== 'locked'" class="crop-stage">
|
|
|
+ <image v-if="plots[index+2].state === 'growing' || plots[index+2].state === 'harvestable'"
|
|
|
+ :src="getCropImage(plots[index+2])"
|
|
|
+ mode="aspectFit"
|
|
|
+ class="crop-image">
|
|
|
+ </image>
|
|
|
+ </view>
|
|
|
+ <view class="plot-state-text" :class="{ 'state-changed': plots[index+2].stateChanged }">
|
|
|
+ {{ getPlotStateText(plots[index+2].state) }}
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="row row-3">
|
|
|
+ <view v-for="index in 3" :key="index+6"
|
|
|
+ class="farm-plot"
|
|
|
+ :class="getPlotClass(plots[index+6])"
|
|
|
+ @click.stop="onPlotClick(index+6)">
|
|
|
+ <view class="plot-content">
|
|
|
+ <view v-if="plots[index+6].state !== 'locked'" class="crop-stage">
|
|
|
+ <image v-if="plots[index+6].state === 'growing' || plots[index+6].state === 'harvestable'"
|
|
|
+ :src="getCropImage(plots[index+6])"
|
|
|
+ mode="aspectFit"
|
|
|
+ class="crop-image">
|
|
|
+ </image>
|
|
|
+ </view>
|
|
|
+ <view class="plot-state-text" :class="{ 'state-changed': plots[index+6].stateChanged }">
|
|
|
+ {{ getPlotStateText(plots[index+6].state) }}
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <view class="farm-grid lower-bed">
|
|
|
+ <view class="row row-1">
|
|
|
+ <view v-for="index in 3" :key="index+9"
|
|
|
+ class="farm-plot"
|
|
|
+ :class="getPlotClass(plots[index+9])"
|
|
|
+ @click.stop="onPlotClick(index+9)">
|
|
|
+ <view class="plot-content">
|
|
|
+ <view v-if="plots[index+9].state !== 'locked'" class="crop-stage">
|
|
|
+ <image v-if="plots[index+9].state === 'growing' || plots[index+9].state === 'harvestable'"
|
|
|
+ :src="getCropImage(plots[index+9])"
|
|
|
+ mode="aspectFit"
|
|
|
+ class="crop-image">
|
|
|
+ </image>
|
|
|
+ </view>
|
|
|
+ <view class="plot-state-text" :class="{ 'state-changed': plots[index+9].stateChanged }">
|
|
|
+ {{ getPlotStateText(plots[index+9].state) }}
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="row row-2">
|
|
|
+ <view v-for="index in 4" :key="index+12"
|
|
|
+ class="farm-plot"
|
|
|
+ :class="getPlotClass(plots[index+12])"
|
|
|
+ @click.stop="onPlotClick(index+12)">
|
|
|
+ <view class="plot-content">
|
|
|
+ <view v-if="plots[index+12].state !== 'locked'" class="crop-stage">
|
|
|
+ <image v-if="plots[index+12].state === 'growing' || plots[index+12].state === 'harvestable'"
|
|
|
+ :src="getCropImage(plots[index+12])"
|
|
|
+ mode="aspectFit"
|
|
|
+ class="crop-image">
|
|
|
+ </image>
|
|
|
+ </view>
|
|
|
+ <view class="plot-state-text" :class="{ 'state-changed': plots[index+12].stateChanged }">
|
|
|
+ {{ getPlotStateText(plots[index+12].state) }}
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="row row-3">
|
|
|
+ <view v-for="index in 3" :key="index+16"
|
|
|
+ class="farm-plot"
|
|
|
+ :class="getPlotClass(plots[index+16])"
|
|
|
+ @click.stop="onPlotClick(index+16)">
|
|
|
+ <view class="plot-content">
|
|
|
+ <view v-if="plots[index+16].state !== 'locked'" class="crop-stage">
|
|
|
+ <image v-if="plots[index+16].state === 'growing' || plots[index+16].state === 'harvestable'"
|
|
|
+ :src="getCropImage(plots[index+16])"
|
|
|
+ mode="aspectFit"
|
|
|
+ class="crop-image">
|
|
|
+ </image>
|
|
|
+ </view>
|
|
|
+ <view class="plot-state-text" :class="{ 'state-changed': plots[index+16].stateChanged }">
|
|
|
+ {{ getPlotStateText(plots[index+16].state) }}
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
- <view v-if="plot.weeds" class="weeds"></view>
|
|
|
- <view v-if="plot.needsWater" class="water-indicator"></view>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
- <view class="action-panel">
|
|
|
- <view class="action-buttons">
|
|
|
- <button @click="selectAction('plant')" :disabled="!canPlant">播种</button>
|
|
|
- <button @click="selectAction('water')" :disabled="!canWater">浇水</button>
|
|
|
- <button @click="selectAction('fertilize')" :disabled="!canFertilize">施肥</button>
|
|
|
- <button @click="selectAction('weed')" :disabled="!canWeed">除草</button>
|
|
|
- <button @click="selectAction('harvest')" :disabled="!canHarvest">收获</button>
|
|
|
+ <view class="action-panel" >
|
|
|
+ <view class="farm-state-indicator" :class="{ 'state-changed': farmStateChanged }">
|
|
|
+ 当前状态: {{ getFarmStateText(farmState) }}
|
|
|
</view>
|
|
|
- <view class="selected-plot-info" v-if="selectedPlot !== null">
|
|
|
- <text>状态: {{ getPlotStatus(plots[selectedPlot]) }}</text>
|
|
|
- <text v-if="plots[selectedPlot].crop">作物: {{ plots[selectedPlot].crop.name }}</text>
|
|
|
- <text v-if="plots[selectedPlot].crop">生长进度: {{ getGrowthProgress(plots[selectedPlot]) }}%</text>
|
|
|
+ <view class="action-buttons">
|
|
|
+ <button @click.stop="onUnlockClick" >解锁</button>
|
|
|
+ <button @click.stop="onPlantClick" >播种</button>
|
|
|
+ <button @click.stop="onHarvestClick" >收获</button>
|
|
|
+ <!-- <button @click.stop="onUnlockClick" :disabled="!canUnlock">解锁</button>
|
|
|
+ <button @click.stop="onPlantClick" :disabled="!canPlant">播种</button>
|
|
|
+ <button @click.stop="onHarvestClick" :disabled="!canHarvest">收获</button> -->
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
@@ -33,20 +142,19 @@
|
|
|
|
|
|
<script>
|
|
|
import CustomDialog from '@/components/CustomDialog/CustomDialog.vue'
|
|
|
+// import { showModal, showToast } from '@/utils/uniapi'
|
|
|
|
|
|
-const CROPS = {
|
|
|
- carrot: {
|
|
|
- name: '胡萝卜',
|
|
|
- growthTime: 30, // minutes
|
|
|
- stages: ['/static/crops/carrot_stage1.png', '/static/crops/carrot_stage2.png', '/static/crops/carrot_stage3.png'],
|
|
|
- value: 100
|
|
|
- },
|
|
|
- tomato: {
|
|
|
- name: '番茄',
|
|
|
- growthTime: 60,
|
|
|
- stages: ['/static/crops/tomato_stage1.png', '/static/crops/tomato_stage2.png', '/static/crops/tomato_stage3.png'],
|
|
|
- value: 200
|
|
|
- }
|
|
|
+const PLOT_STATES = {
|
|
|
+ LOCKED: 'locked',
|
|
|
+ EMPTY: 'empty',
|
|
|
+ GROWING: 'growing',
|
|
|
+ HARVESTABLE: 'harvestable'
|
|
|
+}
|
|
|
+
|
|
|
+const FARM_STATES = {
|
|
|
+ IDLE: 'idle',
|
|
|
+ PLANTING: 'planting',
|
|
|
+ HARVESTING: 'harvesting'
|
|
|
}
|
|
|
|
|
|
export default {
|
|
@@ -58,172 +166,222 @@ export default {
|
|
|
visible: {
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
+ },
|
|
|
+ coins: {
|
|
|
+ type: Number,
|
|
|
+ default: 0
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
dialogVisible: false,
|
|
|
- plots: Array(12).fill().map(() => ({
|
|
|
- crop: null,
|
|
|
+ farmState: FARM_STATES.IDLE,
|
|
|
+ farmStateChanged: false,
|
|
|
+ plots: Array(20).fill().map(() => ({
|
|
|
+ state: PLOT_STATES.LOCKED,
|
|
|
plantedAt: null,
|
|
|
- watered: false,
|
|
|
- fertilized: false,
|
|
|
- weeds: false,
|
|
|
- needsWater: false
|
|
|
- })),
|
|
|
- selectedPlot: null,
|
|
|
- selectedAction: null,
|
|
|
- growthTimer: null
|
|
|
+ stateChanged: false
|
|
|
+ }))
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
+ canUnlock() {
|
|
|
+ return this.farmState === FARM_STATES.IDLE && this.hasLockedPlots
|
|
|
+ },
|
|
|
canPlant() {
|
|
|
- return this.selectedPlot !== null && !this.plots[this.selectedPlot].crop
|
|
|
+ return this.farmState === FARM_STATES.IDLE && this.hasEmptyPlots
|
|
|
+ },
|
|
|
+ canHarvest() {
|
|
|
+ return this.farmState === FARM_STATES.IDLE && this.hasHarvestablePlots
|
|
|
},
|
|
|
- canWater() {
|
|
|
- return this.selectedPlot !== null &&
|
|
|
- this.plots[this.selectedPlot].crop &&
|
|
|
- !this.plots[this.selectedPlot].watered
|
|
|
+ hasLockedPlots() {
|
|
|
+ return this.plots.some(plot => plot.state === PLOT_STATES.LOCKED)
|
|
|
},
|
|
|
- canFertilize() {
|
|
|
- return this.selectedPlot !== null &&
|
|
|
- this.plots[this.selectedPlot].crop &&
|
|
|
- !this.plots[this.selectedPlot].fertilized
|
|
|
+ hasEmptyPlots() {
|
|
|
+ return this.plots.some(plot => plot.state === PLOT_STATES.EMPTY)
|
|
|
},
|
|
|
- canWeed() {
|
|
|
- return this.selectedPlot !== null &&
|
|
|
- this.plots[this.selectedPlot].weeds
|
|
|
+ hasHarvestablePlots() {
|
|
|
+ return this.plots.some(plot => plot.state === PLOT_STATES.HARVESTABLE)
|
|
|
},
|
|
|
- canHarvest() {
|
|
|
- return this.selectedPlot !== null &&
|
|
|
- this.plots[this.selectedPlot].crop &&
|
|
|
- this.isCropReady(this.plots[this.selectedPlot])
|
|
|
+ nextUnlockedPlotIndex() {
|
|
|
+ return this.plots.findIndex(plot => plot.state === PLOT_STATES.LOCKED)
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
|
visible(newVal) {
|
|
|
this.dialogVisible = newVal
|
|
|
if (newVal) {
|
|
|
- this.startGrowthTimer()
|
|
|
- } else {
|
|
|
- this.stopGrowthTimer()
|
|
|
+ // 初始化第一块地为空地状态
|
|
|
+ if (this.plots[0].state === PLOT_STATES.LOCKED) {
|
|
|
+ this.plots[0].state = PLOT_STATES.EMPTY
|
|
|
+ }
|
|
|
+ console.log('农场对话框打开,当前农场状态:', this.farmState)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ farmState: {
|
|
|
+ handler(newVal, oldVal) {
|
|
|
+ if (newVal !== oldVal) {
|
|
|
+ console.log(`农场状态发生变化: ${oldVal} -> ${newVal}`)
|
|
|
+ this.farmStateChanged = true;
|
|
|
+ setTimeout(() => {
|
|
|
+ this.farmStateChanged = false;
|
|
|
+ }, 300);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
onClose() {
|
|
|
+ console.log('关闭农场对话框,重置农场状态为空闲')
|
|
|
+ this.farmState = FARM_STATES.IDLE
|
|
|
this.$emit('update:visible', false)
|
|
|
},
|
|
|
- onPlotClick(index) {
|
|
|
- this.selectedPlot = index
|
|
|
- if (this.selectedAction) {
|
|
|
- this.performAction(index)
|
|
|
+ getPlotClass(plot) {
|
|
|
+ return {
|
|
|
+ 'is-locked': plot.state === PLOT_STATES.LOCKED,
|
|
|
+ 'is-empty': plot.state === PLOT_STATES.EMPTY,
|
|
|
+ 'is-growing': plot.state === PLOT_STATES.GROWING,
|
|
|
+ 'is-harvestable': plot.state === PLOT_STATES.HARVESTABLE,
|
|
|
+ 'highlight-empty': this.farmState === FARM_STATES.PLANTING && plot.state === PLOT_STATES.EMPTY,
|
|
|
+ 'highlight-harvestable': this.farmState === FARM_STATES.HARVESTING && plot.state === PLOT_STATES.HARVESTABLE
|
|
|
}
|
|
|
},
|
|
|
- selectAction(action) {
|
|
|
- this.selectedAction = action
|
|
|
+ getCropImage(plot) {
|
|
|
+ if (plot.state === PLOT_STATES.GROWING) {
|
|
|
+ return '/static/crops/growing.png'
|
|
|
+ } else if (plot.state === PLOT_STATES.HARVESTABLE) {
|
|
|
+ return '/static/crops/harvestable.png'
|
|
|
+ }
|
|
|
+ return ''
|
|
|
},
|
|
|
- performAction(plotIndex) {
|
|
|
- const plot = this.plots[plotIndex]
|
|
|
-
|
|
|
- switch (this.selectedAction) {
|
|
|
- case 'plant':
|
|
|
- if (this.canPlant) {
|
|
|
- plot.crop = { ...CROPS.carrot }
|
|
|
- plot.plantedAt = Date.now()
|
|
|
- plot.watered = false
|
|
|
- plot.fertilized = false
|
|
|
- plot.weeds = false
|
|
|
- plot.needsWater = true
|
|
|
- }
|
|
|
- break
|
|
|
- case 'water':
|
|
|
- if (this.canWater) {
|
|
|
- plot.watered = true
|
|
|
- plot.needsWater = false
|
|
|
- }
|
|
|
- break
|
|
|
- case 'fertilize':
|
|
|
- if (this.canFertilize) {
|
|
|
- plot.fertilized = true
|
|
|
- }
|
|
|
- break
|
|
|
- case 'weed':
|
|
|
- if (this.canWeed) {
|
|
|
- plot.weeds = false
|
|
|
- }
|
|
|
- break
|
|
|
- case 'harvest':
|
|
|
- if (this.canHarvest) {
|
|
|
- // TODO: Add harvested items to inventory
|
|
|
- plot.crop = null
|
|
|
- plot.plantedAt = null
|
|
|
- plot.watered = false
|
|
|
- plot.fertilized = false
|
|
|
- plot.weeds = false
|
|
|
- plot.needsWater = false
|
|
|
- }
|
|
|
- break
|
|
|
+ updatePlotState(index, newState) {
|
|
|
+ const plot = this.plots[index];
|
|
|
+ if (plot.state !== newState) {
|
|
|
+ console.log(`更新土地 ${index} 状态: ${plot.state} -> ${newState}`)
|
|
|
+ plot.state = newState;
|
|
|
+ plot.stateChanged = true;
|
|
|
+ setTimeout(() => {
|
|
|
+ plot.stateChanged = false;
|
|
|
+ }, 300);
|
|
|
}
|
|
|
-
|
|
|
- this.selectedAction = null
|
|
|
},
|
|
|
- getPlotClass(plot) {
|
|
|
- return {
|
|
|
- 'has-crop': plot.crop,
|
|
|
- 'needs-water': plot.needsWater,
|
|
|
- 'has-weeds': plot.weeds
|
|
|
+ async onUnlockClick() {
|
|
|
+ if (!this.hasLockedPlots) {
|
|
|
+ console.log('没有可解锁的土地,保持当前状态:', this.farmState)
|
|
|
+ uni.showToast({ title: '已经解锁所有土地', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const unlockCost = 100
|
|
|
+ console.log(`当前金币: ${this.coins}, 解锁费用: ${unlockCost}`)
|
|
|
+ const result = await uni.showModal({
|
|
|
+ title: '解锁新土地',
|
|
|
+ content: `是否使用${unlockCost}金币解锁新土地?\n当前金币:${this.coins}`
|
|
|
+ })
|
|
|
+
|
|
|
+ if (result.confirm) {
|
|
|
+ if (this.coins < unlockCost) {
|
|
|
+ console.log(`金币不足,需要 ${unlockCost} 金币,当前只有 ${this.coins} 金币`)
|
|
|
+ uni.showToast({ title: '金币不够', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(`解锁成功,扣除 ${unlockCost} 金币,剩余 ${this.coins - unlockCost} 金币`)
|
|
|
+ this.$emit('update:coins', this.coins - unlockCost)
|
|
|
+ this.updatePlotState(this.nextUnlockedPlotIndex, PLOT_STATES.EMPTY)
|
|
|
+ } else {
|
|
|
+ console.log('用户取消解锁,保持当前状态:', this.farmState)
|
|
|
}
|
|
|
},
|
|
|
- getCropImage(plot) {
|
|
|
- if (!plot.crop) return ''
|
|
|
- const growthStage = this.getGrowthStage(plot)
|
|
|
- return plot.crop.stages[growthStage]
|
|
|
- },
|
|
|
- getGrowthStage(plot) {
|
|
|
- if (!plot.crop || !plot.plantedAt) return 0
|
|
|
- const growthProgress = this.getGrowthProgress(plot)
|
|
|
- if (growthProgress >= 100) return 2
|
|
|
- if (growthProgress >= 50) return 1
|
|
|
- return 0
|
|
|
- },
|
|
|
- getGrowthProgress(plot) {
|
|
|
- if (!plot.crop || !plot.plantedAt) return 0
|
|
|
- const elapsed = (Date.now() - plot.plantedAt) / 1000 / 60 // minutes
|
|
|
- const progress = (elapsed / plot.crop.growthTime) * 100
|
|
|
- return Math.min(100, Math.floor(progress))
|
|
|
- },
|
|
|
- isCropReady(plot) {
|
|
|
- return this.getGrowthProgress(plot) >= 100
|
|
|
- },
|
|
|
- getPlotStatus(plot) {
|
|
|
- if (!plot.crop) return '空地'
|
|
|
- if (plot.weeds) return '需要除草'
|
|
|
- if (plot.needsWater) return '需要浇水'
|
|
|
- if (this.isCropReady(plot)) return '可以收获'
|
|
|
- return '生长中'
|
|
|
- },
|
|
|
- startGrowthTimer() {
|
|
|
- this.growthTimer = setInterval(() => {
|
|
|
- this.plots.forEach(plot => {
|
|
|
- if (plot.crop && !plot.watered) {
|
|
|
- plot.needsWater = true
|
|
|
- }
|
|
|
- if (plot.crop && Math.random() < 0.1) { // 10% chance to spawn weeds
|
|
|
- plot.weeds = true
|
|
|
+ onPlantClick() {
|
|
|
+ console.log(`点击播种按钮,当前农场状态: ${this.farmState}`);
|
|
|
+ if (this.farmState === FARM_STATES.PLANTING) {
|
|
|
+ console.log('取消播种模式,切换为空闲状态');
|
|
|
+ this.farmState = FARM_STATES.IDLE;
|
|
|
+ } else {
|
|
|
+ console.log('进入播种模式,请选择要播种的空地');
|
|
|
+ this.farmState = FARM_STATES.PLANTING;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onHarvestClick() {
|
|
|
+ console.log(`点击收获按钮,当前农场状态: ${this.farmState}`);
|
|
|
+ if (this.farmState === FARM_STATES.HARVESTING) {
|
|
|
+ console.log('取消收获模式,切换为空闲状态');
|
|
|
+ this.farmState = FARM_STATES.IDLE;
|
|
|
+ } else {
|
|
|
+ console.log('进入收获模式,请选择要收获的土地');
|
|
|
+ this.farmState = FARM_STATES.HARVESTING;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onPlotClick(index) {
|
|
|
+ const plot = this.plots[index]
|
|
|
+ console.log(`点击土地 ${index},当前状态: ${plot.state},农场状态: ${this.farmState}`)
|
|
|
+
|
|
|
+ if (plot.state === PLOT_STATES.LOCKED) {
|
|
|
+ console.log(`土地 ${index} 未解锁,无法操作`)
|
|
|
+ uni.showToast({ title: '请先解锁该土地', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.farmState === FARM_STATES.PLANTING) {
|
|
|
+ console.log(`当前为播种状态,尝试在土地 ${index} 播种`)
|
|
|
+ if (plot.state !== PLOT_STATES.EMPTY) {
|
|
|
+ console.log(`土地 ${index} 不是空地,无法播种,当前状态: ${plot.state}`)
|
|
|
+ uni.showToast({ title: '只有空地可以播种', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log(`在土地 ${index} 播种成功,状态更新为生长中`)
|
|
|
+ this.updatePlotState(index, PLOT_STATES.GROWING)
|
|
|
+ plot.plantedAt = Date.now()
|
|
|
+ console.log(`土地 ${index} 开始生长,种植时间: ${new Date(plot.plantedAt).toLocaleString()}`)
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ if (plot.state === PLOT_STATES.GROWING) {
|
|
|
+ console.log(`土地 ${index} 生长完成,状态更新为可收获`)
|
|
|
+ this.updatePlotState(index, PLOT_STATES.HARVESTABLE)
|
|
|
+ } else {
|
|
|
+ console.log(`土地 ${index} 状态已改变,当前状态: ${plot.state},不更新为可收获状态`)
|
|
|
}
|
|
|
- })
|
|
|
- }, 60000) // Check every minute
|
|
|
+ }, 5000)
|
|
|
+ } else if (this.farmState === FARM_STATES.HARVESTING) {
|
|
|
+ console.log(`当前为收获状态,尝试收获土地 ${index}`)
|
|
|
+ if (plot.state !== PLOT_STATES.HARVESTABLE) {
|
|
|
+ console.log(`土地 ${index} 没有可收获的作物,当前状态: ${plot.state}`)
|
|
|
+ uni.showToast({ title: '没有可以收获的花朵', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log(`收获土地 ${index} 成功,状态更新为空地`)
|
|
|
+ this.updatePlotState(index, PLOT_STATES.EMPTY)
|
|
|
+ plot.plantedAt = null
|
|
|
+ console.log(`发送收获完成事件`)
|
|
|
+ this.$emit('harvest-complete')
|
|
|
+ } else {
|
|
|
+ console.log(`当前为空闲状态,点击土地 ${index} 无效,请先选择操作模式`)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onContainerClick() {
|
|
|
+ if (this.farmState !== FARM_STATES.IDLE) {
|
|
|
+ console.log(`点击空白区域,从${this.farmState}状态切换为空闲状态`)
|
|
|
+ this.farmState = FARM_STATES.IDLE
|
|
|
+ }
|
|
|
},
|
|
|
- stopGrowthTimer() {
|
|
|
- if (this.growthTimer) {
|
|
|
- clearInterval(this.growthTimer)
|
|
|
- this.growthTimer = null
|
|
|
+ getPlotStateText(state) {
|
|
|
+ const stateTexts = {
|
|
|
+ [PLOT_STATES.LOCKED]: '未解锁',
|
|
|
+ [PLOT_STATES.EMPTY]: '空地',
|
|
|
+ [PLOT_STATES.GROWING]: '生长中',
|
|
|
+ [PLOT_STATES.HARVESTABLE]: '可收获'
|
|
|
}
|
|
|
+ return stateTexts[state]
|
|
|
+ },
|
|
|
+ getFarmStateText(state) {
|
|
|
+ const stateTexts = {
|
|
|
+ [FARM_STATES.IDLE]: '空闲',
|
|
|
+ [FARM_STATES.PLANTING]: '播种状态',
|
|
|
+ [FARM_STATES.HARVESTING]: '收获状态'
|
|
|
+ }
|
|
|
+ return stateTexts[state]
|
|
|
}
|
|
|
- },
|
|
|
- beforeDestroy() {
|
|
|
- this.stopGrowthTimer()
|
|
|
}
|
|
|
}
|
|
|
</script>
|