 Okay welcome to the Harry Potter text adventure code review. This is a kind of a code review of this game I made a long long long long time ago when I knew very very little about JavaScript and I didn't know anything about object oriented programming at the time so you'll see that in the code. And so first let me show you what the game looks like. Okay so basically it's just a one-page website there's some images and it's like an old-school text adventure like Zork if you're familiar with that and you just interact with the world basically through you know text commands. So you can see here you are Harry Potter, Hermione and Ron have been captured by Lord Voldemort. You need to rescue them. So press enter to begin. So it tells you where you are. You are in Dumbledore's office. It says there are a lot of old books on bookshelves. Dumbledore's desk has various items on it. There's a magic mirror in one corner and Dumbledore is sitting behind his desk. Now you'll notice over here there's a score. This is your inventory. These are the things you've picked up and these are the directions you can move. Now in this particular case since they're all white that means you actually can't move in those directions. So you got to basically kind of just solve the puzzle of the world you're in. So if you type help it gives you a little bit of a hint. So here's some of the command you can use. INV for inventory that tells you what you have. Ask, talk or say to talk to someone. You can go like go north, go south, go east but it's easier to do E and SW. You can get items, you can drop items, you need to examine things. That's really really important. You have to guess the rest of the commands. Good luck. So hit enter again. So you have to think about the situation. So in this case I want to go ahead and ask Dumbledore. Now notice it's very very simple. It's verb object. So Ron and Hermione were kidnapped by Lord Voldemort. Take this magic amulet. It will glow when you get close to your friends. When you find them save, return us. Good luck. That's a really key piece of information. I've done this many many times with my students over the years and there's always a group that gets to the end of the game and then they realize they didn't write down the magic word and they've forgotten what it is. So yeah, make sure you remember that. So you can see an amulet. So I'm gonna go ahead and get the amulet. Then you can see how it appears over here. My score went up. I'm just gonna go ahead and examine the amulet. So the amulet has a large crystal in the center. So basically with this type of game, I thought to Dumbledore. I found out what I got to do. I've got the amulet. I'm done with him. The next thing I'm gonna do is I'm gonna go ahead and examine the mirror. You'll see where it says the mirror is bigger than you and has a gold frame. There's some ancient writing on the frame. It says to use this mirror, say it thou trail fads. So kind of tells you. I'm gonna go ahead and say trail fads. Okay. So the magic mirror begins to glow. You feel yourself floating towards the mirror. You go through the mirror and find yourself on a path. You're on a path. The path goes in many different directions. To the north you can see trees. Must be the legendary forbidden forest. To the south you can see a river. And to the east is the castle of the evil Lord Voldemort. And you see up here you can go north. You can go east. You can go south. Now I can actually just click on these. Okay so you're standing by a wide slow moving river. The river continues to the west. I'm gonna go ahead to the west. You can see the river is a little bit more narrow here. There's a lot of trash laying around. You can see a bottle. So I'm gonna go ahead and get the bottle. I'm gonna examine the bottle. It says the bottle is old. It says Voldemort's vineyards inside. It has a note inside. Oh my gosh. So at this point you gotta think about okay how am I gonna get the note? And then you say like get notes. You can't get the note. Okay so let's say examine notes. Nothing happens. It wasn't very good programming on my part. So basically you got to think about what would you do. You can try opening the bottle. It says you can't open the bottle. So thinking about what would you do in this case. And so I might say break bottle. And so you break the bottle and the note falls to the ground. You can see notes. So get notes. Now I'm gonna go ahead and drop the bottle because I don't need it anymore. But I do need the note. And then you can go ahead and you can read the note. You can examine the note etc etc. This is what these old text ventures were like except there was no graphics. I just added graphics because I know students would be bored with no graphics. So what I want to do today was to take a look at the code part of it. And so let me go ahead and show you that. Now as I mentioned I made this ages and ages and ages ago. So my coding was not particularly good. I didn't know hardly anything about CSS. I knew just enough to do some really really basic stuff. You can see the code formatting is terrible. I'm really really you know strict about that with my own students about code formatting and about naming variables and things. Now everything what's nice I guess is everything is basically on one file or in one file except for the images. Now you'll see here I made things about 800 by 480 screens were smaller than. So I had to like you know magnify it or zoom in on it when I was showing it to you. And you can see again just you know you would never do this anymore. You do everything in CSS. Also tables you know tables aren't really a thing anymore either. I don't mean it works which is important but it's not very very pretty. You can see just some of these values or everything's just like kind of hard-coded to 800 by 480, 640 by 420. It looks nice because it's all aligned but again it's not really the way you want to do things. You can just see some really just yeah just stuff that you would just never do anymore in in HTML. You'd be using CSS for all of these things. So you know technology has evolved. I've learned more and I think I have and this is your this is the North-South-East-West part of it. So you see on mouse over on mouse out. That's what changes all the colors and things. And then so just it's just a bunch of nested tables. You know all the images are in a folder called images and just yeah just capitalization is weird. I'm really I'm really strict about that now. I would never have I would never write some of the stuff the way I did here. Now this is where we actually get to the JavaScript. Yeah JavaScript 1.2 I don't even know what version JavaScript is up to but I'm pretty sure it's way past 1.2 at this point. So you can just see some of this stuff is just really really old style. So there's some variables here that's OK. I'm almost embarrassed to show this. So you can see how there are rooms in the game. There's inventory. There's items and there's stat items which are static items. I'll explain that in a little bit. So rather than you know put these things into a list or an array I hard coded the numbers and it's just yeah it's just ugly really really ugly. Here it made an array for the the room array because it's basically you know if you want to go north from room one well you can't that's a zero. But if you're in room one you can south is to east takes you to room three. Yeah you can see how kind of all those things work. And again just the code formatting here is atrocious. You know if I were doing this now I would probably I would do something along these lines. So it's actually a bit more readable. Again I would never let my students submit code like this. So yeah yeah see here and again same thing here. I've got a nested loop but you can't even tell it's nested because the indenting is just completely off. Yeah it's pretty bad. And then here is where I created all of the room. This is basically the room array and this is where you know so if you're in room one and you want to go I think north you can't go because it's a zero. Yeah so basically this is a Dumbledore's room right. So zero zero zero zero you can't go anywhere from Dumbledore's room. Also notice I started with room one because the zero was being used for no room which I guess is an okay decision. But you can see here these rooms you can actually go up and down. This one you can only go probably down. This one you can probably only go up or you can go up from that room. So this is basically the array that controls you know where you can move. Again I just probably would not do things like this anymore. So these are the scores so there's some you know some puzzles in the game. So for example you saw earlier about the notes so if you get the notes your score is five. You get five extra points for getting the notes. You get five points for getting the amulet. For example you get five points for I think for smashing the bottle as well. So you can see there's quite a few things you have to deal with. You have to figure out in the game these are the scores. Now what I would do now is I would create some sort of object and so like each object in the game would have a class and so it'd be like you know item class item and so the item each item like when you get it would have a score if it's if you want to have a score otherwise would be a zero. Then I use these flags. So flags are just like you know they hold the state of some sort of object and again I would do this in a class now as an object oriented style. Let's see here so like for example you know when you get the bottle initially it's closed. I think once you get it and break it the state is then broken. So depending on what its state is you know it's closed oh there's a note inside of it blah blah blah if it's broken then you know obviously there's no note inside anymore. And then here's where we have an array for items for images let's see l item l this is location this is I don't even know. This is another thing I tell my students description item location item description and item name item image. So I have four different arrays for to contain all the information for each item and again I would do this in a class it would just be so much easier again you know the indenting here is terrible and you can see here this is where I define all of the different items. So item zero is empty item one is the amulet which we saw earlier item one's images amulet.jpg and then this is the description for that item and when you start the game the item is in 88 now I don't know why I did this but 88 was like it didn't exist I don't think there's a room 88 I think I just used that number to represent like no place in the game because like it doesn't exist until Dumbledore gives it to you. So these are again at the time this is this is my level of coding ability. Now I got a lot of this from actually from some book I forget it was like 101 computer games or something like that how to program an RPG or an old school RPG I forget what it was called. So this is like really I took like a basic program not not basic as in simple but the programming language basic and I adapted it to JavaScript. So again so we've got all these different items again the text these are sorry the stuff is not indenting correctly God is horrible. So here are the static items now there's items which are things that you can get and not and you carry and that sort of thing these are all the different things you need to get in the game and then there are static items which are things that you can't get like you can't get Dumbledore you can't get the mirror there's a troll in the game you can't get the troll so you can see all these different things that you interact with but they can't be moved they're they're stuck in a particular location okay so again just some indentation problems oh my God this is just some of the worst things that are written so RO is the player's room so this is where the player is located so when the game starts the player is in room one again I capitalize that uh I should have just typed room or player room or player location I just yeah the variable names and this is horrible and then I made these keywords to see if the computer actually understands what the player is has typed so this is the keyword so this would be like get bottle okay okay w would be the object keyword so like maybe get bottle or something like that so does it understand the keyword doesn't understand the object and then the player's score so same thing here I would probably make a player object and that player object would have a score attached to it so here are all the rooms so each room has a has an image it has a name uh has a description uh I can see like just I'm just using arrays here this is just so bad um yeah please don't code like this uh now this is our kind of our main loop and it's not really a loop since it doesn't run unless all right but it doesn't run unless the user does something so I wouldn't call it the main loop um again just didn't know what I was doing so um everybody's got to start somewhere and so I'm gonna go ahead and like roll scroll down through here and just kind of indent start fixing the indentation uh oh this is just it's it's practically unreadable um it's a long program though um so basically it's it's a text adventure so it's really just a ton of uh if statements for the most part um so you get the command from that part of the document um and it just kind of it like if you if you type like get the key it just reduces that to get key um so stuff like put on it reduces that to where because it's the same meaning so oh my god yeah so this is like this separates the command into verbs and objects let's see again so same thing here with this the structure um this is probably the way I would go with it um now you can again you can do this I just at this point you know I'm really a bit a bit more strict about you know how code is aligned um so same thing here now you see there's just a ton of if statements here where you know if this then that which is fine um but you know I would probably do this in an array now or something I would do something different so I could just add stuff to it ease it more easily so you read it becomes examined exit exit exa becomes examined um this this fixes like if the user types a lower case it turns into an upper case but again I'm not going to try and fix the whole thing at this point but like you can just see how the it's just the indentation is terrible and again this should all be this should be like a loop of some sort not like a ton of if statements because what what does the game work 10 times is big and you have a million of statements this is terrible um so then here's where we basically work on the game logic so um so it for example I do use this means that the program understands the keyword now I have to check the object okay so if it's the ambulance besides I if I type something like use amulet um it says you should really be more specific how would you like to use the amulet so it kind of deals with the different things so if I say use the bottle you should be more specific if I say use the mirror you should be more specific um you know it's kind of like the same thing over and over again um these are commands that deal with certain aspects of the game so I'm going to go ahead and tab that in um so if I'm in room one and the verb is say and the object is trail fast so this is the magic word we learned so I understand the keyword and the object keyword I'm going to go to room two and I'm going to print the message the magic mirror begins to glow which you saw earlier in the game and you get five points okay now this is where I dealt with stuff like you know the user tries to do stuff that you can't do so for example if you're in room one and you try to get the magic mirror you try lifting it but it's too big blah blah blah so there's just basically a lot of if statements in this game and oh my god this is horrible um so I would have made I should have made a function for some of this stuff um so you can see how if you ask say or talk Dumbledore um yeah says oh hey Ron and Hermione are kidnapped by lord Voldemort take this magic amulet um so you can see here if item l equals 88 88 was just no location then I move that item to room one and then you get five points so nice yeah you get five points I didn't even use I didn't even use these scores I don't know what I was thinking so they're in there but they were never used um yeah wow this is bad so this is basically how the game works um it just changes in your location whether you understand things or not I know what this is um um oh I did I did do this I did make a function called player has which is an improvement um but you can basically see how the game functions hopefully from here um so you can see how we use flags uh and things like that to determine whether or not the game works or whether or not a something is in a certain condition um yeah I think I'm gonna stop there this is just it's embarrassing um but you get the I hopefully just from watching this a little bit you get the idea that you know what what kind of badly written code looks like um it's not formatted properly you know you're using tons of arrays where you could be using objects which make your your program much much simpler um you know these variable names just don't really make a lot of sense in certain cases like ro for room um which is where the player is and just yeah it's just just really really bad I'm a lot of this stuff should be you know put into functions and organized by at least organized by functions um yeah that's it's that's about it um um oh my god this is terrible uh yeah so uh I'm just gonna I'm just gonna stop there um as I said this this has been my uh first video in like six months I guess I'm a little rusty but uh hopefully uh you got something out of this if you'd like to play the game I'll put a link down below uh to my website where you can kind of try it out and if I get get around so I'll put a link where you can actually download this and play with the code yourself and maybe uh improve the game it's it's it's a it's a pretty fun I think my students really enjoy it so uh anyway uh that's it uh thanks for listening and uh keep on coding take care