HarmonyOS应用开发实战:猫猫大作战-Combined 合并与连击倍率机制
·


前言
在「猫猫大作战」中,连击倍率是得分系统的核心机制——当玩家在 2 秒内连续触发合并时,倍率从 1x 递增到最高 5x,激励玩家快速规划、连续操作。
一、连击机制
interface ComboInfo {
count: number; // 连击次数
multiplier: number; // 当前倍率(1-5)
lastMergeTime: number; // 上次合并时间戳
}
private updateCombo(): void {
const now = Date.now();
const COMBO_WINDOW = 2000; // 2 秒
if (now - this.combo.lastMergeTime < COMBO_WINDOW) {
this.combo.count++;
this.combo.multiplier = Math.min(this.combo.count, 5);
} else {
this.combo.count = 1;
this.combo.multiplier = 1;
}
this.combo.lastMergeTime = now;
}
二、倍率计算
| 连击次数 | 倍率 | 小猫合并 | 传奇猫合并 |
|---|---|---|---|
| 第 1 次 | 1x | 10 | 2430 |
| 第 2 次 | 2x | 20 | 4860 |
| 第 3 次 | 3x | 30 | 7290 |
| 第 4 次 | 4x | 40 | 9720 |
| 第 5+ 次 | 5x(最高) | 50 | 12150 |
三、超时重置
// 连击窗口 2 秒,超时重置
// 在游戏主循环中可强制重置
private clearComboIfExpired(): void {
const now = Date.now();
if (now - this.combo.lastMergeTime > 2000 && this.combo.multiplier > 1) {
this.combo = { count: 0, multiplier: 1, lastMergeTime: now };
}
}
四、UI 展示
// 连击倍率显示
Text(`🔥 ${this.combo.multiplier}x`)
.fontSize(this.combo.multiplier > 1 ? 24 : 16)
.fontColor(this.combo.multiplier >= 3 ? '#E74C3C' : '#2C3E50')
.fontWeight(FontWeight.Bold)
// 连击动画(3x 以上高亮)
if (this.combo.multiplier >= 3) {
Text(`${this.combo.count}x 连击!`)
.fontSize(18).fontColor('#F39C12')
.fontWeight(FontWeight.Bold)
}
五、平衡性设计
| 参数 | 值 | 目的 |
|---|---|---|
| 连击窗口 | 2 秒 | 足够规划操作但不拖沓 |
| 最高倍率 | 5x | 奖励连续操作但不失控 |
| 重置条件 | 超时 / 新局 | 防一直保留高倍率 |
六、最佳实践
- 连击窗口 2 秒:玩家有足够时间观察棋盘
- 重置时机明确:超时重置或新一局重置
- UI 反馈醒目:倍率变大时字号和颜色变化
- 上限 5x:防倍率无限膨胀导致得分失衡
总结
连击倍率通过 2 秒窗口和最高 5x 限制,激励玩家连续合并操作。核心要点:Date.now() 计算时间差、 Math.min(count, 5) 上限、 超时重置防作弊、 视觉反馈提醒玩家。
如果这篇文章对你有帮助,欢迎点赞👍、收藏⭐、关注🔔,你的支持是我持续创作的动力!
相关资源:
更多推荐


所有评论(0)