代写代考 package dungeonmania.entities;

package dungeonmania.entities;

import dungeonmania.map.GameMap;

Copyright By PowCoder代写 加微信 powcoder

import dungeonmania.entities.collectables.Key;
import dungeonmania.entities.enemies.Spider;
import dungeonmania.entities.inventory.Inventory;
import dungeonmania.util.Position;

public class Door extends Entity {
private boolean open = false;
private int number;

public Door(Position position, int number) {
super(position.asLayer(Entity.DOOR_LAYER));
this.number = number;

public boolean canMoveOnto(GameMap map, Entity entity) {
if (open || entity instanceof Spider) {
return true;
return (entity instanceof Player && hasKey((Player) entity));

public void onOverlap(GameMap map, Entity entity) {
if (!(entity instanceof Player))

Player player = (Player) entity;
Inventory inventory = player.getInventory();
Key key = inventory.getFirst(Key.class);

if (hasKey(player)) {
inventory.remove(key);

private boolean hasKey(Player player) {
Inventory inventory = player.getInventory();
Key key = inventory.getFirst(Key.class);

return (key != null && key.getnumber() == number);

public boolean isOpen() {
return open;

public void open() {
open = true;

public void onMovedAway(GameMap map, Entity entity) {

public void onDestroy(GameMap gameMap) {

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com