Repository navigation
Expand file tree
/
Copy pathGameBoardGUI.java
More file actions
113 lines (96 loc) · 3.18 KB
/
Copy pathGameBoardGUI.java
File metadata and controls
113 lines (96 loc) · 3.18 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class GameBoardGUI extends JFrame {
private checkerCanvas canvas = new checkerCanvas();
private GameBoard gameboard;
//make blank canvas
public GameBoardGUI(GameBoard check){
gameboard = check;
setLayout(new BorderLayout());
setSize(750, 750);
setTitle("Checkers");
add("Center", canvas);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
}
private class checkerCanvas extends Canvas {
//update method
@Override
public void update(Graphics g){
repaint();
}
//paint method
@Override
public void paint(Graphics g){
int square = 65; //size of each square
int xBound = 105; //x alignment
int yBound = 555; //y alignment
Color myColor = new Color(78, 53, 36);
g.setColor(myColor);
g.fillRect(0, 0, 750, 750);
//draw board
int baseCord = 133;
int baseCordY = 593;
Color myColor2 = new Color(255, 255, 255); //draw letters and dnumbers
g.setColor(myColor2);
g.drawString("A", baseCord, 645);
g.drawString("B", (baseCord + square), 645);
g.drawString("C", (baseCord + square*2), 645);
g.drawString("D", (baseCord + square*3), 645);
g.drawString("E", (baseCord + square*4), 645);
g.drawString("F", (baseCord + square*5), 645);
g.drawString("G", (baseCord + square*6), 645);
g.drawString("H", (baseCord + square*7), 645);
g.drawString("0", 80, baseCordY);
g.drawString("1", 80, (baseCordY - square));
g.drawString("2", 80, (baseCordY - square*2));
g.drawString("3", 80, (baseCordY - square*3));
g.drawString("4", 80, (baseCordY - square*4));
g.drawString("5", 80, (baseCordY - square*5));
g.drawString("6", 80, (baseCordY - square*6));
g.drawString("7", 80, (baseCordY - square*7));
//draw board
for(int x=0;x<8;x++){
for(int y=0;y<8;y++){
g.setColor(Color.black);
if(((x+y) % 2 == 0)){
g.fillRect((xBound + x*square), (yBound - y*square), square, square);
}else{
g.setColor(Color.white);
g.fillRect((xBound + x*square), (yBound - y*square), square, square);
}
}
}
//check 2d gb array to determine piece placement and draw piece
Checkers[][] checkers = gameboard.getBoard();
String color;
for(int a=0;a<8;a++){
for(int b=0;b<8;b++){
if(!(checkers[a][b] == null)){
color = checkers[a][b].getColor();
if(color.equalsIgnoreCase("blue")){
g.setColor(Color.blue);
if(checkers[a][b].isKing() == false){
g.fillOval((xBound + a*square), (yBound - b*square), square, square);
}else{
g.setColor(Color.green);
g.fillOval((xBound + a*square), (yBound - b*square), square, square);
}
}else{
g.setColor(Color.red);
if(checkers[a][b].isKing() == false){
g.fillOval((xBound + a*square), (yBound - b*square), square, square);
}else{
g.setColor(Color.orange);
g.fillOval((xBound + a*square), (yBound - b*square), square, square);
}
}
}
}
}
}
}
}