-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathGabrielsaucedo.java
74 lines (64 loc) · 2.2 KB
/
Gabrielsaucedo.java
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
package esi18;
import battleship.core.*;
import java.util.List;
/*
* SimpleShip
* @author Your Name
*/
public class Gabrielsaucedo extends Ship {
public Gabrielsaucedo() {
this.initializeName("Gabe");
this.initializeOwner("Gabe");
this.initializeHull(2);
this.initializeFirepower(3);
this.initializeSpeed(1);
this.initializeRange(4);
}
/*
* Determines what actions the ship will take on a given turn
* @param arena (Arena) the battlefield for the match
* @return void
*/
@Override
protected void doTurn(Arena arena) {
// instruction for ship behavior here
this.fire(arena, 1, 3);
// get a list of nearby ships
List<Ship> targets = this.getNearbyShips(arena);
// access the list if there are any nearby ships
if (targets.size() > 0) {
// get the first ship in the targets list
Ship ship = targets.get(0);
Coord location = ship.getCoord();
int x = location.getX();
int y = location.getY();
this.fire(arena, x, y);
int numMoves = this.getRemainingMoves();
while(numMoves > 0) {
// move north, west until there's only one turn left
this.move(arena, Direction.NORTH);
this.move(arena, Direction.WEST);
// update the number of turn remaining
numMoves = this.getRemainingMoves();
}
this.move(arena, Direction.EAST);
// instruction for ship behavior here
this.fire(arena, 1, 3);
// get a list of nearby ships
// List<Ship> targets = this.getNearbyShips(arena);
// loop over all nearby ships
for (int index = 0; index < targets.size(); index += 1) {
Ship shipInfo = targets.get(index);
System.out.println("One nearby ship has " + shipInfo.getHealth() + " HP left.");
}
System.out.println("There are " + targets.size() + " number of nearby ships");
// if there is atleast one nearby ships
if (targets.size() > 0) {
// get the first ship in the list
Ship first = targets.get(0);
// get the fourth ship in the list
Ship fourth = targets.get(0);
}
}
}
}