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/package-lock.json b/package-lock.json index 4e5e2be..c047f7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,8 +1,25 @@ { "name": "FSW-Text-Based-Adventure", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "readline-sync": "^1.4.10" + } + }, + "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" + } + } + }, "dependencies": { "readline-sync": { "version": "1.4.10", diff --git a/textBasedAdventure.js b/textBasedAdventure.js index d392b19..2cbebd5 100644 --- a/textBasedAdventure.js +++ b/textBasedAdventure.js @@ -1,5 +1,80 @@ -const readline1 = require('readline-sync') +const readlineSync = require('readline-sync') -let nameInput = readline.question("Enter your name: ") +const startGame = () => { + console.log("Welcome") +let answer = readlineSync.keyInYN("Are you ready?") +if (answer) { + play() +} else { + leaveGame() + Process.exit() +} -console.log(`Hello ${nameInput}! Welcome to my game.`) +} +const leaveGame = () => { + let leavingAnswer = readlineSync.keyInYN("Aww man, it looks like you kicked the bucket\n Would you like to try again?") + if (leavingAnswer) { + play() + } else { + console.log("Goodbye") + } +} + +const youWin = () => { + let winningResponse = readlineSync.keyInYN('Would you like to play again') + if (winningResponse) { + play() + }else console.log("Goodbye") +} + + +const play = () => { + +let nameInput = readlineSync.question("Enter your name: ") + +let title = "A Warrior's Digest!" + +console.log('Hello ' + nameInput) + +console.log("Welcome to " + title) + +console.log('You ' + nameInput + ' are a gifted warrior from the ancient lands of True North.\n After countless years away you have finally returned home. Only to find ') +console.log('The objective of the game is to defeat the dragon and save your homeland.') + +let arr = ["Sword", "Bow & Arrow"] + +let warriorChoice = readlineSync.keyInSelect(arr, "Please, choose your weapon: ") + +console.log(nameInput +' has chosen the ' + arr[warriorChoice]) + + +console.log('There is a terrible dragon that has been destroying the lands of True North! \n You are the only hope for your lands survival!') + +let arr2 = ["Head", "Body", "Tail"] +let question2 = readlineSync.keyInYN("Will you " + nameInput + " face said dragon now?") + if (question2 === true) { + let question3 = readlineSync.keyInYN("Will you use the " + arr[warriorChoice] + " to attack?") + console.log(question3) +} else {console.log('Welp... the dragon ate you') +leaveGame() +process.exit() +} +if (question3 === arr2.length-2) { + let question4 = readlineSync.keyInSelect(arr2, "where will you use the " + arr[warriorChoice] + " to attack next?") +console.log(question4) +} else { + leaveGame() + process.exit() +} +let question5 = readlineSync.keyInSelect(arr2, 'Where will you attack next?') +if (question5 === arr2.length-1) { + console.log("Congratulations!!!!!!!!!!!!!!!\n You have slain the dragon!!!!!!!!!") + youWin() +} else { + leaveGame() +} + +} + + +startGame()