123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- /*
- * 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 <http://www.gnu.org/licenses/>.
- */
- 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<Integer,boolean[]> exits = new HashMap<>();//ints for layer and bools for directions
- private Map<Integer,boolean[]> 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<Integer,boolean[]> pexits, Map<Integer,boolean[]> pentrances,int bl,int lh)
- {
- exits = pexits; entrances = pentrances;
-
- }
-
- public MazeCell(Map<Integer,boolean[]> pexits, Map<Integer,boolean[]> 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<Integer, boolean[]> getExits()
- {
- return exits;
- }
- public void setExits(Map<Integer, boolean[]> exits)
- {
- this.exits = exits;
- }
- public Map<Integer, boolean[]> getEntrances()
- {
- return entrances;
- }
- public void setEntrances(Map<Integer, boolean[]> 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;
- }
-
- }
|