var ThereWillBeBlood = (function() {
var sanity = 100,
friends = ['H.W. Plainview'],
money = 5000,
time;
function numFriends() {
var amt = 0,
j;
for (j in friends) {
if (typeof friends[j] != 'undefined') {
amt++;
}
}
return amt;
}
function addFriend(index, name) {
friends[index] = name;
console.log('Added Friend: ' + name);
}
function abandon(index, notes) {
if (typeof notes == 'undefined') {
notes = '';
}
console.log('Abandoned ' + friends[index], notes);
delete friends[index];
}
function kill(index) {
console.log('Killed ' + friends[index]);
delete friends[index];
}
function im_finished() {
console.groupEnd();
console.log('Fin');
return;
}
function init() {
for (time = 0; time <= sanity; time++) {
var currentSanity = sanity - time,
currentMoney = money + ((time) * (sanity - currentSanity));
if (numFriends() === 0) {
currentMoney *= time;
}
if (time % 10 === 0) {
console.log(currentSanity);
console.group('Sanity: %s%', currentSanity);
console.log('Money: $%s', currentMoney);
console.log('Friends: ', friends);
switch (currentSanity) {
case 80:
addFriend(1, 'Henry Plainview');
break;
case 60:
abandon(0);
break;
case 50:
kill(1);
break;
case 40:
addFriend(0, 'Henry Plainview');
break;
case 20:
abandon(0, '(Again)');
break;
case 0:
im_finished();
break;
}
console.groupEnd();
}
}
}
return {
drill: init
};
})();
ThereWillBeBlood.drill();
var sanity = 100,
friends = ['H.W. Plainview'],
money = 5000,
time;
function numFriends() {
var amt = 0,
j;
for (j in friends) {
if (typeof friends[j] != 'undefined') {
amt++;
}
}
return amt;
}
function addFriend(index, name) {
friends[index] = name;
console.log('Added Friend: ' + name);
}
function abandon(index, notes) {
if (typeof notes == 'undefined') {
notes = '';
}
console.log('Abandoned ' + friends[index], notes);
delete friends[index];
}
function kill(index) {
console.log('Killed ' + friends[index]);
delete friends[index];
}
function im_finished() {
console.groupEnd();
console.log('Fin');
return;
}
function init() {
for (time = 0; time <= sanity; time++) {
var currentSanity = sanity - time,
currentMoney = money + ((time) * (sanity - currentSanity));
if (numFriends() === 0) {
currentMoney *= time;
}
if (time % 10 === 0) {
console.log(currentSanity);
console.group('Sanity: %s%', currentSanity);
console.log('Money: $%s', currentMoney);
console.log('Friends: ', friends);
switch (currentSanity) {
case 80:
addFriend(1, 'Henry Plainview');
break;
case 60:
abandon(0);
break;
case 50:
kill(1);
break;
case 40:
addFriend(0, 'Henry Plainview');
break;
case 20:
abandon(0, '(Again)');
break;
case 0:
im_finished();
break;
}
console.groupEnd();
}
}
}
return {
drill: init
};
})();
ThereWillBeBlood.drill();