Text-based Game
Project Type: University
Software/Language Used: Visual Studio / C++
Conquer is a text-based Stratagy game where the player gathers resources, develops an army and then battles an opponent in turn-based combat.
I developed a system for managing unit and army information. Using two structs I could create units that have different stats (Attack, Defence, etc.) and information on special traits and unlocked status, while having a second struct that stores the quantitys of units in a given army aswell as base health and stat boosts.
The code below shows the structs used.
For combat to take place over multiple lanes (rows and columns) I created a unit class and made 5 arrays of this class to represent the lanes. Each Lane has the player base side (Blue), battle field spaces (white) and the enemy base side (red). Units appear in their sides colours (player units appear blue, etc.)
This class contains all the basic information about a unit, bools for whether it is active or not and strings for names (to trigger specific effects) and alligences that can all be read during combat. It also contains functions to allow the unit to move forward (by swaping), take damage and be defeated (reseting the unit to blank).
The code below shows the Swap and Defeat functions.
Units are placed using pointers. When the player or enemy places a unit, the lane and type are passed through to a function with then finds the lane (and correct column) and Swaps the blank data in that unit class for that of the unit being placed.
Combat is then looped through, with unit placement and then activation, starting with the player. This cycle repeats until a side has lost all their base health. During placement and activation, the battlefield is updated to display each change made.
The code below shows the Combat loop.
The code below shows the Display Updating.
The code below shows the Display Updating.
To add variety to each week of the game, I created randomised events that would give the player choices on how to proceed. For example, trading workers for garanteed higher profit or drinking a potion with a potential good or bad effect.
The code below shows Events.
There are also Mid-Week events that grant benefits to the player.
The code below shows Mid-Week Events.
At the start of the week the player sends their workers to 3 locations, each having their own risk and profit. This is handled using a function that is given an upper-limit, ensuring players cannot place more units than they have.
The code below shows Worker Assignment.
At the end of the week, income is calculated by generating a random number and comparing it to the chance of success for each location. The player then can spend their income on units they have access too, checked using a list containing the abbreviated units.
The player can also print out a list of the units they have acess to with their stats and effects.
The code below shows Unit Purchase.
To create a smooth expirience I added function to clear the screen and to print text gradually.
For each week I wanted to introduce the enemy faction to the player, so I added code to open txt files and read them using the text output at the start of each week.
The code below shows code for reading in txt files.
I also made code for reading in player input for string and integer inputs, as the game requires this often.
If you want to message me, please do so here: coreygfives@gmail.com, I'll be sure to respond as quick as possible!