-
Notifications
You must be signed in to change notification settings - Fork 0
/
Square
54 lines (45 loc) · 927 Bytes
/
Square
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
/*
This class models the individual squares inside the small
tic-tac-toe boards
*/
import java.io.IOException;
public class Square extends Board {
// default constructor
public Square() {
status = NONE;
}
// implementing stub method
@Override
public void placePiece(Point largePos, Point smallPos, char piece) throws IOException {
// changes status depending on piece
if (piece == 'X') {
status = X;
} else if (piece == 'O') {
status = O;
}
}
// checking if the square is empty
public boolean isEmpty() {
// check status
if (status == NONE) {
return true;
} else {
return false;
}
}
// what to print out in the square
public String toString() {
// print appropriate char
if (status == 1) {
return "X";
} else if (status == 2) {
return "O";
} else {
return " ";
}
}
// removing a piece from the board
public void removePiece() {
status = NONE;
}
}