This is a short tech test that is designed to emulate a game of TicTacToe written in Javascript and tested with Jasmine
This game has been designed to be used in the console. In order to play this game, create a new game with game = new Game(turn = new Turn(player = new Player))
. This generates a new game, with two players, X and O. You can show the current board with game.displayerBoard()
.
You can then take it in turns to add an X or O to the board with the command game.playerMove(1)
with the argument being the square you want to play.
This tech test is a work in progress and if I had more time to complete this I would include win conditions within the Game constructor function. This would consist of a prototype function that would identify if the this.board
array has three consecutive elements of X or O.
I would also most likely refactor the Player constructor function as it is only wrapped around playerX and playerO rather than having any particular behaviour.