Add game,js and modify calcLocation. Added variable exports to every file.

This commit is contained in:
Raktbastr 2025-02-26 09:51:09 -06:00
parent 25efc4f9f9
commit 3178ef479b
10 changed files with 109 additions and 85 deletions

View file

@ -1,4 +1,4 @@
// Holds the global variables, functions, and math operations such as the day counter and food eaten..
// Holds the global variables and useful functions such as userInput
const readline = require('readline-sync');
module.exports = { // Lets variables and functions be used in other files
@ -17,12 +17,7 @@ module.exports = { // Lets variables and functions be used in other files
name,
prewarmoney,
caps,
eatfood,
calcLocation,
calcSickPoints,
scavenge,
sleep,
checkLose,
userInput,
randomNumber
};
@ -59,81 +54,12 @@ var inventory = []; // Max of 5 items
var lootTables = [[],[],[],[],[]] // Only small things like food and ammo, 5 Loot tables per scavenge score, 3 items in each, first is best
function eatfood() {
if (food == 0) { health - 20 }
if (isSick == true) { food = food-((travelSpeed*foodAmt)+sickSeverity); }
else { food = food-(travelSpeed*foodAmt); }
health = health+(5*foodAmt);
}
function calcSickPoints() {
if (isSick = true) {
sickPoints = sickPoints+((sickSeverity-(0.5*foodAmt))+(0.5*(travelSpeed+radSeverity)));
}
}
function scavenge() { // Rolls a random number between 1 and 100 to see which loot table you get, then picks a random item from it. ADD COOLDOWN!
let luck = Math.random(1,100);
if (luck <= 20) {
let group = 0;
let random = Math.random(lootTables[group][0], lootTables[group][3]);
inventory.push(random);
} else if (luck <= 40) {
let group = 1;
let random = Math.random(lootTables[group][0], lootTables[group][3]);
inventory.push(random);
} else if (luck <= 60) {
let group = 2;
let random = Math.random(lootTables[group][0], lootTables[group][3]);
inventory.push(random);
} else if (luck <= 80) {
let group = 3;
let random = Math.random(lootTables[group][0], lootTables[group][3]);
inventory.push(random);
} else if (luck <= 100) {
let group = 4;
let random = Math.random(lootTables[group][0], lootTables[group][3]);
inventory.push(random);
}
}
var daysSinceScav = 0; // Days since your last scavenge, you must wait 15 days before scavenging again.
function sleep(time) { // Waits the inputed amt of miliseconds before proceeding
setTimeout(() => {}, time);
}
function checkLose() { // Checks to see if any lose conditions have been met
if (health <= 0 || sickPoints >= 50) {
deathScreen();
}
if (day >= 365) {
timeDeath();
}
}
function calcLocation() { // Calculates your location in the world using location points, You move your move speed per day, but 3/4 of it if you are sick
if (travelSpeed == 1) {
if (isSick == true) {
location = location+0.75;
} else {
location++;
}
}
if (travelSpeed == 2) {
if (isSick == true) {
location = location+1.5;
} else {
location = location+2;
}
}
if (travelSpeed == 3) {
if (isSick == true) {
location = location+2.25;
} else {
location = location+3;
}
}
}
function userInput(question) { // Basic user input functions, takes in the question to be asked.
let answer = readline.question(question);
return(answer);