forked from joinpursuit/FSW-Text-Based-Adventure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextBasedAdventure.js
More file actions
80 lines (61 loc) · 2.22 KB
/
textBasedAdventure.js
File metadata and controls
80 lines (61 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const readlineSync = require('readline-sync')
const startGame = () => {
console.log("Welcome")
let answer = readlineSync.keyInYN("Are you ready?")
if (answer) {
play()
} else {
leaveGame()
Process.exit()
}
}
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()