-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoats.java
More file actions
100 lines (97 loc) · 1.78 KB
/
Copy pathBoats.java
File metadata and controls
100 lines (97 loc) · 1.78 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
package BoatTypes;
public class Boats
{
String name;
int spaces;
char boatChar;
int rowBegin;
int colBegin;
int rowEnd;
int colEnd;
boolean isVertical = false;
boolean[] isHit;
boolean isSunk;
public int health;
public void setBoatVar(int row, int col, boolean isVertical)
{
this.rowBegin = row;
this.colBegin = col;
this.isVertical = isVertical;
if (isVertical)
{
this.rowEnd = rowBegin + (spaces - 1);
this.colEnd = colBegin;
}
else
{
this.colEnd = colBegin + (spaces - 1);
this.rowEnd = rowBegin;
}
this.isSunk = false;
}
public boolean isHere(int x, int y)
{
boolean condition = false;
if (isVertical)
{
// if the boat is vertical the col is constant, and the row varies between the boat rowBegin and boat rowEnd
if (this.colBegin == this.colEnd && this.colEnd == y && this.rowBegin <= x && x <= this.rowEnd)
{
condition = true;
}
}
else
{
// if the boat is not vertical the row remains the same and the col varies between colBegin and colEnd
if (this.rowBegin == this.rowEnd && this.rowEnd == x && this.colBegin <= y && y <= this.colEnd)
{
condition = true;
}
}
return condition;
}
public void setHit()
{
this.health -= 10;
if (health <= 0)
{
System.out.println("BOAT SUNK");
}
}
public String getName()
{
return name;
}
public int getSpaces()
{
return spaces;
}
public char getboatChar()
{
return boatChar;
}
public void setRowBegin(int row)
{
this.rowBegin = row;
}
public void setColBegin(int col)
{
this.colBegin = col;
}
public int getRowBegin()
{
return this.rowBegin;
}
public int getColBegin()
{
return this.colBegin;
}
public void setIsVertical(boolean b)
{
this.isVertical = b;
}
public boolean getIsVertical()
{
return this.isVertical;
}
}