blob: 7445073acf99c0d8d9cdbd237e6c82c59c58ec96 (
plain) (
blame)
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
|
package design.model.holeplay;
import design.model.*;
import design.persistence.PersonalDatabase;
public class HolePlayContext {
private final Golfer golfer;
private final Round round;
private final PersonalDatabase pdb;
private HoleState state;
private Play currentPlay;
private int strokes;
private int distanceRemainingYds;
public HolePlayContext(Golfer golfer, Round round, PersonalDatabase pdb) {
this.golfer = golfer;
this.round = round;
this.pdb = pdb;
setState(new SetupState());
}
public void setState(HoleState next) {
this.state = next;
next.enter(this);
}
// API the PTUI/Commands will call:
public void startHole() {
state.handleStart(this);
}
public void recordShot(Club club, Integer distanceYds) {
state.handleShot(this, club, distanceYds);
}
public void holeOut() {
state.handleHoleOut(this);
}
// package-private helpers the states use:
void beginNewPlay(int holeNumber, int par) {
/* create Play, reset counters */ }
void addSwing(Club club, Integer distanceYds) {
/* add Swing to currentPlay; strokes++; distanceRemainingYds -= distanceYds */ }
void finalizePlayAndPersist() {
/* round.addPlay(currentPlay); currentPlay=null; pdb.updateGolfer(golfer); */ }
// getters you’ll want:
public Golfer getGolfer() {
return golfer;
}
public Round getRound() {
return round;
}
public Play getCurrentPlay() {
return currentPlay;
}
public int getStrokes() {
return strokes;
}
public int getDistanceRemainingYds() {
return distanceRemainingYds;
}
// setters used internally
void setCurrentPlay(Play p) {
this.currentPlay = p;
}
void setStrokes(int s) {
this.strokes = s;
}
void setDistanceRemainingYds(int d) {
this.distanceRemainingYds = d;
}
}
|