forked from CodeYourFuture/Project-terminal-tic-tac-toe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplay.js
36 lines (28 loc) · 757 Bytes
/
play.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import prompt from 'prompt';
import { isGameOver } from './status-checker.js';
import { makeMove } from './move-maker.js';
import { printBoard } from './board-printer.js';
prompt.message = '';
prompt.start();
async function playGame() {
let moveNumber = 0;
const board = [
['_', '_', '_'],
['_', '_', '_'],
['_', '_', '_']
];
while(!isGameOver(board)) {
let player = moveNumber % 2 === 0 ? 'X' : 'O';
let move;
do {
move = await getMove(player);
} while(!makeMove(board, move, player));
printBoard(board);
moveNumber++;
}
}
async function getMove(player) {
let move = await prompt.get(player);
return move[player];
}
playGame();