-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardGraphic.java
More file actions
60 lines (51 loc) · 1.34 KB
/
Copy pathBoardGraphic.java
File metadata and controls
60 lines (51 loc) · 1.34 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
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class BoardGraphic extends JComponent{
private Board underlying;
public BoardGraphic(){
underlying=new Board();
}
public Board board(){
return underlying;
}
public void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;
int boxStarterX=55;
int boxStarterY=35;
Rectangle outline=new Rectangle(50,30,410,410);
g2.setColor(Color.BLACK);
g2.fill(outline);
for(int i=0;i<8;i++){
//make a row of boxes
for(int j=0;j<8;j++){
Rectangle box=new Rectangle(boxStarterX,boxStarterY,50,50);
if((i%2==0&&j%2==0)||(i%2==1&&j%2==1)){
g2.setColor(Color.LIGHT_GRAY);
}else{
g2.setColor(Color.BLACK);
}
g2.fill(box);
BoardSpace curr=underlying.getBoardSpace(boxStarterX+10,boxStarterY+10);
if(curr.isOccupied()){
Ellipse2D.Double checker = new Ellipse2D.Double(boxStarterX+10,boxStarterY+10,30,30);
if(curr.getChecker().isRed()){
g2.setColor(Color.RED);
g2.fill(checker);
}else{
g2.setColor(Color.BLACK);
g2.fill(checker);
}
if(curr.getChecker().isCrowned()){
Rectangle crown=new Rectangle(boxStarterX+20,boxStarterY+20,10,10);
g2.setColor(Color.WHITE);
g2.fill(crown);
}
}
boxStarterX+=50;
}
boxStarterY+=50;
boxStarterX=55;
}
}
}