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/Narniagameplay.gif b/Narniagameplay.gif new file mode 100644 index 0000000..ee484a2 Binary files /dev/null and b/Narniagameplay.gif differ diff --git a/README.md b/README.md index 1851af6..3e09c4d 100644 --- a/README.md +++ b/README.md @@ -1,77 +1,26 @@ -# Text-Based-Adventure +# 🌬 ❄️ 🐺 🦫 Text-Based-Adventure Game - Narnia! 🦫 🐺 ❄️ 🌬 -## Introduction +This project was built with javascript as a text based adventure game that you can play in terminal! -This project will build on the skills that you've learned after your first couple weeks of programming in JavaScript! You will build a command line application that plays a text-based adventure game. +My Trello project link: [Trello](https://trello.com/b/vjRX7ODW/my-text-based-adventure-project) -### Examples +Instructions to run this code: +1. Git clone this repo +2. Open up the code in VSCode or your choice of IDE +3. Run npm install to install dependencies that this project uses +4. Run node textBasedAdventure.js +5. Play! -Look [here](https://classicreload.com/zork-i.html) and [here](http://www.bbc.co.uk/programmes/articles/1g84m0sXpnNCv84GpN2PLZG/the-hitchhikers-guide-to-the-galaxy-game-30th-anniversary-edition) for a couple examples of the genre. Be creative! +![Gamegif](https://github.com/sbweins/FSW-Text-Based-Adventure/blob/master/Narniagameplay.gif?raw=true) -A fun Google easter egg is to Google search `text adventure`. From the results page right click on the page and inspect the console. You should find a game by Google. -### Reading input +```javascript +console.log("Hello there! Welcome to Narnia!") -This project imports an npm module called `readline-sync` that allows the user to enter input to the terminal. The line at the top: `const readline = require('readline-sync')` gives you access to this functionality - -Use the following line to get user input: - -```js -let yourVariableHere = readline.question("Enter your name: ") +if (readlineSync.keyInYNStrict("Would you like to explore the world of Narnia? (Please type Y or N)")) { + play() +} +else { + leaveGame() +} ``` - - -## Setup Instructions - -1. Fork this repo -1. Clone the forked repo to your machine -1. `cd` to the cloned folder and type `npm install` in the terminal. -1. Create a file called `.gitignore`. -1. Inside of .gitignore write `node_modules/` - -## Submission Instructions - -1. Complete the project -1. Commit and Push your changes to your fork -1. Submit a Pull Request back to the assignment repo -1. Paste a link to your Pull Request (not your fork!) on Canvas and submit - - -## User Stories - -### As a user, I want to be able to begin a game - -#### Acceptance criteria - -- Cloning your project, running `npm install` and `node YOURPROJECTNAMEHERE.js` will start a game -- No errors are logged to the console -- The game displays initial instructions about how to play and a welcome message - -### As a user, I want to be able to make decisions during the game - -#### Acceptance criteria - -- Invalid entires are re-prompted -- There are at least 10 opportunities to make a decision -- The user must enter a string to make a decision -- The user must enter a number to make a decision - -### As a user, I want to be able to restart a game - -#### Acceptance criteria - -- The user is prompted to restart the game and can enter yes or no -- Entering no causes the program to terminate -- Entering yes begins the game again, wiping the previous state - -## Trello Board - -Replace the link below with the link to your Trello project: - -[Trello](https://trello.com/b/vbKtMOKj/text-based-adventure-project-plan) - - -## Rubric - -![outcomesRubric.png](./outcomesRubric.png) -![acRubric.png](./acRubric.png) 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 index d392b19..00c66c8 100644 --- a/textBasedAdventure.js +++ b/textBasedAdventure.js @@ -1,5 +1,221 @@ const readline1 = require('readline-sync') +const readlineSync = require("readline-sync") -let nameInput = readline.question("Enter your name: ") +const chalk = require('chalk'); +const { greenBright } = require("chalk"); -console.log(`Hello ${nameInput}! Welcome to my game.`) + +const loseGame = () => { + console.log(chalk.redBright.underline("============================================================================")) + console.log(chalk.redBright("Sorry, You didn't find Aslan!\nYou can keep trying though!")) + leaveGame() +} + + +const winGame = () => { + console.log(chalk.redBright.underline("============================================================================")) + console.log(chalk.redBright.underline("You did it! You've just entered the Kingdom of Narnia!\nYou found Aslan, The king Of Narnia!\nYou have been rewarded infinite life in Narnia!\n................To be continued! =)")) +} + + +const play = () => { + + + console.log(chalk.whiteBright.underline("============================================================================")) + console.log(chalk.cyanBright.bold("Great! We are so glad you want to explore Narnia today!\n")) + const userName = readlineSync.question(chalk.cyanBright("Please introduce yourself by entering your name:\n")) + console.log(chalk.cyanBright(`Welcome ${userName}! You are now beginning a quest into Narnia!`)) + + + const beginPLayQ = () => { + + const askAge = () => { + const age = readlineSync.question("How old are you?: )\n") + if (age <= 7) { + console.log(chalk.yellow("Wow, are you really that young? =) Let's play Narnia!")) + } + + else if (age <= 23) { + console.log(chalk.yellow("Hello Generation Z - lets play Narnia!")) + } + + else if (age <= 39) { + console.log(chalk.yellow("Welcome fellow Millenial, You must know about Narnia =)!")) + } + + else if (age <= 55) { + console.log(chalk.yellow("Hello Generation X! Let's play!")) + } + + else if (age <= 74) { + console.log(chalk.yellow("Boomers! Welcome!")) + } + + else if (age > 74) { + console.log(chalk.yellow("Hello Silent generation! ")) + } + else { + console.log('Error! - Incorrect input'); + askAge(); + } + } + + askAge() + + const askHowRU = () => { + const ansHowRU = readlineSync.question(chalk.cyanBright("How are you doing today? (Please answer with: great, okay, bad : )\n")) + if (ansHowRU === "great") { + console.log(chalk.cyanBright("Glad to hear it, Let's keep it going!")) + } + else if (ansHowRU === "okay") { + console.log(chalk.cyanBright("Just okay? Let's make it better!")) + } + else if (ansHowRU === "bad") { + console.log(chalk.cyanBright("Well then, we have some work to do, lets get started!")) + } + else { + console.log('Error! - Incorrect input'); + askHowRU() + } + } + + askHowRU() + + + + } + + beginPLayQ() + + console.log(chalk.whiteBright.underline("============================================================================")) + console.log(chalk.whiteBright.underline("You have just been transported to the world of Narnia.\nYou find yourself in the middle of a snow covered forest.")) + console.log(chalk.cyan("You have to find the way to get to the King of Narnia who will reward you!\nBe careful not to encounter the White Witch, she's not who she says she is.")) + + + + const directionToGo = () => { + + const direction = readlineSync.question("Where would you like to go? Please type north, south, east, or west to proceed\n") + if (direction === 'north') { + + console.log(chalk.whiteBright.underline("============================================================================")) + console.log(chalk.cyan("You have just encountered a fawn who lives in the forest")) + + if (readlineSync.keyInYNStrict(chalk.blueBright("The fawn asks you a question: 'It's so cold out here, would you like to join me for some biscuits and a hot cup of tea?' (Please type Y or N)\n"))) { + console.log(chalk.blueBright("The fawn says: 'I am so glad you can join me! It's not often we have human visitors! =)'")) + } + else { + console.log("Oh no! quitting already? The goal is to get to the King of Narnia!") + leaveGame() + } + + + if (readlineSync.keyInYNStrict(chalk.blueBright("The fawn asks you another question: 'Do you trust me?' (Please type Y or N)\n"))) { + console.log(chalk.blueBright("The fawn says, 'I am so sorry, I have something to tell you... I work for the White Witch and I was going to lead you to her.")) + console.log(chalk.blueBright("Your kindness has changed my mind and I want to help you get to Aslan, the King of Narnia!")) + } + else { + console.log(chalk.cyan("Oh no! quitting already? The goal is to get to the King of Narnia!")) + leaveGame() + } + + + if (readlineSync.keyInYNStrict("The faun asks: 'Are you ready to enter the Kingdom of Narnia? (Please type Y or N)'\n")) { + console.log(chalk.whiteBright.underline("============================================================================")) + console.log(chalk.cyan("The Fawn leads you to the Great Kingdom of Aslan!")) + winGame() + } + + else { + console.log(chalk.cyan("Oh no! The goal is to get to the King of Narnia!")) + leaveGame() + } + } + + else if (direction === 'south') { + console.log(chalk.whiteBright.underline("============================================================================")) + console.log(chalk.cyan("You've just entered the White Witch's territory! You can see her in the far distance.")) + if (readlineSync.keyInYNStrict("Do you wish to proceed?(Please type Y or N)'\n")) { + console.log(chalk.cyan("You have just encountered the White Witch and her orcas have tied you up and taken you captive.")); + readlineSync.keyInYNStrict(chalk.redBright("The White Witch asks: 'Are you looking for the King of Narnia?' (Please type Y or N)\n")) + console.log(chalk.whiteBright.underline("============================================================================")) + console.log(chalk.redBright("The White Witch says, 'There is no King of Narnia! You are now under my control and you will do as I say!'")) + console.log(chalk.whiteBright.underline("============================================================================")) + console.log(chalk.cyan("Unfortunately, you have been imprisoned and you are now under control of the White Witch.")) + loseGame() + } + else { + loseGame() + } + } + + + else if (direction === "east") { + console.log(chalk.whiteBright.underline("============================================================================")) + console.log(chalk.cyan("You have just encountered Mr. Beaver in the forest and he is thrilled to see you!")) + console.log(chalk.greenBright("Mr. Beaver says: 'Hey there! We have been waiting for you a very long time!'")) + if (readlineSync.keyInYNStrict(greenBright.greenBright("Mr. Beaver asks: 'Are you here to save our forest?'"))) { + console.log(chalk.greenBright(`Mr. Beaver says: 'We are truly thankful for your bravery!'`)) + if (readlineSync.keyInYNStrict(chalk.greenBright("Mr. Beaver asks: Would you like us to lead you to the King of Narnia?'"))) + console.log(chalk.cyan("Your bravery has been rewarded, Mr. Beaver is now leading you to the King of Narnia!")) + winGame() + } + else { + loseGame() + } + } + + + else if (direction === "west") { + console.log(chalk.whiteBright.underline("============================================================================")) + console.log(chalk.cyan("You have encountered a black wolf walking through the western part of the forest")) + if (readlineSync.keyInYNStrict("Do you wish to proceed?(Please type Y or N)'\n")) { + console.log(chalk.magentaBright("The black wolf says: 'I smell a human! Just what the White Witch was looking for!'")) + if (readlineSync.keyInYNStrict(greenBright.magentaBright("The black wolf asks: 'Are you here to find the King of Narnia?'"))) { + console.log(chalk.magentaBright("The black wolf says: 'Well follow me and I can show you something better!'")) + loseGame() + } + else { + loseGame() + } + } + } + + + else { + console.log('Error! - Incorrect input'); + directionToGo() + } + + + } + + directionToGo() + +} + + + + +const leaveGame = () => { + console.log(chalk.whiteBright.underline("It's okay if you don't want to explore Narnia today!")) + console.log(chalk.whiteBright.bold("We'd like to say see you next time...")) + console.log(chalk.whiteBright.bold("But... we dont know if there will be another chance to explore Narnia!")) + if (readlineSync.keyInYNStrict("Do you want to continue to explore the world of Narnia? (Please type Y or N)")) { + play() + } + else { + console.log(chalk.yellowBright.bold("Good luck to you! We hope to see you again someday!")) + process.exit() + } +} + + +console.log("Hello there! Welcome to Narnia!") + +if (readlineSync.keyInYNStrict("Would you like to explore the world of Narnia? (Please type Y or N)")) { + play() +} +else { + leaveGame() +} \ No newline at end of file