-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.js
103 lines (84 loc) · 2.41 KB
/
command.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
/*******************************
EXPORT EACH COMMAND FROM HERE
Move the parser to a app.js?
*******************************/
var db = require('./db'),
_ = require('underscore');
/*var DEFAULT_USERS = 5;
var DEFAULT_COMPETITORS = [];
var DEFAULT_EMPLOYEES = 5;
var DEFAULT_FEATURES = [];
var DEFAULT_INVESTORS = 5;
var DEFAULT_MONEY = 500;
var DEFAULT_RPU = 1;*/
// create user through db API
var initGame = function(phoneNumber) {
db.initPlayer(phoneNumber, {
/*balance: DEFAULT_MONEY,
users: DEFAULT_USERS,
employees: DEFAULT_EMPLOYEES,
rpu: DEFAULT_RPU,
competitors: DEFAULT_COMPETITORS,
features: DEFAULT_FEATURES*/
});
return "New game created for " + phoneNumber + "with " +global.DATA[phoneNumber]+ ". See help for more information."
};
//remove user's game
var ipo = quit = function(phoneNumber) {
db.remove(phoneNumber);
return phoneNumber + " has been successfully removed from our database. \nP.S. Botched! You lose! - Lukas";
};
// User information
var help1 = function(phoneNumber) {
help = "Zuck is a text-based Facebook Tycoon game.\n Text \
'help' followed by any of these commands: 'new', 'buy', 'develop', \
'report', 'competition', 'ipo'.";
return help;
//return help manual
// if phone number is not listed
// Zuck is a text-based Facebook Tycoon game. Text "new" to begin, or
// "help" followed by any of these commands: "buy", "develop",
// "report", "competition", "ipo"
// if phone number is listed
//
};
var report = function(phoneNumber, options) {
var player = db.getPlayer(phoneNumber);
var res = "STATUS REPORT\n";
if(_.isEmpty(options)) {
console.log('empty');
}
_.each(player, function(value, key) {
res += key + ": " + player[key] + "\n";
});
return res;
};
//User interaction
var buy = function buy(phoneNumber, offer) {
var buyout = require('./purchase');
return buyout.negotiation(offer);
};
var devProject = function(phoneNumber, project) {
var develop = require('./developModule');
develop.applyModule(project);
};
var commands = {
"new": initGame,
quit: ipo,
ipo: ipo,
help1: help1,
report: report,
buy: buy,
develop: devProject
};
exports.parse = function(phoneNumber, text) {
var input = text.split(" ");
var commandFunc = commands[input.shift()];
if(_.isFunction(commandFunc)) {
var output = commandFunc(phoneNumber, input);
return output;
}
else {
return "Command is not recognized. Please try again or see help for more information."
}
};