Files
zp1/backend/src/main/java/com/zombie/game/model/Wall.java
2026-04-25 22:09:27 +08:00

69 lines
1.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.zombie.game.model;
import lombok.Getter;
/**
* 墙体抽象基类
*
* 地图中的障碍物,分为:
* - StaticWall静态墙体不可破坏
* - NutWall坚果墙体可被僵尸攻击破坏有血量
*/
public abstract class Wall {
/** 格子X坐标 */
@Getter
protected final int gridX;
/** 格子Y坐标 */
@Getter
protected final int gridY;
public Wall(int gridX, int gridY) {
this.gridX = gridX;
this.gridY = gridY;
}
/**
* 是否可破坏
*
* @return true 表示可以被破坏
*/
public abstract boolean isDestructible();
/**
* 是否已被破坏(仅对可破坏墙体有效)
*
* @return true 表示已破坏
*/
public abstract boolean isDestroyed();
/**
* 获取当前血量(仅对可破坏墙体有效)
*
* @return 当前血量
*/
public abstract float getHealth();
/**
* 受到伤害
*
* @param damage 伤害值
*/
public abstract void takeDamage(float damage);
/**
* 获取移动代价(用于流场计算)
*
* @return 移动代价,不可通行返回 Float.MAX_VALUE
*/
public abstract float getMovementCost();
/**
* 是否阻挡移动
*
* @return true 表示阻挡
*/
public boolean blocksMovement() {
return !isDestroyed();
}
}