package cicaprojekt;

public class Wall extends Tile {
    private Stargate sg = null;

    public Wall() {
        super();
    }

    @Override
    public void spawnStargate(Stargate stargate, Direction direction) {
        if(stargate.isSpawned())
            stargate.getCurrentWall().clearStargate();
        if (sg == null) {
            sg = stargate;
            sg.setCurrentWall(this, direction);
            Game.instance.updateDisplay();
        }
        else
            return;
    }

    @Override
    public boolean isSteppable() {
        if (sg != null)
            return true;

        return false;
    }

    public void clearStargate() {
        if(sg != null) {
            sg.setCurrentWall(null, null);
            sg = null;
        }
    }

    public void onEntry(PlayerBase playerBase) {
        super.onEntry(playerBase);
        if (sg == null) {
            return;
        } else {
            sg.teleport(playerBase);
        }
    }

    public void onExit(PlayerBase playerBase) throws IllegalStateException {
        if(sg != null) return;
        throw new IllegalStateException("Hiba! Te hogy kerültél a falba?");
    }
    
    public Stargate getStargate() {
        return sg;
    }
}
