From 8844e79abe3d0b30b43739ff5d85917eff178073 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 9 Jan 2022 23:39:38 +0100 Subject: Create a Piece class This class represents a piece on a draughts board. Pretty obvious why this would exist I think. --- draughts/piece.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 draughts/piece.js diff --git a/draughts/piece.js b/draughts/piece.js new file mode 100644 index 0000000..4635aee --- /dev/null +++ b/draughts/piece.js @@ -0,0 +1,23 @@ +/* A class representing a piece on a draughts board. It has a position within the board, a color, an + * ID which corresponds to its ID in the HTML DOM, and whether or not its a kinged piece. + */ +const Piece = function(x, y, color, id) { + this.position = { + x: x, + y: y + } + this.color = color + this.id = id + this.isKing = false +} + +/* Move the given piece to the coordinates specified by `direction' */ +Piece.prototype.movePiece = direction => { + let x = direction[0] + let y = direction[1] + + if (x <= 9 && x >= 0 && y <= 9 && y >= 0) + this.position = direction +} + +module.exports = Piece -- cgit v1.2.3