wangfukang 4 days ago
parent
commit
e51f9266d4
  1. 24
      package1/planet/adventure.vue

24
package1/planet/adventure.vue

@ -165,6 +165,7 @@
timeLimit: 150, timeLimit: 150,
timeLeft: 150, timeLeft: 150,
timer: null, timer: null,
roundSeed: '',
moveCount: 0, moveCount: 0,
modal: { show: false, title: '', sub: '' } modal: { show: false, title: '', sub: '' }
} }
@ -328,6 +329,7 @@
this.session = res.result this.session = res.result
this.playing = true this.playing = true
this.startTs = Date.now() this.startTs = Date.now()
this.roundSeed = this.newRoundSeed()
this.buildLevel() this.buildLevel()
if (!this.cards.length) this.buildLevel() if (!this.cards.length) this.buildLevel()
this.startTimer() this.startTimer()
@ -336,19 +338,20 @@
buildLevel() { buildLevel() {
const icons = ['🍔', '🥤', '🥟', '🏀', '🎧', '🚲', '🍜', '🔥', '☕', '🍢'] const icons = ['🍔', '🥤', '🥟', '🏀', '🎧', '🚲', '🍜', '🔥', '☕', '🍢']
const garbageIcons = ['🚀', '🪐', '🛸'] const garbageIcons = ['🚀', '🪐', '🛸']
if (!this.roundSeed) this.roundSeed = this.newRoundSeed()
let cards = [] let cards = []
for (let attempt = 0; attempt < 100; attempt++) { for (let attempt = 0; attempt < 100; attempt++) {
const seed = this.levelSeed() + '_try_' + attempt const seed = this.roundSeed + '_try_' + attempt
const positions = this.buildCardPositions(seed) const positions = this.buildCardPositions(seed)
cards = this.assignTrapLayoutIcons(positions, icons, garbageIcons, seed) cards = this.assignTrapLayoutIcons(positions, icons, garbageIcons, seed)
if (cards.length && this.checkDifficultyMetrics(cards)) break if (cards.length && this.checkDifficultyMetrics(cards)) break
cards = [] cards = []
} }
if (!cards.length) { if (!cards.length) {
cards = this.assignTrapLayoutIcons(this.buildCardPositions(this.levelSeed() + '_fallback'), icons, garbageIcons, this.levelSeed() + '_fallback', true) cards = this.assignTrapLayoutIcons(this.buildCardPositions(this.roundSeed + '_fallback'), icons, garbageIcons, this.roundSeed + '_fallback', true)
} }
if (!cards.length) { if (!cards.length) {
cards = this.assignEmergencyIcons(this.buildCardPositions(this.levelSeed() + '_emergency'), icons, garbageIcons) cards = this.assignEmergencyIcons(this.buildCardPositions(this.roundSeed + '_emergency'), icons, garbageIcons)
} }
if (this.shouldBuildUnwinnableLevel()) { if (this.shouldBuildUnwinnableLevel()) {
this.applyUnwinnableTwist(cards, icons, garbageIcons) this.applyUnwinnableTwist(cards, icons, garbageIcons)
@ -359,6 +362,9 @@
this.normalizeCards(icons) this.normalizeCards(icons)
this.refreshCardState() this.refreshCardState()
}, },
newRoundSeed() {
return `${this.levelSeed()}_${Date.now()}_${Math.floor(Math.random() * 100000)}`
},
buildCardPositions(seed) { buildCardPositions(seed) {
const cards = [] const cards = []
const template = this.levelTemplate('hell') const template = this.levelTemplate('hell')
@ -505,7 +511,7 @@
return positions return positions
}, },
shouldBuildUnwinnableLevel() { shouldBuildUnwinnableLevel() {
const rand = this.seededRandom(this.levelSeed() + '_win_rate') const rand = this.seededRandom((this.roundSeed || this.levelSeed()) + '_win_rate')
return rand() < 0.5 return rand() < 0.5
}, },
applyUnwinnableTwist(cards, icons, garbageIcons) { applyUnwinnableTwist(cards, icons, garbageIcons) {
@ -517,7 +523,7 @@
}) })
const candidates = Object.keys(iconMap).filter(icon => iconMap[icon].length >= 3) const candidates = Object.keys(iconMap).filter(icon => iconMap[icon].length >= 3)
if (!candidates.length) return if (!candidates.length) return
const rand = this.seededRandom(this.levelSeed() + '_unwinnable') const rand = this.seededRandom((this.roundSeed || this.levelSeed()) + '_unwinnable')
this.shuffleWithRandom(candidates, rand) this.shuffleWithRandom(candidates, rand)
const trapIcons = candidates.slice(0, 4) const trapIcons = candidates.slice(0, 4)
trapIcons.forEach((targetIcon, trapIndex) => { trapIcons.forEach((targetIcon, trapIndex) => {
@ -533,9 +539,16 @@
key.displayIcon = this.displayIcon(key.icon) key.displayIcon = this.displayIcon(key.icon)
key.unwinnableKey = true key.unwinnableKey = true
key.trap = true key.trap = true
this.exposeBadCardEarly(key, trapIndex)
this.exposePairEarly(iconMap[targetIcon].filter(card => card.id !== key.id).slice(0, 2), trapIndex) this.exposePairEarly(iconMap[targetIcon].filter(card => card.id !== key.id).slice(0, 2), trapIndex)
}) })
}, },
exposeBadCardEarly(card, index) {
card.layer = 2
card.x = 116 + index * 74
card.y = 178 + (index % 2) * 70
card.style = `left:${card.x}rpx;top:${card.y}rpx;z-index:${this.cardZIndex(card)};`
},
exposePairEarly(pair, index) { exposePairEarly(pair, index) {
const baseX = 74 + index * 88 const baseX = 74 + index * 88
pair.forEach((card, i) => { pair.forEach((card, i) => {
@ -773,6 +786,7 @@
this.playing = false this.playing = false
this.clearTimer() this.clearTimer()
this.timeLeft = this.timeLimit this.timeLeft = this.timeLimit
this.roundSeed = this.newRoundSeed()
this.buildLevel() this.buildLevel()
if (!this.cards.length) this.buildLevel() if (!this.cards.length) this.buildLevel()
}, },

Loading…
Cancel
Save