This commit is contained in:
Caroline Foy 2025-04-29 14:01:20 -05:00
commit a540fb6518
6 changed files with 147 additions and 84 deletions

View file

@ -4,6 +4,8 @@ import './variables.js';
import { randomNumber, userInput } from './functions.js'; import { randomNumber, userInput } from './functions.js';
import { inventoryMenuM } from './inventory.js'; import { inventoryMenuM } from './inventory.js';
// InitCombat function (currently not used in final game)
// First sets the proper level of the enemy, then sets the stats of the enemy and runs combat() with it as a parameter.
function initCombat(enemy) { function initCombat(enemy) {
if (enemy.minLevel > level) { if (enemy.minLevel > level) {
var enemyLevelFinal = enemy.minLevel; var enemyLevelFinal = enemy.minLevel;
@ -16,17 +18,21 @@ function initCombat(enemy) {
if (enemy.armor.value > 85 && enemy.armor.unit == "dr") { if (enemy.armor.value > 85 && enemy.armor.unit == "dr") {
var enemyArmor = 85; var enemyArmor = 85;
} else { } else {
var enemyArmor = enemy.armor.value var enemyArmor = enemy.armor.value;
} }
var enemyStats = {level: enemyLevelFinal, health: enemy.health+enemyLevelFinal, weapon: enemy.weapon, armor: enemyArmor, armorUnit: enemy.armor.unit}; var enemyStats = {level: enemyLevelFinal, health: enemy.health+enemyLevelFinal, weapon: enemy.weapon, armor: enemyArmor, armorUnit: enemy.armor.unit};
var playerStats = {level: level, health: health, weapon: equippedWeapon, armor: equippedArmor, armorUnit: equippedArmor.unit, chem: "placeholder"}; var playerStats = {level: level, health: health, weapon: equippedWeapon, armor: equippedArmor, armorUnit: equippedArmor.unit, chem: "placeholder"};
combat(enemyStats);
} }
// Combat function (currently not used in final game)
// Gives a menu to attack the enemy, open inventoryM(), or view player stats. Menu will repeat until enemy.health is not > 0
function combat(enemy) { function combat(enemy) {
console.clear(); console.clear();
console.log("You enter combat with "+enemy.name+"..."); console.log("You enter combat with "+enemy.name+"...");
let combatInput; let combatInput;
while (enemy.health > 0) {
while (true) { while (true) {
console.log("What would you like to do?"); console.log("What would you like to do?");
console.log("-----------------------"); console.log("-----------------------");
@ -35,6 +41,7 @@ function combat(enemy) {
console.log("3) View Stats"); console.log("3) View Stats");
combatInput = userInput("Enter: "); combatInput = userInput("Enter: ");
// Input validation
if (combatInput != "1" && combatInput != "2" && combatInput != "3") { if (combatInput != "1" && combatInput != "2" && combatInput != "3") {
console.log("Invalid input. Please enter 1, 2, or 3."); console.log("Invalid input. Please enter 1, 2, or 3.");
} else { } else {
@ -100,8 +107,12 @@ function combat(enemy) {
break; break;
} }
} }
}
// damageCalc() function (currently not used in final game)
// If the attacker parameter = the player it runs the respective menus, checking for damage dealt and returns it.
// Vice versa if attacker = enemy
// If crit = true 3 extra damage is applied regardless of armor calculations.
function damageCalc(attacker, crit) { function damageCalc(attacker, crit) {
if (attacker = player) { if (attacker = player) {
if (playerStats.chem == "psycho") { if (playerStats.chem == "psycho") {

View file

@ -13,6 +13,7 @@ import { checkPOI } from './poiscreens.js';
import './poiscreens.js'; import './poiscreens.js';
import os from 'os'; import os from 'os';
import { exit } from 'process'; import { exit } from 'process';
import { naturalEncounter } from './encounters.js';
global.isRawModeEnabled = false; // Track whether raw mode is enabled global.isRawModeEnabled = false; // Track whether raw mode is enabled
@ -70,8 +71,7 @@ export function checkLose() { // Checks to see if any lose conditions have been
death("Test Death"); death("Test Death");
} }
} }
// Checks to see what path the player is on and adds the respective amount to the respective location variable
export function calcLocation() { export function calcLocation() {
if (walkRate == 1) { if (walkRate == 1) {
if (path == 0) { if (path == 0) {
@ -108,6 +108,10 @@ export function calcLocation() {
} }
} }
// sleep() function
// First detects what os the user is on and assigns it to osPlat
// if osPlat == 'win32' the program runs the shell command 'sleep' with powershell and the desired time parameter
// if it is not equal to 'win32' the program just runs 'sleep' with the desired time parameter
var osPlat = os.platform(); var osPlat = os.platform();
export async function sleep(time) { export async function sleep(time) {
if (osPlat === 'win32') { if (osPlat === 'win32') {
@ -125,6 +129,7 @@ export async function sleep(time) {
} }
} }
// Calculates a random number to see which death screen you recieve if called and imputs the death cause as a parameter.
function death(deathCause) { function death(deathCause) {
let random = randomNumber(1,100); let random = randomNumber(1,100);
if (random >= 1 && random <= 33) { death1(deathCause); } if (random >= 1 && random <= 33) { death1(deathCause); }
@ -133,6 +138,7 @@ function death(deathCause) {
if (random == 100) { death4(deathCause); } if (random == 100) { death4(deathCause); }
} }
// death1, death2, and death3 all display a death message, similar to those in Fallout 1, along with the cause given as a parameter
function death1(dc) { function death1(dc) {
console.clear(); console.clear();
sleep(2); sleep(2);
@ -205,6 +211,7 @@ function timeDeath() { // The death screen for passing the time limit
var travelFrame = 0; var travelFrame = 0;
// Shows the 'frames' of the travel screen, and shows some player stats.
export function travelScreen() { export function travelScreen() {
if (travelFrame < 0 || travelFrame > 3) { if (travelFrame < 0 || travelFrame > 3) {
travelFrame = 0; travelFrame = 0;
@ -307,6 +314,9 @@ export function travelScreen() {
} }
} }
// This function is run everytime the player 'moves' in the world. It first enables raw mode to detect for the pause button
// If paused it displays pauseScreen();
// If not it runs calcLocation(), radPointsCalc(), healthCapCalc(), checkLose(), travelScreen(), checkPOI(), naturalEncounter(), eatFood(), adds to the day counter, and then re runs the function.
export async function walkPathMain() { export async function walkPathMain() {
enableRawMode(); enableRawMode();
if (paused) { if (paused) {
@ -320,22 +330,23 @@ export async function walkPathMain() {
checkLose(); checkLose();
travelScreen(); travelScreen();
checkPOI(); checkPOI();
naturalEncounter(location);
eatFood(); eatFood();
day++ day++
await sleep(0.5); await sleep(0.5);
walkPathMain(); walkPathMain();
} }
// This checks to see if the spacebar is pressed while raw menu is enabled.
// If so it sets paused to true.
process.stdin.resume(); process.stdin.resume();
process.stdin.on('data', (key) => { process.stdin.on('data', (key) => {
if (key.toString() === ' ') { if (key.toString() === ' ') {
paused = true; // Pause the game paused = true; // Pause the game
} else if (key.toString() === '\u0003') { // Handle Ctrl+C (ASCII code for Ctrl+C)
console.log("\nExiting game...");
process.exit(); // Exit the program
} }
}); });
// Turns raw mode on, runs the above function when called and sets the variable isRawModeEnabled to true
export function enableRawMode() { export function enableRawMode() {
if (!isRawModeEnabled) { if (!isRawModeEnabled) {
process.stdin.setRawMode(true); process.stdin.setRawMode(true);
@ -344,6 +355,7 @@ export function enableRawMode() {
} }
} }
// Turns raw mode off and sets the variable isRawModeEnabled to true
export function disableRawMode() { export function disableRawMode() {
if (isRawModeEnabled) { if (isRawModeEnabled) {
process.stdin.setRawMode(false); process.stdin.setRawMode(false);
@ -352,6 +364,7 @@ export function disableRawMode() {
} }
} }
// Gives player a menu to resume the game, view inventory, distances, stats, scavenge, and change the speed/food rate
var paused = false; var paused = false;
export function pauseScreen() { export function pauseScreen() {
let pauseInput let pauseInput
@ -367,6 +380,7 @@ export function pauseScreen() {
console.log ("6) Change Speed/Food Rate"); console.log ("6) Change Speed/Food Rate");
pauseInput = userInput("Enter: "); pauseInput = userInput("Enter: ");
// Input validation
if (pauseInput != "1" && pauseInput != "2" && pauseInput != "3" && pauseInput != "4" && pauseInput != "5" && pauseInput != "6") { if (pauseInput != "1" && pauseInput != "2" && pauseInput != "3" && pauseInput != "4" && pauseInput != "5" && pauseInput != "6") {
console.log("Invalid input. Please enter 1, 2, or 3."); console.log("Invalid input. Please enter 1, 2, or 3.");
} else { } else {
@ -374,6 +388,7 @@ export function pauseScreen() {
} }
} }
switch(pauseInput) { switch(pauseInput) {
// Shows all pois on the main path, and the chosen path if the player choses one.
case "1": case "1":
paused = false; paused = false;
break; break;
@ -423,6 +438,7 @@ export function pauseScreen() {
userInput("\n[Press Enter to return]"); userInput("\n[Press Enter to return]");
break; break;
case "4": case "4":
// Displays many player stat variables.
console.clear(); console.clear();
console.log("Player Stats"); console.log("Player Stats");
console.log("-------------"); console.log("-------------");
@ -439,9 +455,10 @@ export function pauseScreen() {
userInput("\n[Press Enter to return]"); userInput("\n[Press Enter to return]");
break; break;
case "5": case "5":
scavenge(); scavenge(); // Scavenge is curently not used in game
break; break;
case "6": case "6":
// Gives the player a menu to change the walkRate and foodRate variables.
console.clear(); console.clear();
console.log("Current Walk Rate: "+walkRate); console.log("Current Walk Rate: "+walkRate);
console.log("Current Food Rate: "+foodRate); console.log("Current Food Rate: "+foodRate);

View file

@ -3,7 +3,12 @@
import { userInput } from "./functions.js"; import { userInput } from "./functions.js";
import "./variables.js"; import "./variables.js";
//Builds the main menu inventory // inventoryMenuM()
// When the user asks to see thier inventory, this is called.
// Shows a list of options from which the player can choose
// If they choose to view, viewInventory() is called
// If they want to equip an armor or weapon, they are shown a list of all items with the specified type (weapon or armor)
// from there they can select the item and it replaces the item currently in the respective variable.
export function inventoryMenuM(){ export function inventoryMenuM(){
console.clear(); console.clear();
console.log("INVENTORY"); console.log("INVENTORY");
@ -65,7 +70,8 @@ export function inventoryMenuM(){
} }
} }
//Builds the supply inventory // viewInventory()
// Lists all items in the inventory array.
function viewInventory(){ function viewInventory(){
console.clear(); console.clear();
console.log("Inventory"); console.log("Inventory");

View file

@ -1,10 +1,15 @@
//Created by student A and B collaobratively //Created by student A and B collaobratively
// Program is started from here, runs functions from other files. // Program is started from here, runs functions from other files.
// In order to use variables and functions from other files we must import them as shown below
// To import functions we use the syntax below
import { userInput, sleep, disableRawMode, walkPathMain, randomNumber } from './functions.js'; import { userInput, sleep, disableRawMode, walkPathMain, randomNumber } from './functions.js';
import { forcedEncounter, naturalEncounter } from './encounters.js';
import { ravenRockStore } from './shops.js'; import { ravenRockStore } from './shops.js';
// To import variables from a file you must mark them as global (done in file) and import the file they are in like shown below.
import './variables.js';
disableRawMode(); disableRawMode();
console.clear(); console.clear();
@ -16,6 +21,7 @@ console.log(" / / ) / / / ) / / / o / / ) / )
console.log("_/________(___(_/___/___(___/_(___(__(_ __o_____/____/_(___/_/___/_(___ _(__)_(___/_/_/__/_(___ _____/_____|__(___/_(___(_(___/___\n\n"); console.log("_/________(___(_/___/___(___/_(___(__(_ __o_____/____/_(___/_/___/_(___ _(__)_(___/_/_/__/_(___ _____/_____|__(___/_(___(_(___/___\n\n");
await sleep(1); await sleep(1);
// Collects player input for menus
var mainMenuInput; var mainMenuInput;
while (true) { while (true) {
console.log("What would you like to do?"); console.log("What would you like to do?");
@ -26,6 +32,7 @@ while (true) {
console.log("4) Credits\n"); console.log("4) Credits\n");
mainMenuInput = userInput("Enter: "); mainMenuInput = userInput("Enter: ");
// Input validation
if (mainMenuInput != "1" && mainMenuInput != "2" && mainMenuInput != "3" && mainMenuInput != "4") { if (mainMenuInput != "1" && mainMenuInput != "2" && mainMenuInput != "3" && mainMenuInput != "4") {
console.log("Invalid input. Please enter 1, 2, or 3."); console.log("Invalid input. Please enter 1, 2, or 3.");
} else { } else {
@ -51,7 +58,11 @@ switch(mainMenuInput) {
break; break;
} }
function startGame() { // So far what I have is filler and testing, feel free to change.
// startGame() function
// Walks player through character creation, story, and sets starting stats. Then opens up ravenRockStore() before
// runing the walkPath() function loop.
function startGame() {
console.clear(); console.clear();
name = userInput("What is your name? "); name = userInput("What is your name? ");
console.log(name+" Is now your name...") console.log(name+" Is now your name...")

View file

@ -133,6 +133,17 @@ var lostHillsInv = [
{item: equipmentList[12], name: equipmentList[12].name, price: equipmentList[12].cost, amount: 10}, {item: equipmentList[12], name: equipmentList[12].name, price: equipmentList[12].cost, amount: 10},
]; ];
// Store functions
// Each store gets its own inventory and function, and work exactly the same for the most part.
// It opens by giving a welcome screen and listing the items in stock, player is given choice to leave or buy items.
// If they chose to buy, player enters the item number, amount they want, and it is then pushed to thier inventory array
// If the item is food, the item is added to the food variable, not the inventory.
// Exceptions to how this works:
// ravenRockStore() and eurekaStore() both use Pre-War Money, multiplying the
// prices by 10 and using the players PWM to purchase the item, not caps.
export function ravenRockStore() { export function ravenRockStore() {
while (true) { while (true) {
console.clear(); console.clear();
@ -153,19 +164,23 @@ export function ravenRockStore() {
console.log("What would you like to buy?"); console.log("What would you like to buy?");
var itemNum = userInput("Enter item number: "); var itemNum = userInput("Enter item number: ");
var itemAmt = userInput("Enter amount: "); var itemAmt = userInput("Enter amount: ");
// Making sure the item has enough in stock
if (itemAmt > rrInv[itemNum].amount) { if (itemAmt > rrInv[itemNum].amount) {
console.log("Not enough stock."); console.log("Not enough stock.");
userInput("[Enter]"); userInput("[Enter]");
break; break;
// Making sure the items requested are not too expensive
} else if (itemAmt * rrInv[itemNum].price*10 > preWarMoney) { } else if (itemAmt * rrInv[itemNum].price*10 > preWarMoney) {
console.log("Not enough money."); console.log("Not enough money.");
userInput("[Enter]"); userInput("[Enter]");
break; break;
// If the choice is vaild, add the item to inventory and remove stock/money
} else { } else {
preWarMoney -= itemAmt * rrInv[itemNum].price*10; preWarMoney -= itemAmt * rrInv[itemNum].price*10;
rrInv[itemNum].amount -= itemAmt; rrInv[itemNum].amount -= itemAmt;
console.log("You bought " + itemAmt + " " + rrInv[itemNum].name + "(s)."); console.log("You bought " + itemAmt + " " + rrInv[itemNum].name + "(s).");
console.log("You have " + preWarMoney + " pre-war money left."); console.log("You have " + preWarMoney + " pre-war money left.");
// Check if the item is food, if so add to food variable
if (rrInv[itemNum].name == "Food") { if (rrInv[itemNum].name == "Food") {
food =+ itemAmt; food =+ itemAmt;
} else { } else {

View file

@ -2,7 +2,9 @@
// Now holds only variables // Now holds only variables
// Items // To allow a variable to be read/wrote from across files you must begin them with "global.variablename"
// Items and related stats
global.supplyList = [ // Supplies: chems, aid global.supplyList = [ // Supplies: chems, aid
{name: "Food", description: "Misc foods", cost: 1, weight: 0}, {name: "Food", description: "Misc foods", cost: 1, weight: 0},
{name: "Stimpak", description: "A Stimpak syringe, heals 25 HP", cost: 5, weight: 0.5}, {name: "Stimpak", description: "A Stimpak syringe, heals 25 HP", cost: 5, weight: 0.5},
@ -41,6 +43,7 @@ global.equipmentList = [ // Equipment: weapons, armor, tools
{name: "Fists (Unarmed)", description: "Unarmed combat, does 5 bash damage", type: "weapon", value: "5", unit: "bash", cost: 5, weight: 1}, {name: "Fists (Unarmed)", description: "Unarmed combat, does 5 bash damage", type: "weapon", value: "5", unit: "bash", cost: 5, weight: 1},
]; ];
// List of possible achievements you can gain (Currently not used in game)
global.achievements = [ global.achievements = [
// POI/Faction Destroy // POI/Faction Destroy
{name: "Dishonorable Discharge", description: "Deactivate MODUS at the Whitespring", unlocked: false}, {name: "Dishonorable Discharge", description: "Deactivate MODUS at the Whitespring", unlocked: false},
@ -98,8 +101,8 @@ global.inventory = [ // Inventory of player, holds all items
equipmentList[27], equipmentList[27],
equipmentList[25], equipmentList[25],
] ]
global.equippedWeapon = equipmentList[27]; global.equippedWeapon = equipmentList[27]; // Players currently equipped weapon
global.equippedArmor = equipmentList[25]; global.equippedArmor = equipmentList[25]; // PLayers currently equipped armor
// Game Mechanics // Game Mechanics
global.walkRate = 0; // Units the player walks per day, affects foodRateCalc and radPointsCalc global.walkRate = 0; // Units the player walks per day, affects foodRateCalc and radPointsCalc