diff options
author | Thomas Voss <thomasvoss@live.com> | 2022-01-09 23:39:38 +0100 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2022-01-09 23:39:38 +0100 |
commit | 8844e79abe3d0b30b43739ff5d85917eff178073 (patch) | |
tree | c6dd73c5891a02493266903bd56a6defdafe6f19 | |
parent | e18aae4ccc49a6c91032e8719281460ccc63346a (diff) |
Create a Piece class
This class represents a piece on a draughts board. Pretty obvious why
this would exist I think.
-rw-r--r-- | draughts/piece.js | 23 |
1 files changed, 23 insertions, 0 deletions
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 |