-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathAmartinez2.java
56 lines (51 loc) · 1.75 KB
/
Amartinez2.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
package esi18;
import battleship.core.*;
import java.util.List;
/*
* SimpleShip
* @author Your Name
*/
public class Amartinez2 extends Ship {
public Amartinez2() {
this.initializeName("Patrick Star");
this.initializeOwner("Your Name");
this.initializeHull(1);
this.initializeFirepower(4);
this.initializeSpeed(2);
this.initializeRange(3);
}
/*
* 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) {
this.move(arena, Direction.EAST);
this.move(arena, Direction.EAST);
List<Ship> nearby = this.getNearbyShips(arena);
for (int i = 0; i < nearby.size(); i++) {
Ship other = nearby.get(i);
boolean isOnMyTeam = this.isSameTeamAs(other);
if (isOnMyTeam) {
// System.out.println("This ship is on my Team!");
} else {
// System.out.println("This ship is an enemy.");
// Ship other = nearby.get(i);
Coord placement = other.getCoord();
int enemyx = placement.getX();
int enemyy = placement.getY();
// while loop: fire until enemy sinks
int health = other.getHealth();
while (health > 0) {
this.fire(arena, enemyx,enemyy);
health--;
}
// for loop equivalent of fire until sink
// for (int health = other.getHealth(); health > 0; health--) {
// this.fire(arena, enemyx,enemyy);
// }
}
}
}
}