-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChessSquare.java
More file actions
99 lines (85 loc) · 2.16 KB
/
Copy pathChessSquare.java
File metadata and controls
99 lines (85 loc) · 2.16 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
public class ChessSquare {
private int row;
private int column;
private char col;
private boolean hasPiece;
private String color;
private ChessPiece piece;
public ChessSquare(int row, int column){
this.row = row;
this.column = column;
convertColumn(column);
hasPiece = false;
}
public void convertColumn(int c){
switch(c){
case 0:
col = 'A';
break;
case 1:
col = 'B';
break;
case 2:
col = 'C';
break;
case 3:
col = 'D';
break;
case 4:
col = 'E';
break;
case 5:
col = 'F';
break;
case 6:
col = 'G';
break;
case 7:
col = 'H';
break;
}
}
public ChessSquare(int row, int column, ChessPiece piece){
this.row = row;
this.column = column;
this.piece = piece;
hasPiece = false;
}
public void addPiece(ChessPiece c){
this.piece = c;
this.hasPiece = true;
}
public void removePiece(){
this.piece = null;
this.hasPiece = false;
}
public void Show(){
//include code for highlighting the square in the graphics
System.out.print("---");
}
public int getRow(){
return row;
}
public int getColumn(){
return column;
}
public char getCol(){
return col;
}
public boolean hasPiece(){
return hasPiece;
}
public ChessPiece getPiece(){
return piece;
}
public String printPiece(){
return piece.getName() + " " + Character.toString(col) + Integer.toString(row);
}
public boolean equals(ChessSquare c){
if (c.getRow() == this.getRow() && c.getColumn() == this.getColumn()){
return true;
}else{
return false;
}
}
}