-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathField.java
More file actions
34 lines (30 loc) · 1.01 KB
/
Field.java
File metadata and controls
34 lines (30 loc) · 1.01 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
import java.util.ArrayList;
import java.util.Arrays;
public class Field {
private ArrayList<Base> bases;
public Field(){
bases = new ArrayList<Base>(Arrays.asList( //create list of bases on field
new Base("Dugout"),
new Base("BatterBox"),
new Base("First"),
new Base("Second"),
new Base("Third"),
new Base("Home")
));
}
//getters and setters
public Base getDugout(){
return bases.get(0);
}
public Base getBatterBox(){
return bases.get(1);
}
//move players around the bases, used for hits and walks when batting
public Base moveAhead(Base startingBase, int numberOfBases){
int startingBaseIndexNumber = bases.indexOf(startingBase);
//move ahead number of bases, but staying withing the range of bases
int newBaseIndexNumber = Math.min(startingBaseIndexNumber + numberOfBases, 5);
Base newBase = bases.get(newBaseIndexNumber);
return newBase;
}
}