aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--draughts/piece.js23
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