-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.java
More file actions
80 lines (65 loc) · 1.95 KB
/
Board.java
File metadata and controls
80 lines (65 loc) · 1.95 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
import javax.swing.*;
import java.awt.*;
public class Board {
private int size;
private boolean whiteTurn = true;
private int source;
private int dest;
private boolean selected;
public JFrame frame;
JButton[] btn;
Square[] spaces;
public static void main(String[] arg) {
Board board = new Board(8);
}
Board(int size) {
this.size = size; //sets board size
frame = new JFrame(); //frame setup
frame.setTitle("Draughts - White's Turn");
frame.setSize(870,900);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridBagLayout()); //uses gridbaglayout
JScrollPane scroll = new JScrollPane(panel);
GridBagConstraints gbc = new GridBagConstraints();
frame.setContentPane(scroll);
spaces = new Square[(int)Math.pow(this.size, 2)]; //creates array of squares
btn = new JButton[(int)Math.pow(this.size, 2)];
gbc.ipadx = -32; //remove button padding
gbc.ipady = -8;
for(int i = 0; i < (int)Math.pow(this.size, 2); i++) {
gbc.gridy = (i / this.size); //calcs square y coordinate
gbc.gridx = (i % this.size); //calcs square x coordinate
Square s = new Square(this, panel, gbc);
spaces[i] = s;
}
frame.setVisible(true);
}
//accessors and mutators
public boolean getTurn() {
return whiteTurn;
}
public void setTurn(boolean b) {
whiteTurn = b;
}
public boolean getSelected() {
return selected;
}
public void setSelected(boolean b) {
selected = b;
}
public int getSize() {
return size;
}
public int getSource() {
return source;
}
public void setSource(int s) {
source = s;
}
public int getDest() {
return dest;
}
public void setDest(int d) {
dest = d;
}
}