-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathLocation.java
More file actions
106 lines (91 loc) · 2 KB
/
Location.java
File metadata and controls
106 lines (91 loc) · 2 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
public class Location
{
// Global Vars
public static final int UNGUESSED = 0;
public static final int HIT = 1;
public static final int MISSED = 2;
// Instance Variables
private boolean hasShip;
private int status;
private int lengthOfShip;
private int directionOfShip;
// Location constructor.
public Location()
{
// Set initial values
status = 0;
hasShip = false;
lengthOfShip = -1;
directionOfShip = -1;
}
// Was this Location a hit?
public boolean checkHit()
{
if (status == HIT)
return true;
else
return false;
}
// Was this location a miss?
public boolean checkMiss()
{
if (status == MISSED)
return true;
else
return false;
}
// Was this location unguessed?
public boolean isUnguessed()
{
if (status == UNGUESSED)
return true;
else
return false;
}
// Mark this location a hit.
public void markHit()
{
setStatus(HIT);
}
// Mark this location a miss.
public void markMiss()
{
setStatus(MISSED);
}
// Return whether or not this location has a ship.
public boolean hasShip()
{
return hasShip;
}
// Set the value of whether this location has a ship.
public void setShip(boolean val)
{
this.hasShip = val;
}
// Set the status of this Location.
public void setStatus(int status)
{
this.status = status;
}
// Get the status of this Location.
public int getStatus()
{
return status;
}
public int getLengthOfShip()
{
return lengthOfShip;
}
public void setLengthOfShip(int val)
{
lengthOfShip = val;
}
public int getDirectionOfShip()
{
return directionOfShip;
}
public void setDirectionOfShip(int val)
{
directionOfShip = val;
}
}