From 3178ef479bde30a28b029bce084f75466c5b995d Mon Sep 17 00:00:00 2001 From: Raktbastr Date: Wed, 26 Feb 2025 09:51:09 -0600 Subject: [PATCH] Add game,js and modify calcLocation. Added variable exports to every file. --- files/deathscreens.js | 3 +- files/game.js | 90 +++++++++++++++++++++++++++++++++++++++++ files/huntinggame.js | 3 +- files/main.js | 6 ++- files/map.js | 3 +- files/poiscreens.js | 3 +- files/rivercrossing.js | 3 +- files/shops.js | 2 +- files/stoptravelmenu.js | 3 +- files/variables.js | 78 +---------------------------------- 10 files changed, 109 insertions(+), 85 deletions(-) create mode 100644 files/game.js diff --git a/files/deathscreens.js b/files/deathscreens.js index 15729f3..e53de46 100644 --- a/files/deathscreens.js +++ b/files/deathscreens.js @@ -1,4 +1,5 @@ // Deathscreens, they should be the fallout 1 screens +const variables = require("./variables.js"); module.exports = { deathScreen, @@ -6,7 +7,7 @@ module.exports = { }; function deathScreen() { - let random = Math.random(1,3); + let random = variables.randomNumber(1,3); if (random = 1) { death1(); } if (random = 2) { death2(); } if (random = 3) { death3(); } diff --git a/files/game.js b/files/game.js new file mode 100644 index 0000000..c793cf3 --- /dev/null +++ b/files/game.js @@ -0,0 +1,90 @@ +// Holds functions needed to play the game +const variables = require("./variables.js"); +const death = require("./deathscreens.js"); + +module.exports = { + eatFood, + calcSickPoints, + scavenge, + checkLose, + calcLocation, +} + +function eatfood() { + if (variables.food == 0) { + variables.health - 3*variables.travelSpeed + } else if (variables.isSick == true) { + variables.food = variables.food-((variables.travelSpeed*variables.foodAmt)+variables.sickSeverity); + } else { + variables.food = variables.food-(variables.travelSpeed*variables.foodAmt); + } + variables.health = variables.health+(5*variables.foodAmt); +} + +function calcSickPoints() { + if (variables.isSick = true) { + variables.sickPoints = variables.sickPoints+((variables.sickSeverity-(0.5*variables.foodAmt))+(0.5*(variables.travelSpeed+variables.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! + if (variables.daysSinceScav < 20 ) { + console.log("You must wait "+(20-variables.daysSinceScav)+" days until you can scavenge again") + } else { + let luck = variables.randomNumber(1,100); + if (luck <= 20) { + let group = 0; + let random = variables.randomNumber(variables.lootTables[group][0], variables.lootTables[group][3]); + inventory.push(random); + } else if (luck <= 40) { + let group = 1; + let random = variables.randomNumber(variables.lootTables[group][0], variables.lootTables[group][3]); + inventory.push(random); + } else if (luck <= 60) { + let group = 2; + let random = variables.randomNumber(variables.lootTables[group][0], variables.lootTables[group][3]); + inventory.push(random); + } else if (luck <= 80) { + let group = 3; + let random = variables.randomNumber(variables.lootTables[group][0], variables.lootTables[group][3]); + inventory.push(random); + } else if (luck <= 100) { + let group = 4; + let random = variables.randomNumber(variables.lootTables[group][0], variables.lootTables[group][3]); + inventory.push(random); + } + } +} + +function checkLose() { // Checks to see if any lose conditions have been met + if (variables.health <= 0 || variables.sickPoints >= 50) { + death.deathScreen(); + } + if (variables.day >= 365) { + death.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 (variables.travelSpeed == 1) { + if (variables.isSick == true) { + variables.location = variables.location+0.75; + } else { + variables.location++; + } + } + if (variables.travelSpeed == 2) { + if (variables.isSick == true) { + variables.location = variables.location+1.5; + } else { + variables.location = variables.location+2; + } + } + if (variables.travelSpeed == 3) { + if (variables.isSick == true) { + variables.location = variables.location+2.25; + } else { + variables.location = variables.location+3; + } + } +} diff --git a/files/huntinggame.js b/files/huntinggame.js index 446270c..e7bc4ac 100644 --- a/files/huntinggame.js +++ b/files/huntinggame.js @@ -1 +1,2 @@ -// Hunting Game, if we even decide to do it. \ No newline at end of file +// Hunting Game, if we even decide to do it. +const variables = require("./variables.js"); diff --git a/files/main.js b/files/main.js index ba4954b..8d43160 100644 --- a/files/main.js +++ b/files/main.js @@ -1,5 +1,6 @@ // Program is started from here, runs functions from other files. const variables = require("./variables.js"); +const game = require("./game.js"); const shops = require("./shops"); const readline = require('node:readline'); @@ -26,7 +27,8 @@ switch(mainMenuInput) { startGame(); break; case "2": - while (true) { console.log(variables.randomNumber(10,15)); } + console.log("Follow the link below for a game manual.") + console.log("[ENTER LINK HERE]") break; case "3": console.log("Quitting Game..."); @@ -48,5 +50,5 @@ function startGame() { // So far what I have is filler and testing, feel free to console.clear(); variables.prewarmoney = 500; - shops.trader(); + shops.ravenRock(); } \ No newline at end of file diff --git a/files/map.js b/files/map.js index 1a03627..4bbb499 100644 --- a/files/map.js +++ b/files/map.js @@ -1 +1,2 @@ -// Map Screen \ No newline at end of file +// Map Screen +const variables = require("./variables.js"); diff --git a/files/poiscreens.js b/files/poiscreens.js index 18515d5..5f3ccdf 100644 --- a/files/poiscreens.js +++ b/files/poiscreens.js @@ -1 +1,2 @@ -// Holds the screens for every POI including thier menus. \ No newline at end of file +// Holds the screens for every POI including thier menus. +const variables = require("./variables.js"); diff --git a/files/rivercrossing.js b/files/rivercrossing.js index 8c13059..974e563 100644 --- a/files/rivercrossing.js +++ b/files/rivercrossing.js @@ -1 +1,2 @@ -// River crossing screens and options. \ No newline at end of file +// River crossing screens and options. +const variables = require("./variables.js"); diff --git a/files/shops.js b/files/shops.js index 656b08f..fd7f663 100644 --- a/files/shops.js +++ b/files/shops.js @@ -1,5 +1,5 @@ const readline = require('readline-sync'); -const variables = require("./variables"); +const variables = require("./variables.js"); module.exports = { ravenRock, diff --git a/files/stoptravelmenu.js b/files/stoptravelmenu.js index 8412d50..665bf0a 100644 --- a/files/stoptravelmenu.js +++ b/files/stoptravelmenu.js @@ -1 +1,2 @@ -// Halt travel screen and menu. \ No newline at end of file +// Halt travel screen and menu. +const variables = require("./variables.js"); \ No newline at end of file diff --git a/files/variables.js b/files/variables.js index 48544c8..501a8b3 100644 --- a/files/variables.js +++ b/files/variables.js @@ -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);