forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBallPlayer.java
More file actions
158 lines (132 loc) · 3.16 KB
/
BallPlayer.java
File metadata and controls
158 lines (132 loc) · 3.16 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import java.util.Random;
public class BallPlayer
{
private int position;
private String name;
private int fouls;
private int possessions;
private int turnovers;
public BallPlayer(String name)
{
this.position = 1;
this.name = name;
this.fouls = 0;
this.possessions = 0;
}
public int getPosition()
{
return position;
}
public String getName()
{
return name;
}
public int getTurnovers()
{
return turnovers;
}
public boolean scoring(PairOfDice dice)
{
boolean foulOccur = false;
int score = 0;
switch (dice.getDieTotalValue())
{
case 2:
score = 3;
this.possessions++;
break;
case 3:
this.turnovers++;
this.possessions++;
break;
case 4:
score = 2;
this.possessions++;
break;
case 5:
score = 1;
foulOccur = true;
break;
case 6:
score = 2;
this.possessions++;
break;
case 7:
this.turnovers++;
this.possessions++;
break;
case 8:
score = 2;
foulOccur = true;
break;
case 9:
break;
case 10:
score = 2;
this.possessions++;
foulOccur = true;
break;
case 11:
this.turnovers++;
this.fouls++;
this.possessions++;
foulOccur = true;
break;
case 12:
score = 3;
this.possessions++;
break;
}
this.position += score;
return foulOccur;
}
public int getPossessions()
{
return possessions;
}
public String getShot(PairOfDice dice)
{
String shot = "";
switch (dice.getDieTotalValue())
{
case 2:
case 12:
shot = "#3Ball from Downtown";
break;
case 4:
case 6:
shot = "#BOOMSHAKALAKA! #SlamDunk";
break;
case 3:
shot = "#TravelerTurnover";
break;
case 5:
shot = "#FoulAtTheRim #1and1";
break;
case 7:
shot = "#Turnover #CrabDribble";
break;
case 8:
shot = "#TechnicalFoul4Coach #Easy2";
break;
case 9:
shot = "#Clang #GetOnTheFloor";
break;
case 10:
shot = "#AndOne #JellyFam";
break;
case 11:
shot = "#Charge #Take1ForTheTeam";
break;
}
return shot;
}
public int assignFoul()
{
return fouls++;
}
public int getFouls()
{
return fouls;
}
}