package dungeonmania.entities.collectables;
import dungeonmania.util.Position;
Copyright By PowCoder代写 加微信 powcoder
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import dungeonmania.entities.Entity;
import dungeonmania.entities.Player;
import dungeonmania.entities.Switch;
import dungeonmania.entities.inventory.InventoryItem;
import dungeonmania.map.GameMap;
public class Bomb extends Entity implements InventoryItem {
public enum State {
INVENTORY,
public static final int DEFAULT_RADIUS = 1;
private State state;
private int radius;
private List
public Bomb(Position position, int radius) {
super(position);
state = State.SPAWNED;
this.radius = radius;
public void subscribe(Switch s) {
this.subs.add(s);
public void notify(GameMap map) {
explode(map);
public boolean canMoveOnto(GameMap map, Entity entity) {
return true;
public void onOverlap(GameMap map, Entity entity) {
if (state != State.SPAWNED) return;
if (entity instanceof Player) {
if (!((Player) entity).pickUp(this)) return;
subs.stream().forEach(s -> s.unsubscribe(this));
map.destroyEntity(this);
this.state = State.INVENTORY;
public void onMovedAway(GameMap map, Entity entity) {
public void onDestroy(GameMap gameMap) {
public void onPutDown(GameMap map, Position p) {
translate(Position.calculatePositionBetween(getPosition(), p));
map.addEntity(this);
this.state = State.PLACED;
List
adjPosList.stream().forEach(node -> {
List
.filter(e -> (e instanceof Switch))
.collect(Collectors.toList());
entities.stream()
.map(Switch.class::cast)
.forEach(s -> s.subscribe(this, map));
entities.stream()
.map(Switch.class::cast)
.forEach(s -> this.subscribe(s));
* it destroys all entities in diagonally and cardinally adjacent cells, except for the player
* @param map
public void explode(GameMap map) {
int x = getPosition().getX();
int y = getPosition().getY();
for (int i = x – radius; i <= x + radius; i++) {
for (int j = y - radius; j <= y + radius; j++) {
List
entities = entities.stream()
.filter(e -> !(e instanceof Player))
.collect(Collectors.toList());
for (Entity e: entities) map.destroyEntity(e);
public State getState() {
return state;
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com