-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
89 lines (76 loc) · 2.64 KB
/
Copy pathPlayer.java
File metadata and controls
89 lines (76 loc) · 2.64 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package finalproject;
public interface Player {
/**
* Add a ship to whatever collection of ships the Player uses to keep track of its ships
*
* @param s the ship to add
*/
/**
* Add a ship to whatever collection of ships the Player uses to keep track of its ships
* Note: This method should only return true upon successful addition to the collection
*
* @param s the ship to be added
* @return whether the ship was successfully added to the collection
*/
public boolean addShip(Ship s);
/**
* Ask the user for the location they want to fire at
*
* @return an integer array of length 2 which contains the (x,y) location the player wants to fire at
*/
public int[] getTargetLocation();
/**
* Record on the board/radar whether a shot made was a hit or a miss
*
* @param x the x location to record if hit or miss
* @param y the y location to record if hit or miss
* @param isHit whether the shot was a hit (true) or miss (false)
*/
public void recordHitOrMiss(int x, int y, boolean isHit);
/**
* Given the length of a ship, decide where on the board to place that ship
* Note: The decision must be valid, i.e. the ship does not overlap any other ships or go off the board, etc
*
* @param sl the length of the ship to place
* @return a Ship instance with the desired (x, y) location, length, and orientation
*/
public Ship decideShipPlacement(int length);
/**
* @return the name of the player
*/
public String getName();
/**
* Tell whether any of the player's ships were hit given an (x, y) firing location
* And record that hit on the ship
*
* @param x the x location the other player shot at
* @param y the y location the other player shot at
* @return true if hit, false if miss
*/
public boolean respondToFire(int x, int y);
/**
* Tell how many of the player's ships have been sunk / how many have not yet been sunk
*
* @return the number of ships still afloat
*/
public int numShipsStillAfloat();
/**
* Randomly place a ship of the given length in a valid location
* Be sure to add it to the collection of ships for the game
* Note: The random ship should NOT OVERLAP any existing ships
*
* @param length the length of the ship to be added
*/
public boolean addRandomShip(int length);
/**
* Tell whether a given ship s will intersect any of the existing ships
* @param s the ship to add
* @return whether the ship intersects any other ships on the board
*/
public boolean isValidShipToAdd(Ship s);
/**
* Prints out the radar indicating where the user has fired,
* and whether those fires were hits or misses
*/
public void printRadar();
}