-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (31 loc) · 955 Bytes
/
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
console.log("script started");
const game = require("./gameHelper");
const input = require("./service/input");
// const config = require("./config/config");
async function initializeGame() {
let gameState = {}; // stores the state for a game
gameState.name = await input.name();
gameState.size = await input.size();
gameState.board = game.blankBoard(gameState.size);
gameState.score = 0;
gameState.status = "progress";
return gameState;
}
async function fetchMove(gameState) {
const dir = await input.move();
let {name, status} = gameState
gameState = game.move(gameState, dir);
if(status == "progress"){
fetchMove(gameState);
}else{
console.log(`${name}, You ${status}`)
}
}
async function startGame(){
let gameState = await initializeGame();
console.log(gameState)
gameState.board = game.randomTile(gameState);
gameState.board = game.randomTile(gameState);
fetchMove(gameState);
}
startGame();