Mianowicie, szkielet aplikacji wygląda póki co tak:
Kod:
public class Field {
protected int fieldPosition;
Field(){
}
}
Kod:
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();
}
}
Następnie tworzę klasę Board, która defacto jest listą obiektów Field
Kod:
public class Board {
Field board[] = new Field[40];
public Board() {
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);
}
public Field[] getBoard(){
return board;
}
}
Kod:
public void buyProperty(Player player, Field property){
if(player.getPlayerCash() >= property.getPropertyPrice() &&
(property.getPropertyOwner().equals("none"))){
player.addProperty(property);
property.setPropertyOwner(player.getPlayerName());
player.removeCash(property.getPropertyPrice());
}
}
Cannot resolve method 'getPropertyPrice()'
Na koniec pokazuje jak chce się odwołać do wspomnianej metody by wszystko było jasne
Kod:
public static void main(String[] args) {
Board gameBoard = new Board();
Game game = new Game();
Player johny = new Player("Johny");
game.buyProperty(johny, gameBoard.getBoard()[1]);
}
Zakładki