mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-06-28 12:55:36 -04:00
feat: created basic prompt for input
This commit is contained in:
parent
3534828db1
commit
9103833e93
1 changed files with 25 additions and 9 deletions
|
@ -1,4 +1,12 @@
|
||||||
const game = (function() {
|
const game = (function() {
|
||||||
|
// only needed for CLI game
|
||||||
|
const readline = require("readline");
|
||||||
|
const rl = readline.createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
let gameBoard = new Array(['', '', ''], ['', '', ''], ['', '', '']);
|
let gameBoard = new Array(['', '', ''], ['', '', ''], ['', '', '']);
|
||||||
|
|
||||||
const resetGameBoard = () => {
|
const resetGameBoard = () => {
|
||||||
|
@ -9,13 +17,19 @@ const game = (function() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const playGame = function(){
|
const playGame = function(){
|
||||||
placeOnBoard(2, 'x');
|
rl.question('Where would you like the piece placed?', position => {
|
||||||
|
position = Number(position);
|
||||||
|
placeOnBoard(position, 'x');
|
||||||
|
rl.close();
|
||||||
printGameBoard();
|
printGameBoard();
|
||||||
// for (i=0; i<9; i++) {
|
})
|
||||||
|
|
||||||
|
// for (let i=0; i<9; i++) {
|
||||||
// printGameBoard();
|
// printGameBoard();
|
||||||
|
// // evalGameOutcome(gameBoard);
|
||||||
// };
|
// };
|
||||||
// evalGameOutcome(gameBoard);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const placeOnBoard = (position, marker) => {
|
const placeOnBoard = (position, marker) => {
|
||||||
|
@ -49,6 +63,7 @@ const game = (function() {
|
||||||
gameBoard[2][2] = marker;
|
gameBoard[2][2] = marker;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
console.log('Must enter a number 1 - 9');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,13 +80,13 @@ const game = (function() {
|
||||||
let diagArray = [
|
let diagArray = [
|
||||||
[gameBoard[0][0], gameBoard[1][1], gameBoard[2][2]],
|
[gameBoard[0][0], gameBoard[1][1], gameBoard[2][2]],
|
||||||
[gameBoard[0,2], gameBoard[1][1], gameBoard[2][0]]
|
[gameBoard[0,2], gameBoard[1][1], gameBoard[2][0]]
|
||||||
]
|
];
|
||||||
|
|
||||||
let checkGameBoard = [gameBoard, diagArray, vertArray];
|
let checkGameBoard = [gameBoard, diagArray, vertArray];
|
||||||
for (i=0; i<3; i++) {
|
for (i=0; i<3; i++) {
|
||||||
let outcome = _evalGameOutcome(checkGameBoard[i]);
|
let outcome = _evalGameOutcome(checkGameBoard[i]);
|
||||||
if (outcome) console.log(outcome[0]);
|
if (outcome) console.log(outcome[0]);
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const _evalGameOutcome = arr => {
|
const _evalGameOutcome = arr => {
|
||||||
|
@ -89,8 +104,9 @@ const game = (function() {
|
||||||
return outcome;
|
return outcome;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return { playGame, printGameBoard };
|
return { playGame, printGameBoard };
|
||||||
})();
|
})();
|
||||||
|
|
||||||
game.playGame();
|
game.playGame();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue