-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
209 lines (187 loc) · 7.46 KB
/
Player.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import java.util.ArrayList;
import java.util.Scanner;
public class Player {
private int balance;
private final String name;
private int depositCard = 0;
private int depositRemain = 0;
private int chanceToRelease = 0;
private int TaxCard = 0;
private int Index = 1;
boolean lowBalance = false;
ArrayList<Cinema> cinemas = new ArrayList<>();
ArrayList<Ground> grounds = new ArrayList<>();
public Player(String name) {
this.name = name;
balance = 200;
}
int findCinema (ArrayList<Cinema> properties, int index){
for (int i = 0; i < properties.size(); i++) {
if(properties.get(i).getIndex() == index)
return i;
}
return -1;
}
int findGround(ArrayList<Ground> properties, int index){
for (int i = 0; i < properties.size(); i++) {
if(properties.get(i).getIndex() == index)
return i;
}
return -1;
}
public void sellProperty() {
System.out.println("which property do you want to sell");
lowBalance = true;
boolean con = true;
do{
System.out.println("1- cinema 2-Ground|House|hotel 3-return");
switch (new Scanner(System.in).nextInt()){
case 1:
if(cinemas.size() == 0){
System.out.println("You are not able to sell");
con = false;break;
}else{
for (Cinema cinema : cinemas) {
System.out.println(cinema.getIndex() + "- cinema" + cinema.getIndex());
}
boolean con1 = true;
do{
int input = new Scanner(System.in).nextInt();
switch (input){
case 4:
case 8:
case 15:
case 22:try {
int indexOfCinema = findCinema(cinemas, input);
if(indexOfCinema != -1){
cinemas.get(indexOfCinema).setOwner(Board.getInstance().bank.banker);
cinemas.remove(indexOfCinema);
addBalance(100);
lowBalance = false;
System.out.println("You sold your cinema!");break;
}else
con1 = false;break;
} catch (LowBalance e) {
System.out.println(e.getMessage());
}break;
default: con1 = false;
break;
}
}while (!con1);
}
break;
case 2:
if(grounds.size() == 0){
System.out.println("You are not able to sell");
con = false;break;
}else{
for (int i = 0; i < grounds.size(); i++) {
System.out.println(grounds.get(i).getIndex()+"- Ground "+grounds.get(i).getIndex());
}
boolean con1 = true;
do{
int input = new Scanner(System.in).nextInt();
switch (input){
case 2:
case 7:
case 9:
case 12:
case 14:
case 18:
case 19:
case 23:
try {
int indexOfGround = findGround(grounds, input);
if(indexOfGround != -1){
grounds.get(indexOfGround).setOwner(Board.getInstance().bank.banker);
if(grounds.get(indexOfGround).isHotel()){
addBalance(400);
lowBalance = false;
} else
addBalance(((grounds.get(indexOfGround).getNumberOfHouses()*150)+100)/2);
grounds.remove(indexOfGround);
System.out.println("You sold your ground!");
break;
}else
con1 = false;
} catch (LowBalance e) {
e.getMessage();
}break;
default: con1 = false;
break;
}
}while (!con1);
}
break;
case 3:con = true;
break;
default:
con = false;
break;
}
}while (!con);
}
public int getDepositCard() {
return depositCard;
}
public void setDepositCard(int depositCard) {
this.depositCard = depositCard;
}
public int getDepositRemain() {
return depositRemain;
}
public void setDepositRemain(int depositRemain) {
this.depositRemain = depositRemain;
}
public int getChanceToRelease() {
return chanceToRelease;
}
public void setChanceToRelease(int chanceToRelease) {
this.chanceToRelease = chanceToRelease;
}
public int getTaxCard() {
return TaxCard;
}
public void setTaxCard(int taxCard) {
TaxCard = taxCard;
}
public int getIndex() {
return Index;
}
public void setIndex(int Index) {
this.Index = Index;
}
public String getName() {
return name;
}
public int getBalance() {
return balance;
}
public void addBalance(int balance) {
this.balance += balance;
}
@Override
public String toString(){
StringBuilder cinemaString = new StringBuilder();
StringBuilder groundString = new StringBuilder();
if(cinemas.size() > 0){
for (int i = 0; i < cinemas.size(); i++) {
cinemaString.append(cinemas.get(i).getName()).append(" ").append(cinemas.get(i).getIndex()).append(" - ");
}
}
if(grounds.size() > 0){
for (int i = 0; i < grounds.size(); i++) {
groundString.append(grounds.get(i).getName()).append(" ").append(grounds.get(i).getIndex()).append(" - ");
}
}
return String.format("""
%s's turn
------------------------
balance :%d properties: %s %s
depositRemain: %d TaxCard: %d releaseCard: %d
------------------------
""",
getName(), getBalance(),cinemaString, groundString,
getDepositRemain(), getTaxCard(),getChanceToRelease());
}
}