-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
37 lines (35 loc) · 1.06 KB
/
index.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
37
'use strict';
const Play = require('./play');
const inquirer = require('inquirer');
const config = require('./config.json');
console.log(" ======= Enter players name ======= ");
const askPlayersName = config.pieces.map((p,i)=>{
return {
type:'input',
message: `player ${i+1} name :-`,
name:`player${i+1}`
}
});
async function main() {
const game = new Play.Game();
const names = await inquirer.prompt(askPlayersName);
game.setPlayers(names);
const playerName = game.getPlayers()
game.result = 'Game Over';
for(let i=0; i<config.gridSize**2;i++){
const currentPlayerPiece = game.getCurrentPlayerPiece()
const move = await inquirer.prompt([{
type:'input',
name:'play',
message:` ----- ${currentPlayerPiece} turn :: enter your move ${playerName[currentPlayerPiece]} -----`
}])
const res = game.makeMove(move.play);
if(res) {
game.result = res;
break;
}
}
console.log(game.result);
process.exit();
}
main();