-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathApalmer8.java
More file actions
59 lines (51 loc) · 1.57 KB
/
Apalmer8.java
File metadata and controls
59 lines (51 loc) · 1.57 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
package esi18;
import battleship.core.*;
import java.util.List;
/*
* SimpleShip
* @author Your Name
*/
public class Apalmer8 extends Ship {
public Apalmer8() {
this.initializeName("Apalmer8");
this.initializeOwner("Andrew");
this.initializeHull(2);
this.initializeFirepower(5);
this.initializeSpeed(1);
this.initializeRange(1);
}
/*
* Determines what actions the ship will take on a given turn
* @param arena (Arena) the battlefield for the match
* @return void
*/
protected void doTurn(Arena arena) {
// your implementation of a ship
// gets the current location of the ship
Coord coord = this.getCoord();
int x = coord.getX();
int y = coord.getY();
if (x > 8) {
this.move(arena, Direction.WEST);
}
else if (x < 2) {
this.move(arena, Direction.EAST);
}
else if (y > 8) {
this.move(arena, Direction.NORTH);
}
else if (y < 2) {
this.move(arena, Direction.SOUTH);
}
else {
// make a list of all the location, and store it in a variable
Direction[] possibleMovement = {Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST};
// get a random number and store it in a variable
int randomNumber = arena.getRandom().nextInt(4);
// get a random movement by using the random number to access one possibleMovement
this.move(arena, possibleMovement[randomNumber]);
}
// ship using this instruction will fire at location (x: 0, y: 0) each turn
this.fire(arena, 0, 0);
}
}