-
Notifications
You must be signed in to change notification settings - Fork 3
/
begin_round2.js
239 lines (228 loc) · 9.17 KB
/
begin_round2.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
var beginRoundWith2 = function() {
var rollDice = function() {
return Math.floor(Math.random()*6);
};
var buyWorkers = function(ai) {
if (Math.floor((ai.money - 5)/21) > 0) {
var toBuy = Math.floor((ai.money - 10)/20);
var cost = toBuy * 20;
ai.workers += toBuy;
ai.money -= cost;
}
confirm(ai.name + " bought " + ai.workers + " workers");
};
var youBuyWorkers = function() {
var ask = function() {
var max = Math.floor(me.money/20);
var askP = prompt("How many workers would you like to buy? You have " + me.money + " dollars. The most you can buy is " + max, max)*1;
if (me.money - (askP * 20) < 0) {
confirm("Oops! Sorry, it looks like you don't have enough money.");
ask();
}else if(isNaN(askP)) {
alert("Sorry! That is not a number!");
ask();
} else {
var cost = askP*20;
me.workers += askP;
me.money -= cost;
confirm("You bought " + me.workers + " workers");
}
};
ask();
};
var otherPersonBuyWorkers = function() {
var ask = function() {
var max = Math.floor(other.money/20);
var askP = prompt("How many workers would you like to buy? You have " + other.money + " dollars. The most you can buy is " + max, max)*1;
if (other.money - (askP * 20) < 0) {
confirm("Oops! Sorry, it looks like you don't have enough money.");
ask();
}else if(isNaN(askP)) {
alert("Sorry! That is not a number!");
ask();
} else {
var cost = askP*20;
other.workers += askP;
other.money -= cost;
confirm("Person 2 bought " + other.workers + " workers");
}
};
ask();
};
var personPersonBuyWorkers = function() {
var ask = function() {
var max = Math.floor(person.money/20);
var askP = prompt("How many workers would you like to buy? You have " + person.money + " dollars. The most you can buy is " + max, max)*1;
if (person.money - (askP * 20) < 0) {
confirm("Oops! Sorry, it looks like you don't have enough money.");
ask();
}else if(isNaN(askP)) {
alert("Sorry! That is not a number!");
ask();
} else {
var cost = askP*20;
person.workers += askP;
person.money -= cost;
confirm("Person 3 bought " + person.workers + " workers");
}
};
ask();
};
var newPersonPersonBuyWorkers = function() {
var ask = function() {
var max = Math.floor(newPerson.money/20);
var askP = prompt("How many workers would you like to buy? You have " + newPerson.money + " dollars. The most you can buy is " + max, max)*1;
if (newPerson.money - (askP * 20) < 0) {
confirm("Oops! Sorry, it looks like you don't have enough money.");
ask();
}else if(isNaN(askP)) {
alert("Sorry! That is not a number!");
ask();
} else {
var cost = askP*20;
newPerson.workers += askP;
newPerson.money -= cost;
confirm("Person 4 bought " + newPerson.workers + " workers");
}
};
ask();
};
//newPersonPersonBuyWorkers();
personPersonBuyWorkers();
otherPersonBuyWorkers();
youBuyWorkers();
//buyWorkers(ai1);
buyWorkers(ai2);
buyWorkers(ai3);
var getMoneyW = function(p) {
pValue = p.workers * 5 + 5;
money = rollDice() * pValue;
p.money += money;
};
var getMoneyM = function(pl) {
getMoneyW(pl);
getMoneyW(pl);
getMoneyW(pl);
getMoneyW(pl);
getMoneyW(pl);
//getMoneyW(pl);
//getMoneyW(pl);
if (pl === me) {
confirm(pl.name + " have " + pl.money + " dollars");
} else {
confirm(pl.name + " has " + pl.money + " dollars");
}
pl.workers = 0;
};
//getMoneyM(newPerson);
getMoneyM(other);
getMoneyM(person);
getMoneyM(me);
//getMoneyM(ai1);
getMoneyM(ai2);
getMoneyM(ai3);
var taxPayer = function() {
round += 1;
var roundsLeftUntilTaxDay = 6 - round;
alert("The round is round " + round + " which means you have " + roundsLeftUntilTaxDay + " days until taxday.");
if(round === 6) {
alert("Tax day: Everybody loses 10% of their money.");
//newPerson.money *= 0.90;
person.money *= 0.90;
other.money *= 0.90;
me.money *= 0.90;
//ai1.money *= 0.90;
ai2.money *= 0.90;
ai3.money *= 0.90;
round = 0;
}
};
taxPayer();
var checkWinner = function() {
var list = [];
var cMoney = function(pl) {
if (pl.money > 500000) {
list.push(pl);
}
};
//cMoney(newPerson);
cMoney(person);
cMoney(me);
//cMoney(ai1);
cMoney(ai2);
cMoney(ai3);
cMoney(other);
if (list.length === 1) {
winner1 = list[0];
beginRound = function() {
confirm(winner1.name + " won with " + winner1.money + "!");
};
beginRound();
} else if (list.length === 2) {
winner1 = list[0];
winner2 = list[1];
beginRound = function() {
confirm(winner1.name + " and " + winner2.name + " both won with over 500,000!");
};
beginRound();
} else if (list.length === 3) {
winner1 = list[0];
winner2 = list[1];
winner3 = list[2];
winner4 = list[3];
beginRound = function() {
confirm(winner1.name + ", " + winner2.name + ", and " + winner3.name + " won with over 500,000!");
};
beginRound();
/*}else if(list.length === 4) {
winner1 = list[0];
winner2 = list[1];
winner3 = list[2];
winner4 = list[3];
winner5 = list[4];
beginRound = function() {
confirm(winner1.name + ", " + winner2.name + ", " + winner3.name + ", and " + winner4.name +" won with over 500,000!");
};
beginRound();
}else if(list.length === 5) {
winner1 = list[0];
winner2 = list[1];
winner3 = list[2];
winner4 = list[3];
winner5 = list[4];
winner6 = list[5];
beginRound = function() {
confirm(winner1.name + ", " + winner2.name + ", " + winner3.name + ", " + winner4.name + ", and " + winner5.name + " won with over 500,000!");
};
beginRound();
}else if(list.length === 6) {
winner1 = list[0];
winner2 = list[1];
winner3 = list[2];
winner4 = list[3];
winner5 = list[4];
winner6 = list[5];
beginRound = function() {
confirm(winner1.name + ", " + winner2.name + ", " + winner3.name + ", " + winner4.name + ", " + winner5.name + ", and " + winner6.name + " won with over 500,000!");
};
}else if(list.length === 7) {
winner1 = list[0];
winner2 = list[1];
winner3 = list[2];
winner4 = list[3];
winner5 = list[4];
winner6 = list[5];
winner7 = list[6];
beginRound = function() {
confirm(winner1.name + ", " + winner2.name + ", " + winner3.name + ", " + winner4.name + ", " + winner5.name + ", " + winner6.name + ", and " + winner7.name + " won with over 500,000!");
};
beginRound();
*/} else if (list.length === 4) {
beginRound = function() {
confirm("Everybody won with over 500,000!");
};
beginRound();
}
};
checkWinner();
};