1
This commit is contained in:
60
backend/src/main/java/com/zombie/game/model/NutWall.java
Normal file
60
backend/src/main/java/com/zombie/game/model/NutWall.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package com.zombie.game.model;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 坚果墙体
|
||||
*
|
||||
* 可被僵尸攻击破坏的障碍物。
|
||||
* 设计血量:僵尸移动速度 2.0格/秒,攻击间隔 1.0秒,
|
||||
* 假设僵尸每攻击一次造成 1 点伤害(用于破坏墙体),
|
||||
* 需要 20 个时间单位(约 20 秒)才能破坏。
|
||||
*
|
||||
* 流场中,坚果的移动代价 = 基础代价 + 摧毁代价(20.0),
|
||||
* 这样 BFS 会自动权衡绕道 vs 摧毁。
|
||||
*/
|
||||
public class NutWall extends Wall {
|
||||
/** 坚果最大血量(20个时间单位) */
|
||||
public static final float MAX_HEALTH = 20.0f;
|
||||
/** 坚果在流场中的额外移动代价(摧毁时间折算) */
|
||||
public static final float MOVEMENT_COST_PENALTY = 20.0f;
|
||||
/** 当前血量 */
|
||||
@Getter
|
||||
private float health;
|
||||
/** 是否已被破坏 */
|
||||
private boolean destroyed;
|
||||
|
||||
public NutWall(int gridX, int gridY) {
|
||||
super(gridX, gridY);
|
||||
this.health = MAX_HEALTH;
|
||||
this.destroyed = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDestructible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDestroyed() {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(float damage) {
|
||||
if (destroyed) return;
|
||||
this.health -= damage;
|
||||
if (this.health <= 0) {
|
||||
this.health = 0;
|
||||
this.destroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMovementCost() {
|
||||
if (destroyed) {
|
||||
return 1.0f; // 被破坏后视为空地
|
||||
}
|
||||
return 1.0f + MOVEMENT_COST_PENALTY;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user