-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.java
More file actions
62 lines (51 loc) · 1.25 KB
/
Board.java
File metadata and controls
62 lines (51 loc) · 1.25 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
package chess;
import java.awt.Graphics2D;
import java.io.PrintStream;
public class Board{
private Piece [][] pieces;
private BackGround[][] theBackGround;
private int col, row;
public Board(int row, int col){
this.col = col;
this.row = row;
pieces = new Piece [row][col];
theBackGround = new BackGround[row][col];
}
public void paint(Object media) {
PrintStream out= (PrintStream) media;
for ( Piece[] row : pieces){
for (Piece e : row){
e.paint(media);
}
out.println();
}
}
public void place (Piece p, int row, int col){
pieces [row][col] = p;
p.place(row,col);
}
public void move(int row1, int col1, int row2, int col2){
pieces[row1][col1].place(row2,col2); // set the pieces know its new position
pieces[row2][col2] = pieces[row1][col1]; // relocate the piece on the board
remove(row1,col1);
}
public void remove(int row, int col){
pieces[row][col] = new Dummy();
pieces[row][col].place(row,col);
}
public Piece look (int row, int col){
return pieces[row][col];
}
public void paint(Graphics2D g2){
for(int i = 0;i<row;i++)
{
for(int j = 0;j<col;j++)
{
theBackGround[row][col].paint(g2);
}
}
}
public void setBG(BackGround bg, int i, int j) {
theBackGround[i][j] = bg;
}
}