-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
135 lines (114 loc) · 2.71 KB
/
Copy pathPlayer.java
File metadata and controls
135 lines (114 loc) · 2.71 KB
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
package lastproj;
import java.util.Arrays;
public class Player {
private String name;
private int bal;
private int prOwn;
private int[] prPos = new int[14];
private int pos;
private boolean status;
private int JCard;
private int Try;
public Player(String name) {
this.name = name;
bal = 1000;
prOwn = 0;
pos = 0;
status = false;
JCard = 0;
Try = 0;
}
public String getName() { // get name
return this.name;
}
public int getBal() { // get balance
return this.bal;
}
public int getPos() { // get position
return this.pos;
}
public int getOwn() { // get owned properties
return this.prOwn;
}
public int getJCard() { // get free jail card amount
return this.JCard;
}
public int getTry() { // get try count (jail free)
return this.Try;
}
public void getProp() { // get list owned properties
if(prOwn > 0){
for(int i=0 ; i<prOwn ; i++){
if(i>0) System.out.print(",");
System.out.print(prPos[i]);
}
System.out.print("\n");
}
else
System.out.print("-\n");
}
public boolean isJail() { // jail status
return this.status;
}
public void altBal(int type, int bal) { // 0 = reduce, 1 = add
if(type==0) this.bal -= bal;
else this.bal += bal;
}
public void altPr(int type) { // 0 = reduce, 1 = add
if(type==0) prOwn--;
else prOwn++;
}
public void altJCard(int type) { // 0 = reduce, 1 = add
if(type==0) JCard--;
else JCard++;
}
public void altTry(int type) { // 0 = add try, 1 = reset
if(type==0) Try++;
else if(type==1) Try = 0;
}
public void setPos(int pos) { // set position
this.pos = pos;
}
public void setStat(boolean status) { // set status
this.status = status;
}
public void addProp(int index) { // add properties list
prPos[prOwn] = index;
altPr(1);
if(prOwn > 1) Arrays.sort(prPos, 0, prOwn);
}
public void remProp(int index) { // remove property
for(int i=0 ; i<prOwn ; i++){
if(prPos[i]==index){
prPos[i] = prPos[i+1];
for(int j=i+1 ; j<prOwn-1 ; j++)
prPos[j] = prPos[j+1];
altPr(0);
if(getOwn() > 0) Arrays.sort(prPos, 0, prOwn);
break;
}
}
}
// buy from bank
public void buyProp(Map map, int pos) {
altBal(0, map.getVal());
map.setOwner(getName());
addProp(pos);
System.out.println("Transaksi berhasil(bayar $" + map.getVal() + ").");
}
// sell to bank
public void sellProp(Map map, int pos) {
map.setOwner("-");
altBal(1, map.getSell());
remProp(pos);
System.out.println("Transaksi berhasil(terima $" + map.getSell() + ").");
}
// transfer property to other player
public void transfer(Player p, Map map, int pos, int price) {
altBal(1, price);
remProp(pos);
p.altBal(0, price);
p.addProp(pos);
map.setOwner(p.getName());
}
}