You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

79 lines
1.5 KiB

/**
* Copyright 2022 Jamie Munro, Distributed under the Common Public Attribution License Version 1.0 (CPAL-1.0)
* Tile engine
*/
import java.io.IOException;
import java.util.Properties;
/**
* Tile class
* Represents a single tile
*/
class Tile {
private final int id;
private final int row;
private final int col;
private TileProperties properties;
/**
* Constructor
* @param id tile ID
* @param col column (x co-ordinate) within level
* @param row row (y co-ordinate) within level
* @throws IOException
*/
public Tile(int id, int col, int row, TileProperties properties) {
this.id = id;
this.col = col;
this.row = row;
try {
this.properties = properties;
}
catch (Exception e) {
this.properties = null;
}
}
/**
* Getter for ID
* @return id
*/
public int getId() {
return id;
}
/**
* Getter for column (x co-ordinate)
* @return col (x co-ordinate)
*/
public int getCol() {
return col;
}
/**
* Getter for row (y co-ordinate)
* @return row (y co-ordinate)
*/
public int getRow() {
return row;
}
public String getProperty(String key) {
if (this.properties == null) return null;
else {
Properties prop = this.properties.getProperties(this.id);
if (prop == null) return null;
else {
return prop.getProperty(key);
}
}
}
@Override
public String toString() {
return String.valueOf(this.id);
}
}