-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSquareType.java
146 lines (123 loc) · 4.12 KB
/
SquareType.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package Monopoly;
import java.util.ArrayList;
import java.util.List;
public abstract class SquareType implements Square{
//Can be made by person creating one class for properties, jail block, etc...
protected String name; //Name of the tile
private int[] rent;
private String tileType; //eg. Utility / Taxes / Land
protected Player owner; //To determine who owns it. 0 for neutral, 1 for player 1... etc.
private int position; // position in the char 2D array
private int index;
private int value;
protected int setId; // PropertySet id of the property.
private int totalInSet;
private final ArrayList<Player> arr = new ArrayList<Player>();
protected int numHouses;
private boolean mortgaged = false;
//Standard setters and getters
public boolean isMortgaged() {
return mortgaged;
}
public void setMortgaged(boolean mortgaged) {
this.mortgaged = mortgaged;
}
public String getName(){
return name;
}
void setName(String name){this.name=name;}
public void setRent(int[] arr) {
rent = arr;
}
protected int getRent(){
if (owner.getCount(setId) == totalInSet && numHouses == 0)
return rent[numHouses]*2;
return rent[numHouses];
}
void setTileType(String tileType){this.tileType=tileType;}
public Player getOwner(){return owner;}
public void setOwner(Player owner){this.owner=owner;}
public int getPosition() {
return position;
}
void setPosition(int position) {
this.position = position;
}
public int getIndex() { return index; }
public void setIndex(int index) {this.index = index;}
public int getValue(){
return this.value;
}
void setValue(int value) {
this.value = value;
}
public int getSetId() {return setId;}
void setSetId(int setId) {this.setId = setId;}
public int getTotalInSet() {return totalInSet;}
void setTotalInSet(int totalInSet) {this.totalInSet = totalInSet;}
public void addPlayer(Player p) {arr.add(p);}
public void removePlayer(Player p) {arr.remove(p);}
public ArrayList<Player> getPlayers() {
return this.arr;
}
public int getNumHouses() {
return numHouses;
}
//TODO trade properties
public void preRollChoices(Player p) {
String str;
while(true){
ArrayList<Square> props = p.getBuildableProperties();
String validChoices = "R";
System.out.println("<R>oll or default 'Enter'");
if(props.size() > 0) {
System.out.println("<B>uild house");
validChoices += "B";
}
if (!p.getPropertyNames(true).equals("")) {
System.out.println("<U>nmortgage");
validChoices += "U";
}
while (true) {
str = Board.readLine().toUpperCase();
if (str.isEmpty()|| (str.length() == 1 && validChoices.contains(str))) break;
System.out.println("Invalid input: " + str);
}
switch (str) {
case "B":
p.buildProperty(props);
break;
case "U":
p.mortgage(false);
break;
case "R":
default:
return;
}
}
}
public int rollAction(Player p, int d1, int d2){
int rollValue = d1 +d2;
int dest = p.getSquare().getIndex() + rollValue;
if (dest > 40) {
Board.bank.payMoney(p, 200);
}
dest %=40;
return dest;
}
void buyCard(Player p) {
Player o = this.getOwner();
if (o == Board.bank) {
System.out.println("Buy? <y/n>" + p.getSquare().getName());
String str = Board.readLine().toLowerCase();
if (str.equals("y") || str.equals("")) {
p.payMoney(Board.bank, this.getValue());
p.addProperty(this);
}
}
}
public void landingAction(Player p) {
}
public void addHouse() {}
public void removeHouse() {}
}