When I was working for McKee Foods Corporation, I found it useful to teach myself Visual Basic for Excel. As such, I started a project, utilizing this project to teach myself Visual Basic. As someone who is a fan of Rogue and Rogue-likes in general, I decided to make my own take on the classic rogue-like formula.
This project took the form of a room, which was generated via a script according to a random selection of three different rooms. This room would be drawn using macros according to a random range of values. The three rooms were either a square room, a plus-shaped room, or a square room with a concave corner in one of the random corners. The player would be positioned at one side of the room with the door positioned on the other side in the wall. The goal of the game would be for the player to traverse these rooms, each scattered with monsters and chests, as deep as he could go before finally succumbing to the dungeon.
The gameplay itself consisted of using four buttons which would move your character in the four cardinal directions. Upon moving, the program would detect if and what was in front of the player and how to react accordingly. It would then iterate through any monsters that were left living, allowing them to act with a primitive AI.
Three monsters were in the game and would appear at random. The first I created was a simple ooze. This monster was the most common and would very stupidly march towards the player, getting caught on corners or other obstacles such as chests. For the next monster I added an ogre, which had more health and was smarter. The ogre could navigate around simple obstacles by using a very simple pathfinding algorithm that would walk towards the player. If there was an obstacle, it would determine the direction of the obstacle and begin searching for a way to move beyond it in one direction. If it ran into another wall, it would search in the opposite direction. While unable to solve a maze, it suited my purposes for the game. Lastly, I added a final monster, the goblin. The goblin was weaker than both the ooze and the ogre. As such, this monster would detect the weapon that the player had and its health and, depending upon those values, determine whether to run from the player or not. It utilized the same pathfinder AI as the ogre.
Beyond these features, the game also featured a score and the ability to find a health potion or a sword to upgrade your weapon.
I worked on this project for several months in my spare time, adding various features and learning about Visual Basic. Sadly, the file is lost due to a mistake in backing up my files which resulted in several lost files. I would like to remake the game at one point in the future, but I have not yet had the time.
If and when I do remake it, I have learned the following lessons from my initial endeavor. First of all, any snippet of code that is used more than once, especially if I will add to it frequently, must be a function. My collision was handled as part of the movement code that was called by each of the buttons moving in the four cardinal directions. As such, when I wanted to add a new feature, such as a new monster, I would have to add it four times with its logic being copy pasted to each of the four directions. This means that adding such new features was unwieldy with bugs creeping in due to discrepencies between the four directions. I would actually apply this knowledge to my version of 2048 for machine learning, with the movement being a single function taking as input the direction of the movement to ensure that the movement function would not run into these same issues.
This same lesson also applied to how I dealt with the monsters as each monster had its own script which reused a large amount of code. Combining these into a function that deals with monsters more generally, especially pathfinding, would have created a much cleaner and easier to edit code base.
Another lesson I learned, was that I was really majoring in the minors. Creating a plus-shaped room consumed almost a month as I struggled with the math to ensure that monsters and items did not generate outside of the walls. However, it seems to me that by using corridors to string together a variable amount of much simpler geometric shapes, I could have finished with the map generation earlier, as well as created a more enjoyable experience.