Try it out: https://colab.research.google.com/drive/12I-ZFEEjzt6dRUjXNlNHPGqkT9HTQBp_?authuser=0#scrollTo=x5tJeoiCjnPT
Our first assignment in the Fusion 10 class was a freestyle coding project. I set out to make a text-based adventure game. It follows a character who enters the dungeon to get a magic item. But in order to get to the item, they must pass through a number of rooms, with challenges sprinkled throughout.
Before I began to code, I started with a flowchart. This is an essential part of any coding project because it outlines the project, giving you a focused way to work individually on each part of the project until the whole of the project is complete.

This flowchart shows the outline of my game idea. Once I had this written out, it made it much quicker to work on the project itself. The coding was very quick and I just went from one part to another.
The Code
Once I had a general plan from my flowchart, I just coded a part, tested it, fixed it, and went to the next part.
Setting the Stage with Variables

Variables are used to set the state of something. Here, I used the first half of this snippet to set the state of the player.
- Inventory starts empty.
- Health starts at 100 and max_health makes sure it can’t go any higher.
- Gold starts at 0
- Events is a list of the room options: a monster encounter, a lucky chest, a valuable merchant, or a benevolent healing room.
The rest after that is lists of items and monsters. Artifacts are used as the item you look for during a quest. The numbers next to them represent how many rooms you need to clear to find the item. After that, it shows the monster or item and the numbers beside them are the stats.
Talking with the Player

There are three main functions used to communicate with the player.
- The typewriter() function gives the game a more interesting way to it by writing the text in a letter by letter way instead of all at once. This makes the game more immersive.
- The GateKeeper() function is used to keep communication from the gatekeeper consistent.
- The Game() function is used to keep communication about the game consistent. This is mainly description.

The player function is important. This is how to receive input from the player to make the game more interactive. It works by receiving an input of a list of options and then the player chooses which option they would like to say.
Logic Behind the Dungeon Rooms

For the Chest() room, I wanted it to always give a weapon, a potion and a number of coins. To determine the weapon and potion, it chooses a random one out of the list that we defined earlier as a variable.

The HealRoom() brings you closer to max health. After a fight with a monster, this is one way to heal your health to prepare for another fight. It works by saving the old health in a variable, then adding the heals to the old health. If that is more than max_health, then it sets health to max_health, otherwise, it just leaves it.


The Merchant() room is a way for players to buy equipment to keep them better prepared for future fights with monsters. First I define a list of items that you can buy from the merchant. Then, it runs through a loop. It asks what item you would like to buy, then makes sure you have the gold to buy that item. If you do, then it gives it to you and takes away the gold.

The last and most complicated room is the Monster() encounter room. It first types out the stats of both you and the monster then it does the combat in the combat function, which I will get to later. It then goes on to print if the player won, if the monster won, or if it was a stalemate.
The Combat Function

The Combat() function starts by getting the stats of both the player and the monster. Then, it lists out the controls that the player can use. I made combat a turn by turn based fight. The player has the option of all these controls. After the player inputs a move, the monster makes a move and there is a small chance it does a lot of damage.


The code above is how the game understands what key is pressed.
- When “c” is pressed, it shows a list of controls
- When “i” is pressed, it uses a potion on the player to heal
- When “j” is pressed, it does a simple jab. There is a 10% chance of a critical hit.
- When “p” is pressed, it does a power strike. There is a 15% chance of a critical hit.
- When “b” is pressed, it does a block, which negates some damage from the monster.
- When “d” is pressed, there is a small chance that you will completely dodge the attack from the monster.
If you choose the wrong control, it means you hesitate and the monster still hits you.
The Prize Room

When you complete the specified amount of rooms for your artifact, you are taken to the prize room. It adds it to your inventory and then teleports you back to the Dungeon Master.
Game Loop

The game starts by asking the player for their username. Then they are greeted by the Gate Keeper and given their first quest. The game always makes the player go through a chest room then a monster room before starting the random room loop. Then once they go through enough rooms, they are taken to the Prize Room. Finally, they are asked to play again.
Reflection
This project was a fun thing to do. I learned how to use libraries I never really used before that much and it made the game so much more interesting. I made sure not to use AI because I like to use ChatGPT to do all the monotonous parts but I forced myself to write all the text myself, and it made the game that much better to make. It is a simple game but it still was fun to make.
The main thing I learned from this project was the importance of planning before coding. I never really used flowcharts on any of my coding projects but using it genuinely made my job so much easier. I just went from part to part and it was so much faster. I moved so quickly.
It was fun at the end to see how I had made a game where no two games are exactly the same all because of random chance. This is a very simple concept but I never really have used it like this.
AI Transcripts:
https://chatgpt.com/share/68d99155-4e8c-8004-ba9d-9a1ecfc7e132
https://chatgpt.com/share/68d991c0-f690-8004-8e54-8ec11f457181
Leave a Reply to mcrompton Cancel reply