-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
96 lines (85 loc) · 3.88 KB
/
menu.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
import readlineSync from 'readline-Sync'
import { loadGreyhoundGet, newGreyhoundPost } from './client.js';
import { myGreyhound, templateObj } from './cont.js';
import chalk from 'chalk';
import { delay } from './index.js';
import { clearScreen, cursorTo } from './map.js';
export const menu = async () => {
const MENUOPT = ['Adopt a New Greyhound', 'Load existing Greyhound', 'Help']
let index = readlineSync.keyInSelect(MENUOPT, 'Menu Options', { cancel: false });
switch (MENUOPT[index]) {
case 'Adopt a New Greyhound':
await newPlayer();
clearScreen()
cursorTo(2, 1)
console.log(`\n\nThank you for adopting ${chalk.green(myGreyhound.name)}\n`)
await delay(2000);
console.log(`It may take some time for ${chalk.green(myGreyhound.name)} to get used to retired life`)
console.log(`and adapt to your home environment.\n`)
await delay(2000)
console.log(`${chalk.green(myGreyhound.name)} can't wait to see her ${chalk.green('furEver Home')}\n`)
readlineSync.keyInPause(`Lets get Bring ${chalk.green(myGreyhound.name)} home`)
clearScreen()
cursorTo(5, 1)
console.log(`It's the next day....${chalk.green(myGreyhound.name)} is ready to explore. She has fallen in love with her new ball!`)
await delay(2000)
console.log('But keeps losing it!!!')
await delay(2000)
break;
case 'Load existing Greyhound':
await loadPlayer();
console.log("loading greyhound")
break;
case 'Help':
await help();
break;
}
}
const help = async () => {
console.log('Greyhounds need your Help!!')
await delay(2000)
console.log('Tracks are closing across the US and the dogs have no where to go!')
await delay(2000)
console.log('Greyhounds, haven\'t spent much time living a normal life')
await delay(2000)
console.log('Help guild your greyhound and adapt to their retired life\n')
await delay(2000)
console.log('use your arrow keys (or WASD ) to move around the map')
console.log('number keys 1-4 will perform the displayed actions\n')
await delay(2000)
console.log(chalk.green('Objectives'))
console.log(chalk.blue('1. Keep your greyhound fed and happy'))
console.log(chalk.blue('2. Find the missing ball in each location'))
console.log(chalk.blue(' a. The smell command will help you locate and pick up balls'))
console.log(chalk.blue('3. Interact with the world and gain experience for your greyhound'))
console.log(chalk.blue(' a. As you level up you gain more access to new actions'))
readlineSync.keyInPause('Have Fun!!')
menu();
}
export const newPlayer = async () => {
let name = readlineSync.question('What would you like to name your greyhound: ', { hideEchoBack: false, limit: /[\S\s]+[\S]+/, limitMessage: 'can not be blank' });
let icon = readlineSync.keyIn('Select a Keyboard Char to represent your greyhound: ', { hideEchoBack: false });
Object.assign(myGreyhound, templateObj)
myGreyhound.name = name
myGreyhound.icon = icon;
myGreyhound.online = true;
myGreyhound.lastOnline = Date.now();
let result = await newGreyhoundPost();
if (result === 'try again') {
console.log('GreyHound Name already Exist')
await newPlayer();
}
}
export const loadPlayer = async (tempGrey) => {
let noload = true;
while (noload === true) {
let name = readlineSync.question('What is the name of your greyhound: ', { hideEchoBack: false, limit: /[\S\s]+[\S]+/, limitMessage: 'can not be blank' });
let data = await loadGreyhoundGet(name);
if (data === 'not found') {
console.log("greyhound not found, try again")
} else {
Object.assign(myGreyhound, data)
noload = false;
}
}
}