1 00:00:00,830 --> 00:00:02,800 All right, I think this is the last of it. 2 00:00:02,800 --> 00:00:05,830 We just need to find out whether the player has found the door, the monster, 3 00:00:05,830 --> 00:00:07,240 or just another room. 4 00:00:07,240 --> 00:00:08,940 If they win, we should congratulate them, and 5 00:00:08,940 --> 00:00:10,770 if they lose, offer them a shoulder to cry on. 6 00:00:10,770 --> 00:00:12,100 I'll meet you in WorkSpaces. 7 00:00:13,540 --> 00:00:18,030 Okay, so now we need to check and see if the player has won or lost. 8 00:00:18,030 --> 00:00:24,100 And it seems like here in game loop, where we deal with moving the player, 9 00:00:24,100 --> 00:00:28,430 seems like this would be a good place for us to handle this check. 10 00:00:28,430 --> 00:00:28,970 So let's go ahead and 11 00:00:28,970 --> 00:00:31,540 add this in, I don't think this is gonna take us too long at all. 12 00:00:32,540 --> 00:00:40,010 So in here, if player is equal to monster, print, let's do our thing again here. 13 00:00:41,270 --> 00:00:43,700 No, the monster got you. 14 00:00:45,640 --> 00:00:47,120 Better luck next time. 15 00:00:49,120 --> 00:00:54,340 And then two more stars, and then we need to break because we want to end that loop. 16 00:00:56,470 --> 00:01:00,290 If player is equal to door, 17 00:01:00,290 --> 00:01:06,942 [NOISE] let's print, and lets say you escaped. 18 00:01:06,942 --> 00:01:09,442 Congratulations. 19 00:01:09,442 --> 00:01:14,250 And then we need to break there as well. 20 00:01:14,250 --> 00:01:18,500 And otherwise we're just gonna keep moving through the loop. 21 00:01:18,500 --> 00:01:21,600 So I think that's it, let's try playing the game. 22 00:01:21,600 --> 00:01:26,410 We may have to play this a time or two to find out if we win or not. 23 00:01:26,410 --> 00:01:28,730 All right, so welcome to the dungeon. 24 00:01:30,390 --> 00:01:33,250 So I'm there, and I'm in 0, 0, I can only move right and down. 25 00:01:33,250 --> 00:01:39,881 So let's go right, right, right, right, down. 26 00:01:39,881 --> 00:01:45,001 Left, left, left, left, down, 27 00:01:45,001 --> 00:01:49,777 right, right, right, right, 28 00:01:49,777 --> 00:01:56,110 down, left, no the monster got me. 29 00:01:56,110 --> 00:02:00,290 Okay, I don't wanna play through all that again just to escape or whatever. 30 00:02:00,290 --> 00:02:03,440 I'm pretty sure it's gonna work because it worked for this one. 31 00:02:03,440 --> 00:02:05,290 One of the things that's a little weird here, 32 00:02:05,290 --> 00:02:07,630 is that it just immediately quit, right? 33 00:02:07,630 --> 00:02:10,490 I mean great work everyone, we did an amazing job on this, 34 00:02:10,490 --> 00:02:13,960 but I think we can add a couple things to make it a little bit more friendly. 35 00:02:13,960 --> 00:02:18,745 And one of the first things I think we can do, is we can move this clear screen to 36 00:02:18,745 --> 00:02:24,670 the top of the loop, and that will make it to where things are a little bit nicer. 37 00:02:24,670 --> 00:02:25,880 So let's cut that out. 38 00:02:28,380 --> 00:02:32,550 And let's put the clear screen right here at the top of the while True. 39 00:02:32,550 --> 00:02:37,150 So we'll do clear screen right there. 40 00:02:37,150 --> 00:02:42,070 And something else that we can do is instead of using while True, 41 00:02:42,070 --> 00:02:46,040 which we have to break the loop, let's actually add a new variable here which is 42 00:02:46,040 --> 00:02:49,820 playing, not player, playing equals True. 43 00:02:49,820 --> 00:02:52,653 Because we're currently playing and 44 00:02:52,653 --> 00:02:56,645 while playing we want to do all of this stuff, right? 45 00:02:56,645 --> 00:03:01,180 Okay, so when we want to change the playing though, 46 00:03:01,180 --> 00:03:06,850 is whenever they have been eaten or they have escaped. 47 00:03:06,850 --> 00:03:09,830 So here let's make playing equal False. 48 00:03:11,280 --> 00:03:14,400 And here, let's make playing equal False. 49 00:03:15,740 --> 00:03:20,200 Okay, otherwise we leave our input and all that stuff all over again. 50 00:03:20,200 --> 00:03:25,900 And then that else is on this if, we can put an else on this while and 51 00:03:25,900 --> 00:03:30,580 if the while exits without having any exceptions or 52 00:03:30,580 --> 00:03:33,890 without getting a break, then this else will happen. 53 00:03:33,890 --> 00:03:38,640 So then we can do if input play again and 54 00:03:38,640 --> 00:03:44,000 we'll do a capital Y and then an in, let's do a space there. 55 00:03:44,000 --> 00:03:48,320 Let's lowercase this, and if that doesn't equal a lowercase n, 56 00:03:48,320 --> 00:03:53,350 and let's close that there, where we need to close it. 57 00:03:54,400 --> 00:03:57,910 Then let's just call game loop, again. 58 00:03:57,910 --> 00:04:03,190 Okay, so what we've done is we checked to see you know, we print and do the playing, 59 00:04:03,190 --> 00:04:05,590 and if they wanna play again will just immediately called the game loop. 60 00:04:05,590 --> 00:04:09,760 Now if they put in quit, then that's gonna throw this break. 61 00:04:09,760 --> 00:04:14,640 Which will not cause this else to happen and will just end of the game, and 62 00:04:14,640 --> 00:04:15,890 that's fine. 63 00:04:15,890 --> 00:04:23,990 So you know we can even put in a, like print, see you next time. 64 00:04:23,990 --> 00:04:29,125 Let's do our \n **, **\n, 65 00:04:29,125 --> 00:04:33,558 let's do that again as well. 66 00:04:33,558 --> 00:04:34,977 And so that way we can just quit and 67 00:04:34,977 --> 00:04:37,370 we can print the nice little message for them. 68 00:04:37,370 --> 00:04:40,003 Cool so we can end our loop or we can break out of our loop, and 69 00:04:40,003 --> 00:04:41,757 we can try all these different things. 70 00:04:41,757 --> 00:04:44,318 Let's see how these things work. 71 00:04:44,318 --> 00:04:48,993 So let's do Python dungeon_game.py, and 72 00:04:48,993 --> 00:04:52,318 I don't want to start the game. 73 00:04:52,318 --> 00:04:53,600 And first I wana try the quit, 74 00:04:53,600 --> 00:04:56,720 I wanna make sure that that works like we expect it to. 75 00:04:56,720 --> 00:04:59,980 So it says see you next time which is great, okay? 76 00:04:59,980 --> 00:05:02,790 So, that means it didn't go to the play again thing. 77 00:05:02,790 --> 00:05:07,124 So, now I need to win or I need to die and see what happens, so let's go right, 78 00:05:07,124 --> 00:05:12,416 up, left, left. 79 00:05:12,416 --> 00:05:21,520 [NOISE] I will eventually find something here. 80 00:05:22,870 --> 00:05:24,085 There's no way for me not to. 81 00:05:24,085 --> 00:05:30,291 [NOISE] Okay, 82 00:05:30,291 --> 00:05:33,690 I escaped, congratulations, play again, yes or no? 83 00:05:33,690 --> 00:05:39,500 So if I press enter if I type in yes if I type in sure, anything 84 00:05:39,500 --> 00:05:44,580 I type in that isn't an uppercase or lowercase in, we'll play the game again. 85 00:05:44,580 --> 00:05:48,600 So let's do the n and see what happens. 86 00:05:49,880 --> 00:05:51,720 It just ends the game, so great, 87 00:05:51,720 --> 00:05:55,130 if I was to put in something else it would have started the game all over again. 88 00:05:55,130 --> 00:05:58,420 But that's amazing, everything seems to be working, great work. 89 00:05:58,420 --> 00:06:00,825 Wow that was a lot of code but you made it through. 90 00:06:00,825 --> 00:06:03,614 You learned all about all the different Python collection types, 91 00:06:03,614 --> 00:06:05,880 and you made a pretty awesome game. 92 00:06:05,880 --> 00:06:07,860 You should definitely try to expand it too. 93 00:06:07,860 --> 00:06:11,790 You could add more rooms, make the monster move around, show the monster on the map, 94 00:06:11,790 --> 00:06:16,055 keep track of wins and losses, add more monsters or all sorts of other things. 95 00:06:16,055 --> 00:06:18,935 One thing that I think would be awesome is a debug mode that shows you 96 00:06:18,935 --> 00:06:20,735 where the door and the monster are. 97 00:06:20,735 --> 00:06:22,935 That would make testing the game a lot easier. 98 00:06:22,935 --> 00:06:25,275 If you make something really neat, be sure to post it on the forums, and 99 00:06:25,275 --> 00:06:26,395 mention me so I can see it. 100 00:06:27,715 --> 00:06:29,395 I'm so proud of you, thanks for learning with me.