diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/justBreathe.js b/justBreathe.js new file mode 100644 index 0000000..b5edebb --- /dev/null +++ b/justBreathe.js @@ -0,0 +1,268 @@ +const readline = require('readline-sync'); +const chalk = require('chalk'); + +const startGame = () => { +if(wantToPlay = readline.keyInYN(chalk.red.bold(`Hello ${nameInput}, do you want to play a game?\n`))){ + gameIntro(); +}else{ + leaveGame(); +} +}; + +const leaveGame = (goodbyeMessage) => { +goodbyeMessage = `You were a bad candidate anyway. Goodbye!` + console.log(chalk.blue.bold(goodbyeMessage)); + process.exit(); +}; + + +let nameInput = readline.question(chalk.red.bold("What is your name?\n")); + +function gameIntro(){ + console.log(chalk.magenta.bold(`Welcome to my experiment ${nameInput}!.....I mean...game.\n`)); +}; + +function howOld (){ +let ageInput = readline.question(chalk.red.bold('How old are you?\n')); +if(ageInput < 18){ + console.log(chalk.magenta.bold(`Oh no, you're just a baby!\nCome back when you're 18. See ya later ${nameInput}!`)); + leaveGame() +}else if(ageInput >= 18){ + console.log(chalk.magenta.bold("Yes! " + ageInput + "," + " you're old...the perfect candidate for my experi- .....game. \n")); + howToPlay(); +}else{ + console.log(chalk.green.italic(`That was not a valid input ${nameInput}\n`)); + console.log(chalk.green.italic('I don\'t usually like repeating myself, but ahemmm.')); + howOld(); +} +}; + +function howToPlay(){ +console.log(chalk.red.bold('Here is how you play:')); + let movement = ["'forward'", "'right'", "'left'", "'up'"] + for(let i = 0; i < movement.length; i++){ + console.log(chalk.yellow.bold(`Type ${movement[i]} to move in that direction.\n`)); + } + console.log(chalk.yellow.bold("Type 'grab' to grab an item.\n")); + console.log(chalk.yellow.bold("Type 'swing' to swing your arm.")); +}; + +const story = () => { +if(readline.keyInYN(chalk.red.bold('Are you ready? \n'))){ + console.log(chalk.magenta.bold('You woke up alone in a cold, dimly lit room.\nAs you move to look around, you feel pain in your body')); + console.log(chalk.magenta.bold('You hear beeping noises all around you...you look down at your body and notice two wires attached to it.\n')); + console.log(chalk.magenta.bold('One wire for each of your beautiful lungs.\n')); + console.log(chalk.magenta.bold('Your goal here is to get your organs back so that you can go home to your family.')); + console.log(chalk.magenta.bold('The building you\'re in only has electricity for the next few hours.\n')); + console.log(chalk.magenta.bold('Before you are two doors:\nDoor 1 leads to your organs...\nDoor 2 leads you to the outside world...\n')); + console.log(chalk.magenta.bold('Just remember that the nearest hospital is miles away...')); + console.log(chalk.magenta.bold('If you choose to stay, however, just know there are traps all througout the building.\n')); +}else{ + leaveGame(); +} +}; + +const doorChoice = () => { +console.log(chalk.magenta.bold('The door you choose holds your destiny my friend.... \n')); +let choice = readline.question(chalk.red.bold('Which door will you choose, 1 or 2? \n')); +let firstDoor = '1' +let SecondDoor = '2' +while(choice){ + if(choice === firstDoor){ + console.log(chalk.magenta.bold('It smells disgusting in here! Must be your organs rotting.\nHurry Up!')); + choice = false + break; + }else if(choice === SecondDoor){ + console.log(chalk.magenta.bold(`The door behind you just locked.\nThe forest surrounds you on all sides!\nThere is nowhere to go ${nameInput}.\n`)); + console.log(chalk.blue.bold('Seems you died my friend. GAME OVER')); + choice = false + restartGame() + }else{ + console.log(chalk.green.italic(`That wasn't a choice ${nameInput}. You don't really listen.\nI don\'t usually like repeating myself, but ahemmm.`)); + choice = readline.question(chalk.red.bold('Which door will you choose, 1 or 2? \n')) + } +} +}; + + +const moveOne = () =>{ +console.log(chalk.magenta.bold('To the left of you there is a long dark hallway with loud music.')); +console.log(chalk.magenta.bold('In front of you there is a staircase, that leads down to a long hallway with a very bright light at the end of it.')); +let l = 'left' +let f = 'forward' +let firstMove = readline.question(chalk.red.bold('Which path will you take, left or forward? \n')); + if(firstMove === l){ + console.log(chalk.magenta.bold(`I see that you like music ${nameInput}. Lets hope that love leads to your organs!\n`)); + console.log(chalk.magenta.bold('As you\'re walking, you notice the music gets louder and louder with every step you take.\nHowever, you can\'t seem to find the source.\n')); + }else if(firstMove === f){ + console.log(chalk.magenta.bold(`You're walking the very long and dark hallway. You might start feeling out of breath ${nameInput}.\n`)); + }else{ + console.log(chalk.green.italic(`You don\'t listen much ${nameInput}.\nThat was not a valid input!\nI don't like repeating myself, but ahemmmm.`)); + moveOne(); + } +}; + +const moveTwo = () =>{ +console.log(chalk.magenta.bold(`Looks like you've reached another crossroads ${nameInput}.\nBoth paths are dark.`)); +if(readline.keyInYN(chalk.red.bold('Do you want to keep walking?\n'))){ + console.log(chalk.magenta.bold('Your bravery takes my breath away. That takes a lot of guts!\n')); +}else{ + console.log(chalk.magenta.bold(`Unfortunately this game isn't for scary cats like you ${nameInput}!`)); + leaveGame() + }; +}; + +function moveThree(){ +let r = 'right' +let u = 'up' + console.log(chalk.magenta.bold('Before you is a staircase that leads to the kitchen, but I\'m sure you\'re not hungry.')); + console.log(chalk.magenta.bold('To the right of you there is a bedroom with a refrigerator in it.....it reeks in there!\n')); + console.log(chalk.magenta.bold(`Let's hope you choose the right path this time ${nameInput}.\n`)); + let thirdMove = readline.question(chalk.red.bold('Which way will you go, right or up? \n')); + if(thirdMove === r){ + console.log(chalk.magenta.bold(`It seems you like making the "right" choice.\nExcept this time, the "right" choice, wasn\'t right ${nameInput}!\n`)); + console.log(chalk.blue.bold('Seems you died my friend. GAME OVER')); + restartGame(); + }else if(thirdMove === u){ + console.log(chalk.magenta.bold('The stairs are sliperry, and the smell of iron consumes you.')); + console.log(chalk.magenta.bold('Moonlight comes in through the window, allowing you to see a clear, bloody glass box.\n')); + console.log(chalk.red.italic('It\'s your lungs!\n')); + if(readline.keyInYN(chalk.red.bold('Are you ready to brake the glass, and get your lungs? \n'))){ + console.log(chalk.magenta.bold(`You should make better choices ${nameInput}. You have no object to brake the glass with.\n`)); + console.log(chalk.red.bold('You cut your arm while braking the class and bled out. What a bloody mess....\n')); + console.log(chalk.blue.bold('Seems you died my friend. GAME OVER')); + restartGame(); + }else{ + console.log(chalk.red.italic('\nGreat choice!\n')); + console.log(chalk.magenta.bold('You will need a hammer to brake the glass!')); + } + }else{ + console.log(chalk.green.italic(`You don\'t listen much ${nameInput}. That was not a choice.\nI don\'t like repeating myself, but here goes nothing...`)); + moveThree(); + } + }; + +const smashBox = () => { +let choiceOne = 'grab' +let choiceTwo = 'leave' +let choiceThree = 'swing' +console.log(chalk.magenta.bold('The hammer is on the window sill.\n')); +let action = readline.question(chalk.red.bold('Will you grab or leave the hammer? \n')); +if(action === choiceOne){ + console.log(chalk.red.italic('\nGreat choice!\n')); + console.log(chalk.magenta.bold('If you swing your arm, you\'ll brake the glass.\nYou can almost smell the victory! You\'re so close to survival!')); + action = readline.question(chalk.red.bold('Ready?..... Swing now!\n')); + if(action === choiceThree){ + console.log(chalk.red.italic('\ncongratulations, you\'ve acquired your lungs!\n')); + console.log(chalk.magenta.bold('Your determination is truly breathtaking.\n')); + }else{ + console.log(chalk.magenta.bold(`You should have swang ${nameInput}.`)); + console.log(chalk.blue.bold('Seems you died my friend. GAME OVER')); + restartGame(); + } +}else if(action === choiceTwo){ + console.log(chalk.magenta.bold(`You don\'t really make good choices ${nameInput}.`)); + console.log(chalk.magenta.bold('Why would you leave?')); + leaveGame() +}else{ + console.log(chalk.green.italic('You don\'t listen')); + console.log(chalk.green.italic(`That wasn\'t a choice ${nameInput}.`)); + console.log(chalk.green.italic('I guess I\'ll have to repeat myself...ahem')); + smashBox(); + } +}; + +function chooseSurgeon (){ +console.log(chalk.magenta.bold('You must be out of breath with all that swinging.')); +console.log(chalk.magenta.bold('Now that you have obtained your lungs, you must choose a surgeon.\n')); +console.log(chalk.magenta.bold('I\'ll let you choose the surgeon of your liking for now...\n')); +let surgeonChoice = ['Butcher', 'Retired Clown', 'Award-Winning Surgeon', 'Magician']; +index = readline.keyInSelect(surgeonChoice, 'Which surgeon woudld you like?\n'); + if(index === -1){ + process.exit(); + }else if(index === 2){ + console.log(chalk.magenta.bold('I don\'t understand why everyone keeps choosing the ' + surgeonChoice[index] +'.')); + console.log(chalk.magenta.bold('\nlet me tell you a little story about the ' + surgeonChoice[index] + '.')); + console.log(chalk.magenta.italic('\nFive years ago, he was in a traggic accident where he lost all 4 of his limbs, and punctured a lung.')); + console.log(chalk.magenta.italic('Now he sits in this building waiting for people like you ' + nameInput + '.' + ' People who choose to participate in this experiment.')); + console.log(chalk.magenta.italic('Those who don\'t make it, become organ donors. donating their body parts, to him.\n')); + console.log(chalk.magenta.bold('You can keep the ' + surgeonChoice[index] + ' or you can try your luck with another surgeon.\n')); + console.log(chalk.magenta.bold('This one will be appointed to you, however.\n')); + if(readline.keyInYN(chalk.red.bold('Would you like to take your chances on another surgeon?\n'))){ + givenSurgeon(); + }else{ + console.log(chalk.magenta.bold(`\nWell, then I guess...good luck ${nameInput}, see ya never.`)); + console.log(chalk.blue.bold('Seems you died my friend. GAME OVER')); + restartGame(); + } + }else if(index === 0){ + console.log(chalk.red.italic('The ' + surgeonChoice[index] + '?' + ' That\'s a great choice!')); + console.log(chalk.magenta.bold('Everyone always underestimates the ' + surgeonChoice[index] + ',' + ' but he\'s actually the best surgeon here.\n')); + console.log(chalk.magenta.italic('He was a ' + surgeonChoice[index] + ' 10 years ago, but fell so much in love with cutting into muscle, that he decided to become a surgeon.\n')); + console.log(chalk.yellow.bold(`Congratulations! You\'ve won the game ${nameInput}! You'll be home in no time!`)); + process.exit(); + }else{ + console.log(chalk.magenta.bold('The ' + surgeonChoice[index] + ' will be your surgeon and try to give you back the breath of life!\n')); + console.log(chalk.magenta.bold('Good luck! ' + nameInput + '.' + ' You\'ll need it!')); + console.log(chalk.blue.bold('Seems you died my friend. GAME OVER')); + restartGame(); + } +}; + +function givenSurgeon (){ +console.log(chalk.magenta.bold('Since you decided to judge a book by it\'s cover, and made the wrong choice. You must now be appointed a surgeon.\n')); +console.log(chalk.magenta.bold(`Your life will be in their hands...may the odds be in your favor ${nameInput}.`)); +if(readline.keyInYN(chalk.red.bold('Are you ready to meet your surgeon?'))){ +let surgeon = ['Butcher', 'Retired Clown', 'Award-Winning Surgeon', 'Magician']; + let giveSurgeon = surgeon[Math.floor(Math.random() * surgeon.length)] + if(giveSurgeon === surgeon[2]){ + console.log(chalk.green.bold(`Seems luck is just not on your side ${nameInput}.....the ${giveSurgeon} will still perform your surgery.\n`)); + console.log(chalk.green.bold('See ya never!')); + console.log(chalk.blue.bold('Seems you died my friend. GAME OVER')); + restartGame(); + }else if(giveSurgeon === surgeon[0]){ + console.log(chalk.red.italic('The ' + giveSurgeon + '!' + ' You\'re in luck!\n')); + console.log(chalk.magenta.bold('Everyone always underestimates the ' + giveSurgeon + ',' + ' but he\'s actually the best surgeon here.\n')); + console.log(chalk.magenta.italic('He was a ' + giveSurgeon + ' 10 years ago, but he fell so much in love with cutting into muscle, that he decided to become a surgeon.\n')); + console.log(chalk.yellow.bold(`Congratulations! You\'ve won the game ${nameInput}!`)); + process.exit(); + }else{ + console.log(chalk.magenta.bold(`The ${giveSurgeon} will be your surgeon and try to give you back the breath of life!\n`)); + console.log(chalk.magenta.bold('Good luck! ' + nameInput + '.' + ' You\'ll need it!')); + console.log(chalk.blue.bold('Seems you died my friend. GAME OVER')); + restartGame(); + } +}else{ + console.log(chalk.cyan.bold('How rude! What kind of person are you?\nThe surgeon was looking forward to meeting you!\nThere are no more surgeons availble for your procedure.')); + leaveGame(); +} +}; + +function restartGame (){ +if(readline.keyInYN(chalk.red.bold('Play Again?\n'))){ + howToPlay(); + story(); + doorChoice(); + moveOne(); + moveTwo(); + moveThree(); + smashBox(); + chooseSurgeon(); + givenSurgeon(); +}else{ + leaveGame(); +} +} + + +startGame(); +howOld(); +story(); +doorChoice(); +moveOne(); +moveTwo(); +moveThree(); +smashBox(); +chooseSurgeon(); +givenSurgeon(); +restartGame(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 4e5e2be..1082e20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,138 @@ { "name": "FSW-Text-Based-Adventure", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "chalk": "^4.1.0", + "readline-sync": "^1.4.10" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/chalk": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", + "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" + } + }, + "node_modules/readline-sync": { + "version": "1.4.10", + "resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz", + "integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==", + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + } + }, "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "requires": { + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", + "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, "readline-sync": { "version": "1.4.10", "resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz", "integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==" + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "requires": { + "has-flag": "^4.0.0" + } } } } diff --git a/package.json b/package.json index 8e8b06f..ec48514 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ }, "homepage": "https://github.com/joinpursuit/FSW-Text-Based-Adventure#readme", "dependencies": { + "chalk": "^4.1.0", "readline-sync": "^1.4.10" } } diff --git a/textBasedAdventure.js b/textBasedAdventure.js deleted file mode 100644 index d392b19..0000000 --- a/textBasedAdventure.js +++ /dev/null @@ -1,5 +0,0 @@ -const readline1 = require('readline-sync') - -let nameInput = readline.question("Enter your name: ") - -console.log(`Hello ${nameInput}! Welcome to my game.`)