-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFleet.java
More file actions
96 lines (82 loc) · 2.08 KB
/
Fleet.java
File metadata and controls
96 lines (82 loc) · 2.08 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
/* A fleet is a group of ships flying from one planet to the other.
For Week 1 we don't need it.
*/
public class Fleet implements Comparable, Cloneable {
// Initializes a fleet.
public Fleet(int owner,
int numShips,
int sourcePlanet,
int destinationPlanet,
int totalTripLength,
int turnsRemaining) {
this.owner = owner;
this.numShips = numShips;
this.sourcePlanet = sourcePlanet;
this.destinationPlanet = destinationPlanet;
this.totalTripLength = totalTripLength;
this.turnsRemaining = turnsRemaining;
}
// Initializes a fleet.
public Fleet(int owner,
int numShips) {
this.owner = owner;
this.numShips = numShips;
this.sourcePlanet = -1;
this.destinationPlanet = -1;
this.totalTripLength = -1;
this.turnsRemaining = -1;
}
// Accessors and simple modification functions. These should be mostly
// self-explanatory.
public int Owner() {
return owner;
}
public int NumShips() {
return numShips;
}
public int SourcePlanet() {
return sourcePlanet;
}
public int DestinationPlanet() {
return destinationPlanet;
}
public int TotalTripLength() {
return totalTripLength;
}
public int TurnsRemaining() {
return turnsRemaining;
}
public void RemoveShips(int amount) {
numShips -= amount;
}
// Subtracts one turn remaining. Call this function to make the fleet get
// one turn closer to its destination.
public void TimeStep() {
if (turnsRemaining > 0) {
--turnsRemaining;
} else {
turnsRemaining = 0;
}
}
public int compareTo(Object o) {
Fleet f = (Fleet)o;
return this.numShips - f.numShips;
}
private int owner;
private int numShips;
private int sourcePlanet;
private int destinationPlanet;
private int totalTripLength;
private int turnsRemaining;
private Fleet(Fleet _f) {
owner = _f.owner;
numShips = _f.numShips;
sourcePlanet = _f.sourcePlanet;
destinationPlanet = _f.destinationPlanet;
totalTripLength = _f.totalTripLength;
turnsRemaining = _f.turnsRemaining;
}
public Object clone() {
return new Fleet(this);
}
}