/* * Copyright (C) 2015 iZc * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package de.nplusc.iZc.MazeGame.cells; import de.nplusc.iZc.MazeGame.Objects.Player; import java.awt.Image; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; import javax.imageio.ImageIO; /** * * @author LH */ public abstract class MazeCell { public static final int DIRECTION_NORTH=0; public static final int DIRECTION_EAST=1; public static final int DIRECTION_SOUTH=2; public static final int DIRECTION_WEST=3; private Map exits = new HashMap<>();//ints for layer and bools for directions private Map entrances = new HashMap<>();//ints for layer and bools for directions //entrance but no exit ->onewaydoor private String TexturePath = ""; private int direction=0; private int baseLayer=0,layerHeight=1; //wichtig bei stacked-tiles wie brücken, tunnels; public MazeCell(Map pexits, Map pentrances,int bl,int lh) { exits = pexits; entrances = pentrances; } public MazeCell(Map pexits, Map pentrances,int bl) { this(pexits,pentrances,bl,1); } public MazeCell() { } public boolean canExit(int direction,int layer,Player p) { if(!exits.containsKey(layer-baseLayer)) { return false; } return exits.get(layer-baseLayer)[direction]; } public boolean canEnter(int direction,int layer,Player p) { if(!entrances.containsKey(layer-baseLayer)) { return false; } return entrances.get(layer-baseLayer)[direction]; } public int getDirection() //setter ist serialisierungskram also nach unten verbannt { return direction; } //setTileImage() ->setTexturePath() public Image getTextureTile() { Image i = null; try { i = ImageIO.read(new File(TexturePath)); } catch (IOException ex) { ex.printStackTrace(); } return i; } int getExitLayer(int direction) //geht da nur maximal ein exit pro richtung möglich { int ret = Integer.MIN_VALUE; //integer_minimum == kein exit in diese richtung Integer[] layers = exits.keySet().toArray(new Integer[]{0}); for (int i = 0; i < layers.length; i++) { int k = layers[i]; if(exits.get(k)[direction]) { return k; } } return ret; //fallback bei kein exit verfügbar } //Serialisuerungskram# public int getBaseLayer() { return baseLayer; } public void setBaseLayer(int baseLayer) { this.baseLayer = baseLayer; } public int getLayerHeight() { return layerHeight; } public void setLayerHeight(int layerHeight) { this.layerHeight = layerHeight; } public void setDirection(int dir) { direction=dir; } public Map getExits() { return exits; } public void setExits(Map exits) { this.exits = exits; } public Map getEntrances() { return entrances; } public void setEntrances(Map entrances) { this.entrances = entrances; } public String getTexturePath() { return TexturePath; } public void setTexturePath(String TexturePath) { this.TexturePath = TexturePath; } public abstract String onCellEnter(Player p); //interface für msgs public boolean requiresFOV() // ob aufgedeckt oder nicht wird im player gespeichert { return true; } }