-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface_play.js
More file actions
160 lines (128 loc) · 3.13 KB
/
interface_play.js
File metadata and controls
160 lines (128 loc) · 3.13 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
var exports = module.exports = {};
var core = require('./core');
var async = require('async')
var readlineSync = require('readline-sync');
exports.PlayGame = function() {
var answer = ''
core.getRandomWord(function(err, response){
answer = response.word;
async.series([
function(callback) {
core.getWordDef(response.word,function(err, res) {
if (err) {
callback(err, null);
return;
}
var ret = []
for (i in res){
ret.push(res[i].text);
}
callback(null, ret);
});
},
function(callback) {
core.getWordRelation(response.word,'synonym',function(err, res) {
if (err) {
callback(err, null);
return;
}
if (res[0]) {
var ret = []
var list = res[0].words
for(i in list){
ret.push(list[i]);
}
}
callback(null, ret);
});
},
function(callback) {
core.getWordRelation(response.word,'antonym',function(err, res) {
if (err) {
callback(err, null);
return;
}
if (res[0]) {
var ret = []
var list = res[0].words
for(i in list){
ret.push(list[i]);
}
}
callback(null, ret);
});
},
], function(err, result){
if (err) {
console.log('ERROR!!!');
return;
}
var antonym = result[2];
var synonym = result[1];
var defination = result[0];
var isOK = false;
var userGuess = false;
var hint = [];
var shuffle = answer.split('').sort(function(){return 0.5-Math.random()}).join('');
hint.push(shuffle);
if (typeof antonym!= 'undefined' && antonym.length > 0) {
for (i in antonym)
{
hint.push(antonym[i]);
}
}
if (typeof synonym!= 'undefined' && synonym.length > 0) {
for (i in synonym)
{
hint.push(synonym[i]);
}
}
if (typeof defination!= 'undefined' && defination.length > 0) {
for (i in defination)
{
hint.push(defination[i]);
}
}
var isHint = true;
console.log(answer);
console.log("lets play the game; we will provide the hints, you guess the words\n");
do {
if (typeof hint!= 'undefined' && hint.length > 0) {
if (isHint){
console.log(hint.pop());
}
userGuess = readlineSync.question('\nGuess the word\n');
if (userGuess.toLowerCase() == answer)
{
console.log('\nCongratulations you got it!!!\n');
return;
} else {
userGuess = readlineSync.question('\nSorry, guess is wrong\n enter "Try Again" or "Hint" or "quit"\n');
switch (userGuess.toLowerCase()) {
case 'try again':
userGuess = readlineSync.question('\nGuess the word\n');
if (userGuess.toLowerCase() == answer)
{
console.log('\nCongratulations you got it!!!\n');
return;
} else {
isHint = false;
}
break;
case 'hint':
isHint = true;
break;
case 'quit':
return;
default:
console.log("\nnot a valid option, we will give you a hint again\n");
}
}
} else {
console.log("\nWe ran out of hints\n");
isOK = true;
}
} while(!isOK)
});
});
};