I'm trying to make Monopoly/Eurbuisness game in Java, but I got stuck with kinda simple problem... So, I have basic Field class
public class Field {
protected int fieldPosition;
Field(){ }
}
then I extend this class to subclasses like Start, Property, Jail, Chance, etc.
Currently I'm working on Property class
public class Property extends Field{
private String propertyGroup;
private String propertyOwner;
private String propertyName;
private float propertyPrice;
private boolean allowBuilding;
private int numberOfHouses;
private int numberOfHotels;
private float basicValue;
private float houseValue;
final private int maxNumberOfHouses = 4;
final private int getMaxNumberOfHotels = 1;
public Property(int fieldPosition, String propertyGroup, String propertyName, float propertyPrice, float basicValue, float houseValue){
this.fieldPosition = fieldPosition;
this.propertyGroup = propertyGroup;
propertyOwner = "none";
this.propertyName = propertyName;
this.propertyPrice = propertyPrice;
allowBuilding = false;
this.basicValue = basicValue;
this.houseValue = houseValue;
numberOfHotels = 0;
numberOfHotels = 0;
}
/*
Setters
*/
public void setAllowBuilding(boolean allowBuilding) {
this.allowBuilding = allowBuilding;
}
public void setPropertyOwner(String propertyOwner) {
this.propertyOwner = propertyOwner;
}
/*
Getters
*/
public String getPropertyGroup() { return propertyGroup; }
public String getPropertyOwner() {
return propertyOwner;
}
public String getPropertyName() {
return propertyName;
}
public float getPropertyPrice() {
return propertyPrice;
}
public boolean isAllowBuilding() {
return allowBuilding;
}
public int getNumberOfHouses() {
return numberOfHouses;
}
public int getNumberOfHotels() {
return numberOfHotels;
}
public int getMaxNumberOfHouses() {
return maxNumberOfHouses;
}
public float getBasicValue() {
return basicValue;
}
public float getHouseValue() {
return houseValue;
}
/*
Add and remove house and hotel methods
*/
public void addHouse(){
this.numberOfHouses = getNumberOfHouses() + 1;
this.propertyPrice = getPropertyPrice() + 100;
}
public void removeHouse(){
this.numberOfHouses = getNumberOfHouses() - 1;
this.propertyPrice = getPropertyPrice() - 100;
}
public void addHotel(){
this.numberOfHotels = getNumberOfHotels() + 1;
this.propertyPrice = getPropertyPrice() + 400;
}
public void removeHotel(){
this.numberOfHotels = getNumberOfHotels() - 1;
this.propertyPrice = getPropertyPrice() - 400;
}
@Override
public String toString() {
return propertyName + getNumberOfHouses();
}
Next class is Board, it should create basic table of all fields (using polymorphysm, some of them will be Properties, some will be something else)
public class Board {
public Board() {
Field board[] = new Property[40];
board[0] = new Start();
board[1] = new Property(1,"Katowice","Mariacka", 600, 100, 175);
board[2] = new Property(2, "Katowice","Stawowa", 750, 125, 215);
board[3] = new Property(3, "Katowice","Korfantego", 1000, 150, 250);
}
}
Then in Game class I got method buyProperty
public void buyProperty(Player player, Property property){
if(player.getPlayerCash() >= property.getPropertyPrice() &&
(property.getPropertyOwner().equals("none"))){
player.addProperty(property);
property.setPropertyOwner(player.getPlayerName());
player.removeCash(property.getPropertyPrice());
}
}
Finnaly, Im trying to test it but unfortunatelly, it doesnt work
public static void main(String[] args) {
Board board = new Board();
Game game = new Game();
Player johny = new Player("Johny");
game.buyProperty(johny, board[1]);
}
java: array required, but game.components.Board found
and it points into last line I posted
any ideas, suggestions?