-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (45 loc) · 1.07 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
38
39
40
41
42
43
44
45
46
47
48
49
import chalk from "chalk";
import clear from "clear";
import figlet from "figlet";
import {
promptGameSettings,
promptNextMove,
promptEndGame
} from "./src/inquirer";
import { createBoard, displayBoard, updateBoard } from "./src/board";
const drawHeader = () => {
clear();
console.log(
chalk.blue(
figlet.textSync("Minesweeper", {
horizontalLayout: "full"
})
)
);
};
const drawBoard = (settings, board) => {
drawHeader();
console.log(`Hello ${settings.username}!`);
displayBoard(board);
};
const run = async () => {
try {
drawHeader();
const settings = await promptGameSettings();
const board = createBoard(settings.width, settings.height);
while (true) {
drawBoard(settings, board);
const { nextMove } = await promptNextMove();
const newBoard = updateBoard(board, nextMove);
}
const { playAgain } = await promptEndGame();
if (playAgain) {
run();
} else {
clear();
}
} catch (exception) {
console.log(chalk.red("There was an exception: " + exception));
}
};
run();