Dungeon Crawler Retrospective

Intro

The dungeon crawler project is a little HTML game with rules similar to a rogue-like dungeon crawler. In my version, the player must explore the dungeon looking for keys, weapon upgrades, and health potions in order to get to the boss on the third floor. Along the way, the player can fight imps to gain XP and level up thus increasing their abilities to help them beat the final boss.

I themed my dungeon crawler after a dungeon from the classic Legend of Zelda on the NES. I knew I wanted the player to only be able to see one room at a time similar to how dungeons in Legend of Zelda work. I also wanted to add a key and locked door feature to simulate Link needing to find keys to move forward to find the dungeon boss in LoZ.

I used Angular to build this dungeon crawler. However, most of the game logic is just straight JavaScript and TypeScript. Angular provided some organization and a couple lifecycle hooks along with calling the modal windows for the pre-game story and success or failure conditions at the end of the game.

To make the sprites, I used a web app called Piskel.

Code Review

This project could use a lot of refactoring. To date, it's the most complex application I've built. So some of the code is less than clean and efficient. There are several places where multiple loops could be condensed into one. Wall generation being the worst offender. Player movement is a complex switch statment with lots of nested if...else if conditionals to do different things based on what a player collides with when the player presses one of the arrow keys. I think it could be cleaned up considerably. Lots of code could be encapsulated into functions to reduce how much duplicate code exists in it.

At the beginning of this project, I committed the same crime as I had in Game of Life, in that I needed to compare two arrays so I used JSON.stringify() and compared strings. At some point in this project that became problematic in that something that I needed to compare couldn't cleanly be coerced to a string and then back into an array. So I figured out how to make that comparison without stringifying the arrays. That said, I didn't go back through the code I'd already written to remove those stringifys.

Future Improvements

The main logic of the game is greater than 1200 lines of TypeScript. I think I could reduce that by half and not lose functionality with enough refactoring. That is the biggest improvement that I could do for this project. There are a few known bugs and I did have some co-workers play it and give me some nice-to-haves:

  • Add WASD controls rather than just arrow keys for moving the player character.
  • I had run into the key being generated inside the locked room, but I haven't run into it in many playthroughs. Though it may still be possible for the key to be unreachable.
  • If the player kills the boss and the boss kills the player in the same round of attacks, the player will get the victory AND loss modals one after the other.