-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.js
112 lines (103 loc) · 3.01 KB
/
game.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import chalk from "chalk";
import inquirer from "inquirer";
import { createSpinner } from "nanospinner";
import chalkAnimation from "chalk-animation";
import { GameRules } from "./gameEngine.js";
export let animationTimer = (time = 3000) =>
new Promise((resolve) => setTimeout(resolve, time));
export const chalkColorMsg = (message, color) => {
return chalk[color](message);
};
const gameObjects = GameRules.map((rule) => rule.name);
export const gameWelcome = async () => {
const gameTitle = chalkAnimation.rainbow(
"Welcome to Game Rock Paper Scissors"
);
await animationTimer();
gameTitle.stop();
console.log(chalkColorMsg("Rules to play the game !!", "blue"));
console.log(
chalkColorMsg(
"1. You have to choose one of Game modes - Player vs Computer or Computer vs Computer",
"blue"
)
);
console.log(
chalkColorMsg(
`2. If you choose Player vs Computer, you have to choose one of the options - ${gameObjects.join(
", "
)}`,
"blue"
)
);
console.log(
chalkColorMsg(
`3. If you choose Computer vs Computer, system will automatically choose one of the options - ${gameObjects.join(
", "
)}`,
"blue"
)
);
};
export const namePrompt = async () => {
const { player_name } = await inquirer.prompt({
name: "player_name",
type: "input",
message: "Please enter your name",
validate: (value) => {
if (value.length) {
return true;
} else {
return "Please enter your name";
}
},
});
return player_name;
};
export const gameModePrompt = async () => {
const { game_mode } = await inquirer.prompt({
name: "game_mode",
type: "list",
message: "Please select game mode",
choices: ["Player vs Computer", "Computer vs Computer"],
});
return game_mode;
};
export const gamePlayAgain = async () => {
const { game_play_bool } = await inquirer.prompt({
name: "game_play_bool",
type: "list",
message: "Do you wanna play again?",
choices: ["Yes", "No"],
});
return game_play_bool;
};
export const evaluatingGameResults = async (result, gameMode, playerName) => {
const spinner = createSpinner("Evaluating...").start();
await animationTimer(2000);
if (result === undefined) {
spinner.warn({ text: "🙈🙈 Its a Draw!" });
} else if (result) {
if (gameMode === "Player vs Computer") {
spinner.success({ text: `✅✅✅ ${playerName} You Win !!!` });
} else {
spinner.success({ text: `✅✅✅ 🖥 🖥 Computer 1 Win !!!` });
}
} else {
if (gameMode === "Player vs Computer") {
spinner.error({ text: `😔😔😔 ${playerName} You Lose !!!` });
} else {
spinner.error({ text: `😔😔😔 🖥 🖥 Computer 1 Lose !!!` });
}
}
return true;
};
export const gameObjectSelection = async () => {
const { game_object } = await inquirer.prompt({
name: "game_object",
type: "list",
message: "Please select object you wanna throw",
choices: [...gameObjects],
});
return game_object;
};