程序代写 package dungeonmania.entities;

package dungeonmania.entities;

import java.util.List;
import java.util.stream.Collectors;

Copyright By PowCoder代写 加微信 powcoder

import dungeonmania.entities.enemies.Mercenary;
import dungeonmania.entities.enemies.ZombieToast;
import dungeonmania.map.GameMap;
import dungeonmania.util.Position;

public class Portal extends Entity {
private ColorCodedType color;
private Portal pair;

public Portal(Position position, ColorCodedType color) {
super(position);
this.color = color;

public boolean canMoveOnto(GameMap map, Entity entity) {
if (pair == null)
return false;
if (entity instanceof Player || entity instanceof Mercenary)
return pair.canTeleportTo(map, entity);
return true;

public boolean canTeleportTo(GameMap map, Entity entity) {
List neighbours = getPosition().getCardinallyAdjacentPositions();
return neighbours.stream().allMatch(n -> map.canMoveTo(entity, n));

public void onOverlap(GameMap map, Entity entity) {
if (pair == null)
if (entity instanceof Player || entity instanceof Mercenary || entity instanceof ZombieToast)
doTeleport(map, entity);

private void doTeleport(GameMap map, Entity entity) {
Position destination = pair.getPosition()
.getCardinallyAdjacentPositions()
.filter(dest -> map.canMoveTo(entity, dest))
.findAny()
.orElse(null);
if (destination != null) {
map.moveTo(entity, destination);

public String getColor() {
return color.toString();

public List getDestPositions(GameMap map, Entity entity) {
return pair == null
: pair.getPosition().getAdjacentPositions()
.filter(p -> map.canMoveTo(entity, p))
.collect(Collectors.toList());
public void bind(Portal portal) {
if (this.pair == portal)
if (this.pair != null) {
this.pair.bind(null);
this.pair = portal;
if (portal != null) {
portal.bind(this);

public void onMovedAway(GameMap map, Entity entity) {

public void onDestroy(GameMap gameMap) {

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