diff options
author | Mark Powers <markppowers0@gmail.com> | 2019-12-07 14:28:18 -0600 |
---|---|---|
committer | Mark Powers <markppowers0@gmail.com> | 2019-12-07 14:28:18 -0600 |
commit | 1682f89e7d696ddba69bbfcfff791b95fd562df5 (patch) | |
tree | 02d1ee8a7c19b6727e4bd6772907c9d375f3816a /src/js/chess-draw.js | |
parent | 298329e1bacee29f13a6a0349786a5b2b4343404 (diff) |
Add correspondence chess
Diffstat (limited to 'src/js/chess-draw.js')
-rw-r--r-- | src/js/chess-draw.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/js/chess-draw.js b/src/js/chess-draw.js new file mode 100644 index 0000000..2cac33f --- /dev/null +++ b/src/js/chess-draw.js @@ -0,0 +1,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) +}
\ No newline at end of file |