Rewrite
This commit is contained in:
parent
8871c644fb
commit
e5fe71ce46
16 changed files with 573 additions and 638 deletions
122
files/functions.js
Normal file
122
files/functions.js
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
// Holds all functions used in multiple files
|
||||
import { createRequire } from 'module';
|
||||
const require = createRequire(import.meta.url);
|
||||
var readlineSync = require('readline-sync');
|
||||
|
||||
|
||||
import { food, foodRate, health, healthCap, locationA, locationB, name, radPoints, radSeverity, walkRate } from "./variables.js";
|
||||
|
||||
// Used for basic functions, not game specific
|
||||
export function userInput(question) { // Basic user input functions, takes in the question to be asked.
|
||||
let answer = readlineSync.question(question);
|
||||
return(answer);
|
||||
}
|
||||
|
||||
export function randomNumber(min, max) { // Takes in two parameters, min and max, and returns a random number between those boundries.
|
||||
while (true) {
|
||||
var randNum = Math.floor(Math.random() * (max+1));
|
||||
if (randNum >= min) { break; }
|
||||
}
|
||||
return randNum;
|
||||
}
|
||||
|
||||
|
||||
// Used for game
|
||||
export function healthCapCalc() { // Calculates HP cap given current radPoints
|
||||
healthCap = healthCap-radPoints;
|
||||
if (health > healthCap) { health = healthCap; }
|
||||
}
|
||||
|
||||
export function radPointsCalc() { // Calculates radPoints given walk/foodrate
|
||||
radPoints = radPoints + 0.5 * (radSeverity * 10 + 5 * (walkRate + foodRate))
|
||||
}
|
||||
|
||||
export function eatFood() { // Calculates food amount after a day of eating
|
||||
if (food == 0) {
|
||||
health = health - 3*walkRate
|
||||
} else {
|
||||
food = food - walkRate * foodRate
|
||||
}
|
||||
}
|
||||
|
||||
export function checkLose() { // Checks to see if any lose conditions have been met
|
||||
if (health <= 0 || radPoints >= 100) {
|
||||
death();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function calcLocation() {
|
||||
if (walkRate == 1) {
|
||||
if (path = 0) {
|
||||
location++;
|
||||
}
|
||||
if (path = 1) {
|
||||
locationA++;
|
||||
}
|
||||
if (path = 2) {
|
||||
locationB++;
|
||||
}
|
||||
}
|
||||
if (walkRate == 2) {
|
||||
if (path = 0) {
|
||||
location * 2;
|
||||
}
|
||||
if (path = 1) {
|
||||
locationA * 2;
|
||||
}
|
||||
if (path = 2) {
|
||||
locationB * 2;
|
||||
}
|
||||
}
|
||||
if (walkRate == 3) {
|
||||
if (path = 0) {
|
||||
location * 3;
|
||||
}
|
||||
if (path = 1) {
|
||||
locationA * 3;
|
||||
}
|
||||
if (path = 2) {
|
||||
locationB * 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function death() {
|
||||
let random = variables.randomNumber(1,3);
|
||||
if (random = 1) { deathScreen1(); }
|
||||
if (random = 2) { deathScreen2(); }
|
||||
if (random = 3) { deathScreen3(); }
|
||||
}
|
||||
|
||||
function death1() {
|
||||
console.log("")
|
||||
}
|
||||
|
||||
function death2() {
|
||||
|
||||
}
|
||||
|
||||
function death3() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function timeDeath() { // The death screen for passing the time limit
|
||||
console.clear;
|
||||
console.log("Your PIP-Boy starts ringing...\n\n")
|
||||
console.log("BEEP...BEEP...BEEP");
|
||||
console.log("INCOMING MESAGE FROM: Raven_Rock_Comms-1\n\n");
|
||||
console.log("|||||||")
|
||||
console.log("|| Enclave Intranet Messager");
|
||||
console.log("|||||||")
|
||||
console.log("|| Message From: automessager");
|
||||
console.log("|||||||\n\n")
|
||||
console.log("Dear, "+name+",\n\n");
|
||||
console.log("You have failed to faithfully execute the tasks laid before you in a timely manner.");
|
||||
console.log("In consequence you have been dishonorably discharged from the Enclave Armed Forces");
|
||||
console.log("Please return to the nearest active Enclave Military Installation immeditely\n\n");
|
||||
console.log("Signed, Enclave Internal Messager");
|
||||
console.clear;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue