-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point.java
88 lines (73 loc) · 1.84 KB
/
Point.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
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
public class Point {
private int row;
private int column;
private boolean isShip;
private boolean hit = false;
private boolean miss = false;
protected GameBoard board;
public Point(int r, int c, GameBoard b, boolean s) {
row = r;
column = c;
board = b;
isShip = s;
}
public char displayCharacter() {
// label axes
if (this.getRow() == 0 && this.getColumn() == 0) {
return ' ';
} else if (this.getRow() == 0 && this.getColumn() > 0) {
//labels
int a = 47 + this.getColumn();
return (char)a;
} else if (this.getColumn() == 0 && this.getRow() > 0) {
//labels
int a = 47 + this.getRow();
return (char)a;
} else if (this.getHit()) {
return 'X';
} else if (this.getMiss()) {
return '.';
}
// display ships
else if (this.getIsShip()) {
//hide ships
return '~';
}
// empty water
return '~';
}
public int getRow() {
return row;
}
public int getColumn() {
return column;
}
public boolean getIsShip() {
return isShip;
}
public void setIsShip(boolean b) {
isShip = b;
}
public boolean getHit() {
return hit;
}
public void setHit(boolean b) {
hit = b;
}
public boolean getMiss() {
return miss;
}
public void setMiss(boolean b) {
miss = b;
}
public String toString() {
return "(" + this.getRow() + ", " + this.getColumn() + ")";
}
public boolean equals(Point p) {
if (this.getRow() == p.getRow() && this.getColumn() == p.getColumn()) {
return true;
} else {
return false;
}
}
}