feat: setup initial game methods

This commit is contained in:
Smigz 2023-11-24 23:47:58 -05:00
parent 8822ecfc5f
commit f56dfb8b95
3 changed files with 41 additions and 0 deletions

0
tictactoe/css/style.css Normal file
View file

0
tictactoe/index.html Normal file
View file

41
tictactoe/js/main.js Normal file
View file

@ -0,0 +1,41 @@
const game = (function() {
const gameBoard = new Array(['', '', ''], ['', '', ''], ['', '', '']);
const resetGameBoard = () => {
gameBoard.forEach(item => {
item[0] = '';
item[1] = '';
item[2] = '';
})
}
const playGame = function(){
for (i=0; i<9; i++) {
let newNum = prompt("enter a number")
printGameBoard();
};
};
const printGameBoard = () => console.log(gameBoard[0] + "\n" + gameBoard[1] + "\n" + gameBoard[2]);
const evalGameOutcome = gameBoard => {
// Checks if elements are equal
let isWinner = arr => arr.reduce(function(a,b) { return a === b ? a : false; });
// create new array of vertical game board
let vertArray;
gameBoard.forEach((_, index) => vertArray.push(vert.map(e => e[index])));
// check for winner in landscape cases
const winnerTestHorizontal = checkgameBoard.forEach(element => {
isWinner(element);
});
}
return { playGame, printGameBoard };
})();
game.playGame();