[SOLVED] package dungeonmania.entities.collectables;

$25

File Name: package_dungeonmania.entities.collectables;.zip
File Size: 405.06 KB

5/5 - (1 vote)

package dungeonmania.entities.collectables;

import dungeonmania.util.Position;

Copyright By Assignmentchef assignmentchef

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 subs = new ArrayList<>();

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 = getPosition().getCardinallyAdjacentPositions();
adjPosList.stream().forEach(node -> {
List entities = map.getEntities(node)
.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 = map.getEntities(new Position(i, j));
entities = entities.stream()
.filter(e -> !(e instanceof Player))
.collect(Collectors.toList());
for (Entity e: entities) map.destroyEntity(e);

public State getState() {
return state;

CS: assignmentchef QQ: 1823890830 Email: [email protected]

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] package dungeonmania.entities.collectables;
$25