Create Your First Project
Start adding your projects to your portfolio. Click on "Manage Projects" to get started
ASCII Adventure
Overview
ASCII Adventure is a text-based adventure I created at the start of my first year.
Project type
Text-based Adventure
Date
November 2024
What I Did
I created a set of functions that let me “draw” ASCII art in the program’s window. I used this to create buttons that can be clicked to interact with the game.
I also created a turn-based combat system where the player controls a party of three characters, each with a regular attack and an ability which has a cooldown. Each party member also has an armour and weapon slot. In combat, the player earns gold for defeating enemies. This gold can be spent at the shop to buy better equipment.
There are several areas, each containing multiple enemies that can spawn.
Finally, there is also a narrator that describes events and the environment throughout the adventure.
How I Did It
The basis of writing ASCII to the window is at the end of the program’s main loop, where an array of characters is printed to the screen. I created ScreenWriter classes to make editing the array easier. The parent ScreenWriter has a function that writes a string into the array. It takes in a string, an integer for the row, and an integer for the inset into the row.
I created child classes for each screen (shop, combat, etc.) and gave them functions to draw their respective pieces – the combat ScreenWriter has functions for the attack and ability buttons. These child classes also have variables that indicate whether their buttons are currently being hovered over, and they draw their outlines differently when they are.
Whether buttons are being hovered over is tracked by a MouseMonitor class, with a monitor for each screen. The parent monitor has a function to get the mouse’s position, and each child checks whether the mouse is hovering over one of its screen’s buttons, updating the screen writer and calling the appropriate function when the player clicks.
The narrator works by using a stack that discards data at the bottom to fit more in at the top. By making the narrator a class (NarratorStack), I was able to include functions for pushing lines onto and reading the stack, which made working with it significantly easier. Then, during the main loop, each line in the stack is read and written in the narrator box.
Combat is run by the combat manager. When combat starts, it will spawn one to three enemies, with the potential enemy types decided by the player’s current location.
On the player’s turn, each party member is given a chance to do something, either attack or use their ability (if it’s off cooldown). After each living member has done something, the enemy turn starts.
On the enemies’ turn, the combat manager loops through each living enemy and has it perform one of its abilities at random. It then pushes descriptions of the enemies’ actions onto the narrator stack.
Each enemy is based on the EnemyParent class, which contains hooks for three attacks, the range of gold it can drop when defeated and a stats struct it shares with the party members, which holds health and damage stats.
The enemy child classes then override two or three of the attack functions, allowing them to adjust targeting and how the damage scales with their damage (e.g. an attack that affects two party members might only deal 75% of attack to each).
The characters in the party inherit from the same Combatant grandparent as the enemies. The CharacterParent class then adds their equipment inventory and overridable functions for their basic attacks and abilities.
What I Would Do Differently
One thing I would potentially do differently is making buttons a class. By doing this, I could let them track whether they’re being hovered over themselves, and assign them functions to call when they are clicked, saving me from repeating a lot of code and making setting up new buttons easier.
Another thing I would do is giving the parent ScreenWriter text and rectangle/shape functions. This would have avoided some repetition and would also help with adding a button class.
The narrator also could probably have been a struct instead of a class, though I don’t think this would have made much of a difference.










%20transparent%202.png)

