Pass 1
Step by step
I want to write this code step by step simulating a little the way I would write it if I were writing it from scratch. So not just copy it from top to bottom, instead I will start with a minimum working version and then make it grow from there.
What I'm thinking is: start with the first room and the character and the functions I might need to just make that work, like the main function and main loop; so I can run a bare-bones version of the game even if it doesn't do anything at first, then step by step add more rooms, more functionality and aesthetics.
I know it is still somewhat artificial because I'm only copying part by part, except I'm not doing it linearly.But helps me see more clearly not just what the "end product" looks like in the end, how it works and and the process of how it's built.
1
Initially I only need about 50 lines to run the bare bones program, including:
- the
dungeon_mapdictionary with the first room - the
playerdictionary display_room()function
Obviously, when you run it like this not much happens, it just displays the room info. But that's the point.
2
I want to add now a basic game loop where it displays the player stats and waits for an input before printing it again, instead of just running the program and exiting. So all I need to do is:
- add the
show_stats() - the
whileloop, and inside the loop:- the call to
show_stats() - the
try:line with the call for aninput() - the
except:block at the end of the while loop.
- the call to
Now I can run the game loop and press Enter and that's it.
3
For the next step I'll continue with next few lines in the while loop and see what else they connect to.
- First I started by testing the basic functionality so I added the
ifblock with the condition to quit. - next I'll start adding the
elif's with the other condictions, but for that I need to write theshow_help()andshow_inventory()functions. - finally in this step, I write the
take_item()function so I can grab the torch in the first room and theshow_inventory()has something to show.
4
In step 4 I will add the movement and complete the map (the rooms dictionary)
- I start by writing the
move(direction)function plus only one new room to test it. And I also need to add theelif action == "go" or action == "move":block in the main loop. - once I make sure that works, I proceed to copy the rest of the rooms.
- make sure the
show_room()function is complete.
5
In step 4 I'll add the fight functionality and the goblin battle
- add the call to the
fight_monster()in the main loop - then write the corresponding function
- or viceversa might make more sense.
6
Finally, add the end-game functionality and final decorations.
- add
check_win()andgame_over()functions and alsoprint_slow()which I had left behind. - double check everything is complete, everything works, test the game, fix bugs.
Ideas
I have a few ideas that I might add to the game, I'll leave them here as a "challenge" for the near future:
- add more rooms
- add music - check if mpv is installed, if yes, then play on background some spooky sounding soundrack in a loop
- add more items
- add a graphical map that you can print with a command and see which rooms you have explored
- add some conditionals to the battle: if has sword, deals more damage than if has only torch; if has shield, recieves less damage.
- fix the fight sequence, make sure it warns first about "something guards them" and then the fight, otherwise the fight happens before you get the description. Makes no sense.
- Modify
take_item()function so that it detects a subset of the name, so you can typetake keyinstead oftake rusty_key.