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
|
function draw_selected(){
if(selected){
color("yellow")
ctx.fillRect(50*(selected.col-1), 50*(8-selected.row), 50, 50)
}
}
function draw_piece(piece){
if(piece.inactive){
return;
}
if(piece.side == "white"){
color("white")
} else {
color("black")
}
ctx.fillRect(50*(piece.col-1)+15, 50*(8-piece.row)+15, 20, 20);
if(piece.side == "white"){
color("black")
} else {
color("white")
}
ctx.fillText(piece.type, 50*(piece.col-1)+18, 50*(8-piece.row+0.2)+20)
}
function draw() {
font(20)
color("#ddd");
ctx.fillRect(0, 0, 400, 600);
color("#aaa")
for(var x = 0; x < 8; x++){
for(var y = 0; y < 8; y++){
if(x % 2 == 0 && y % 2 == 1){
ctx.fillRect(50*x, 50*y, 50, 50);
}
if(x % 2 == 1 && y % 2 == 0){
ctx.fillRect(50*x, 50*y, 50, 50);
}
}
}
draw_selected();
pieces.forEach(piece => {
draw_piece(piece)
});
color("black")
ctx.fillText(status, 20, 420)
}
|