|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- package structures.basic;
-
- import java.io.File;
- import java.util.ArrayList;
- import java.util.List;
-
- import com.fasterxml.jackson.annotation.JsonIgnore;
- import com.fasterxml.jackson.databind.ObjectMapper;
-
- /**
- * A basic representation of a tile on the game board. Tiles have both a pixel position
- * and a grid position. Tiles also have a width and height in pixels and a series of urls
- * that point to the different renderable textures that a tile might have.
- *
- * @author Dr. Richard McCreadie
- *
- */
- public class Tile {
-
- @JsonIgnore
- private static ObjectMapper mapper = new ObjectMapper(); // Jackson Java Object Serializer, is used to read java objects from a file
-
- List<String> tileTextures;
- int xpos;
- int ypos;
- int width;
- int height;
- int tilex;
- int tiley;
-
- public Tile() {}
-
- public Tile(String tileTexture, int xpos, int ypos, int width, int height, int tilex, int tiley) {
- super();
- tileTextures = new ArrayList<String>(1);
- tileTextures.add(tileTexture);
- this.xpos = xpos;
- this.ypos = ypos;
- this.width = width;
- this.height = height;
- this.tilex = tilex;
- this.tiley = tiley;
- }
-
- public Tile(List<String> tileTextures, int xpos, int ypos, int width, int height, int tilex, int tiley) {
- super();
- this.tileTextures = tileTextures;
- this.xpos = xpos;
- this.ypos = ypos;
- this.width = width;
- this.height = height;
- this.tilex = tilex;
- this.tiley = tiley;
- }
- public List<String> getTileTextures() {
- return tileTextures;
- }
- public void setTileTextures(List<String> tileTextures) {
- this.tileTextures = tileTextures;
- }
- public int getXpos() {
- return xpos;
- }
- public void setXpos(int xpos) {
- this.xpos = xpos;
- }
- public int getYpos() {
- return ypos;
- }
- public void setYpos(int ypos) {
- this.ypos = ypos;
- }
- public int getWidth() {
- return width;
- }
- public void setWidth(int width) {
- this.width = width;
- }
- public int getHeight() {
- return height;
- }
- public void setHeight(int height) {
- this.height = height;
- }
- public int getTilex() {
- return tilex;
- }
- public void setTilex(int tilex) {
- this.tilex = tilex;
- }
- public int getTiley() {
- return tiley;
- }
- public void setTiley(int tiley) {
- this.tiley = tiley;
- }
-
- /**
- * Loads a tile from a configuration file
- * parameters.
- * @param configFile
- * @return
- */
- public static Tile constructTile(String configFile) {
-
- try {
- Tile tile = mapper.readValue(new File(configFile), Tile.class);
- return tile;
- } catch (Exception e) {
- e.printStackTrace();
-
- }
- return null;
-
- }
-
-
-
- }
|