-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoft.js
More file actions
101 lines (86 loc) · 3.29 KB
/
soft.js
File metadata and controls
101 lines (86 loc) · 3.29 KB
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
const game = require('./game.js')
const fs = require('fs')
const commander = require('commander')
class moreOrLess extends game
{
constructor(chooser, commander, inquirer, fs, async)
{
super(chooser, commander, inquirer, fs, async)
}
game()
{
const nbToFind = Math.round(Math.random() * (1 + 100) - 1)
var count = 0
let i = 0
let nom = "nom"+i
console.log('Welcome to the game of more or less, if you need help type -h.')
console.log('Choose a number between 1 and 100 : ')
this.commander
.version('1.0.0')
.option('-r, --rules', 'You only just need to find a number between 1 and 100. Just type a number and enter.')
.parse(process.argv)
if (this.commander.r)
{
console.log('You only just need to find a number between 1 and 100. Just type a number and enter.\n-s, --save create a file log, do it at the end of the game.')
}
else
{
const funct = (name) =>
{
const a =
[{
type:'input',
message:'Enter a number',
name: name
}]
return this.inquirer.prompt(a)
}
const quizz = async () =>
{
let answers = await funct(nom)
count++
if (answers[nom] > nbToFind)
{
console.log('Too big, enter a smaller number than : ' + answers[nom])
quizz()
}
else if (answers[nom] < nbToFind)
{
console.log('Too small, enter a larger number than : ' + answers[nom])
quizz()
}
else if (answers[nom] == nbToFind)
{
if (count == 1)
{
console.log('Congratulations you find it in ' + count + ' shot. A new file is created.')
}
else
{
console.log('Congratulations you find it in ' + count + ' shots. A new file is created.')
}
function save()
{
let path = "save_mol.txt"
let message = "This is the local save for the more or less game.\nnumber to find : " + nbToFind + "\ncount : " + count
let eMessage = "An error was occured (how did you get this message ???)."
fs.writeFile(path, message), (err) =>
{
if (err)
{
console.log(eMessage)
}
else
{
console.log('The file is save, you can now send it to the db.')
}
}
}
save()
}
}
quizz()
}
}
}
module.exports = moreOrLess