-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.java
More file actions
81 lines (77 loc) · 1.35 KB
/
Copy pathPlayer.java
File metadata and controls
81 lines (77 loc) · 1.35 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
package IT178Monopoly;
public class Player {
private String name;
private int location;
private int cash;
final int STARTING_CASH= 300;
final int PASS_GO_CASH = 200;
public Player(){
cash = STARTING_CASH;
name = "";
location = 0;
}
/**
*
* @param name Name of the player in the new Object
*/
public Player(String name){
cash = STARTING_CASH;
this.name = name;
location = 0;
}
/**
*
* @param payer the Player Object who is paying this player.
* @param rent
*/
public void payOwner(Player payer, int rent){
this.cash +=rent;
if(payer != null){
payer.cash -= rent;
}
}
/**
*
* @param price price of the property to buy.
* @return returns null if unable to afford the property.
*/
public Player buyFunction(int price){
if(this.cash> price){
this.cash -=price;
return this;
}else
return null;
}
/**
*
* @return Name of the person
*/
public String getName(){
return name;
}
/**
*
* @return location of the player (0-39)
*/
public int getLocation(){
return location;
}
/**
*
* @param spaces Number of spaces to move.
*/
public void move(int spaces){
this.location += spaces;
if (location > 39){
location-=40;
cash += PASS_GO_CASH;
}
}
/**
* returns the current cash reserves of the person.
* @return
*/
public int getCash(){
return cash;
}
}