diff --git a/src/js/Game.js b/src/js/Game.js index 56df0c9..749ae67 100644 --- a/src/js/Game.js +++ b/src/js/Game.js @@ -111,13 +111,41 @@ export class Game field.onclick = () => { - this.board[y][x] = this.state.currentPlayer; - this.state.turnCount++; - this.draw(); + if (this.addChip(x, y)) + { + this.state.turnCount++; + this.draw(); + } }; board.appendChild(field); } } } + + /** + * Adds a chip to the board indicated by the {@link x `x`} and the {@link y `y`} coordinate. + * + * @param {number} x + * The x coordinate to add the chip to. + * + * @param {number} y + * The y coordinate to add the chip to. + * + * @returns {boolean} + * A value indicating whether the chip could be added. + */ + addChip(x, y) + { + for (let i = Game.#height - 1; i >= 0; i--) + { + if (this.board[i][x] === "") + { + this.board[i][x] = this.state.currentPlayer; + return true; + } + } + + return false; + } }