My comments.
This commit is contained in:
parent
77cb3f4613
commit
a8c9d868be
6 changed files with 147 additions and 84 deletions
|
|
@ -11,6 +11,7 @@ import { checkPOI } from './poiscreens.js';
|
|||
import './poiscreens.js';
|
||||
import os from 'os';
|
||||
import { exit } from 'process';
|
||||
import { naturalEncounter } from './encounters.js';
|
||||
|
||||
global.isRawModeEnabled = false; // Track whether raw mode is enabled
|
||||
|
||||
|
|
@ -68,8 +69,7 @@ export function checkLose() { // Checks to see if any lose conditions have been
|
|||
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() {
|
||||
if (walkRate == 1) {
|
||||
if (path == 0) {
|
||||
|
|
@ -106,6 +106,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();
|
||||
export async function sleep(time) {
|
||||
if (osPlat === 'win32') {
|
||||
|
|
@ -123,6 +127,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) {
|
||||
let random = randomNumber(1,100);
|
||||
if (random >= 1 && random <= 33) { death1(deathCause); }
|
||||
|
|
@ -131,6 +136,7 @@ function death(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) {
|
||||
console.clear();
|
||||
sleep(2);
|
||||
|
|
@ -203,6 +209,7 @@ function timeDeath() { // The death screen for passing the time limit
|
|||
|
||||
var travelFrame = 0;
|
||||
|
||||
// Shows the 'frames' of the travel screen, and shows some player stats.
|
||||
export function travelScreen() {
|
||||
if (travelFrame < 0 || travelFrame > 3) {
|
||||
travelFrame = 0;
|
||||
|
|
@ -305,6 +312,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() {
|
||||
enableRawMode();
|
||||
if (paused) {
|
||||
|
|
@ -318,22 +328,23 @@ export async function walkPathMain() {
|
|||
checkLose();
|
||||
travelScreen();
|
||||
checkPOI();
|
||||
naturalEncounter(location);
|
||||
eatFood();
|
||||
day++
|
||||
await sleep(0.5);
|
||||
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.on('data', (key) => {
|
||||
if (key.toString() === ' ') {
|
||||
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() {
|
||||
if (!isRawModeEnabled) {
|
||||
process.stdin.setRawMode(true);
|
||||
|
|
@ -342,6 +353,7 @@ export function enableRawMode() {
|
|||
}
|
||||
}
|
||||
|
||||
// Turns raw mode off and sets the variable isRawModeEnabled to true
|
||||
export function disableRawMode() {
|
||||
if (isRawModeEnabled) {
|
||||
process.stdin.setRawMode(false);
|
||||
|
|
@ -350,6 +362,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;
|
||||
export function pauseScreen() {
|
||||
let pauseInput
|
||||
|
|
@ -365,6 +378,7 @@ export function pauseScreen() {
|
|||
console.log ("6) Change Speed/Food Rate");
|
||||
pauseInput = userInput("Enter: ");
|
||||
|
||||
// Input validation
|
||||
if (pauseInput != "1" && pauseInput != "2" && pauseInput != "3" && pauseInput != "4" && pauseInput != "5" && pauseInput != "6") {
|
||||
console.log("Invalid input. Please enter 1, 2, or 3.");
|
||||
} else {
|
||||
|
|
@ -372,6 +386,7 @@ export function pauseScreen() {
|
|||
}
|
||||
}
|
||||
switch(pauseInput) {
|
||||
// Shows all pois on the main path, and the chosen path if the player choses one.
|
||||
case "1":
|
||||
paused = false;
|
||||
break;
|
||||
|
|
@ -421,6 +436,7 @@ export function pauseScreen() {
|
|||
userInput("\n[Press Enter to return]");
|
||||
break;
|
||||
case "4":
|
||||
// Displays many player stat variables.
|
||||
console.clear();
|
||||
console.log("Player Stats");
|
||||
console.log("-------------");
|
||||
|
|
@ -437,9 +453,10 @@ export function pauseScreen() {
|
|||
userInput("\n[Press Enter to return]");
|
||||
break;
|
||||
case "5":
|
||||
scavenge();
|
||||
scavenge(); // Scavenge is curently not used in game
|
||||
break;
|
||||
case "6":
|
||||
// Gives the player a menu to change the walkRate and foodRate variables.
|
||||
console.clear();
|
||||
console.log("Current Walk Rate: "+walkRate);
|
||||
console.log("Current Food Rate: "+foodRate);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue