forked from CoachJulian/2023TeamEdgeTerm0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzombie_manor_starter.js
181 lines (118 loc) · 5.15 KB
/
zombie_manor_starter.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//This is the starter file for zombie_manor.js
//Use it to develop your skills as needed
const READLINE = require("readline-sync")
let inputMsg ="" //an empty string to hold our user inputs
let gameIsOn = true //the game loop will depend on this being true
let currentRoom = null //to keep track of where we are
let rooms = [] //push any new rooms you create to this array
//******** DEFINE CLASSES *******************
class Room {
constructor(name, description, objects, paths) {
this.name = name;
this.description = description;
this.objects = objects;
this.paths = paths;
}
}
class Player {
constructor(name, items){
this.name =name
this.items = items
}
}
//**********INSTANTIATE OBJECTS ***************
let player = new Player()
player.name = null
player.items = []
let kitchen = new Room()
kitchen.name = "Kitchen"
kitchen.description = "The kitchen is a really nice one! It has all the stuff you need to cook a healthy meal...of zombie parts! on the table there is a red pill."
kitchen.objects =["potion", "sandwich", "knife"]
kitchen.paths=["Living Room" , "Bathroom" , "Backyard" ]
let bathroom = new Room()
bathroom.name= "Bathroom"
bathroom.description ="You are in a Bathroom. Everything is a mess. There is blood on the floor. The shower is still on... "
bathroom.objects = ["towel" , "toothbrush", "toilet Paper", "soap"]
bathroom.paths =["Kitchen"]
rooms.push(kitchen, bathroom) //add the rooms to the rooms array
//************* START GAME *************************
function start(){
console.log("Welcome to Zombie Manor!!");
let name = READLINE.question("What is your name, player? ")
player.name = name
console.log("Welcome, " + name);
//begin at the kitchen
currentRoom = kitchen
console.log(`You are in a: ${currentRoom.name}. and everything looks normal. The air smells like death`)
while(gameIsOn){
checkAnswer(promptUser()) //this makes the game continously prompt and check response
}
}
function promptUser(){
let reply = READLINE.question("What do you want to do? >> ")
return reply
}
function checkAnswer(input){
console.log("checking input : " + input)
inputMsg = input
//GO
if(inputMsg.includes("go")){
//split the string into two arguments
let msgArray = inputMsg.split(" ")
let newRoom = msgArray[1] //get the second element
console.log(" user typed go to " + newRoom)
if(currentRoom.paths.includes(newRoom)){
console.log("Yes you can go there")
//find the room that has that "key" newRoom as a property
for (room of rooms){ //Make challenge!!!!
if(room.name.toLowerCase() == newRoom.toLowerCase()){
//set the current room by grabbing its index
let index = rooms.indexOf(room)
currentRoom = rooms[index]
console.log("You are now at the : " + currentRoom.name);
}
}
} else {
console.log("No you can't go there")
}
//LOOK
} else if(inputMsg.includes("look")){
//loop through all the objects and paths and print them out so user can see options
console.log("You see the following: ")
for(object of currentRoom.objects){
console.log(" - " + object)
}
console.log("From here you can go to: ")
for(path of currentRoom.paths){
console.log(" - " + path)
}
//TAKE
} else if(inputMsg.includes("take")){
console.log("Taking item...")
let itemsArray = inputMsg.split(" ")
let itemToTake = itemsArray[1] //get the second element
//check to see if it is part of the room's inventory..
if(currentRoom.objects.includes(itemToTake)){
console.log("Yes you can take this item: " + itemToTake)
player.items.push(itemToTake) //add to the players items array
//remove from room
let indexToRemove = currentRoom.objects.indexOf(itemToTake)
currentRoom.objects.splice(indexToRemove, 1)
//console.log("current room items after taking item " + currentRoom.objects)
console.log("player has : " + player.items)
} else {
console.log("No you can't pick that up")
}
//Name
} else if (inputMsg.includes("name")){
console.log( currentRoom.name);
} else if (inputMsg.includes("help")){
console.log(" You can type 'look' to look around and 'go' to follow a path.")
} else if (inputMsg == ""){
console.log(" input: " + inputMsg)
inputMsg = READLINE.question("What do you want to do? You can type 'help' for commands to use >>> ");
} else {
console.log(" I don't understand that")
}
}
start()