-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathEmagallanes.java
More file actions
62 lines (56 loc) · 1.88 KB
/
Emagallanes.java
File metadata and controls
62 lines (56 loc) · 1.88 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
package esi18;
import battleship.core.*;
import java.util.List;
/*
* SimpleShip
* @author Your Name
*/
public class Emagallanes extends Ship {
private int waitToMove;
public Emagallanes() {
this.initializeName("Emagallanes");
this.initializeOwner("Your Name");
this.initializeHull(3);
this.initializeFirepower(3);
this.initializeSpeed(2);
this.initializeRange(2);
waitToMove = 2;
}
/*
* 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) {
if (waitToMove > 0) {
waitToMove = waitToMove - 1;
// do nothing
}
else{
Coord location = this.getCoord();
this.move(arena, Direction.EAST);
// Get a list of nearby ships
List<Ship> nearby = this.getNearbyShips(arena);
// Get the number of shots left on this ship
int numShots = this.getRemainingShots();
for (int i = 0; i < nearby.size(); i++) {
if ( this.isSameTeamAs(nearby.get(i)) ) {
// if same team, don't shoot
} else {
Ship enemy = nearby.get(i);
while(enemy.getHealth() > 0 && numShots > 0) {
Coord enemyLoc = enemy.getCoord();
int x = enemyLoc.getX();
int y = enemyLoc.getY();
this.fire(arena, x, y);
numShots = this.getRemainingShots();
}
// if we get here, that means a ship has been sunk
// call this function again to update the list to not shoot at a sunk ship
nearby = this.getNearbyShips(arena);
}
}
}
}
}