Merge branch 'main' of https://github.com/Raktbastr/Create-Task
This commit is contained in:
commit
a540fb6518
6 changed files with 147 additions and 84 deletions
|
|
@ -13,6 +13,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
|
||||
|
||||
|
|
@ -70,8 +71,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) {
|
||||
|
|
@ -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();
|
||||
export async function sleep(time) {
|
||||
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) {
|
||||
let random = randomNumber(1,100);
|
||||
if (random >= 1 && random <= 33) { death1(deathCause); }
|
||||
|
|
@ -133,6 +138,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);
|
||||
|
|
@ -205,6 +211,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;
|
||||
|
|
@ -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() {
|
||||
enableRawMode();
|
||||
if (paused) {
|
||||
|
|
@ -320,22 +330,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);
|
||||
|
|
@ -344,6 +355,7 @@ export function enableRawMode() {
|
|||
}
|
||||
}
|
||||
|
||||
// Turns raw mode off and sets the variable isRawModeEnabled to true
|
||||
export function disableRawMode() {
|
||||
if (isRawModeEnabled) {
|
||||
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;
|
||||
export function pauseScreen() {
|
||||
let pauseInput
|
||||
|
|
@ -367,6 +380,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 {
|
||||
|
|
@ -374,6 +388,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;
|
||||
|
|
@ -423,6 +438,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("-------------");
|
||||
|
|
@ -439,9 +455,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