Conquer


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.

Unit Structs and Army Pool

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.

Struct Code Snippet

Combat Structure

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.)


Combat Grid Display
Unit Class Code


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.

Unit Class Swap Code Snippet

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.


Unit Placement 1 Unit Placement 2

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.

Combat Loop Code Snippet

The code below shows the Display Updating.

Display Updating Code Snippet 1

The code below shows the Display Updating.

Display Updating Code Snippet 1 Display Updating Code Snippet 2

Weekly Randomised Events

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.


Chest Event Miner Event Witch Event

The code below shows Events.

Event Code Snippet

There are also Mid-Week events that grant benefits to the player.


Chest Event

The code below shows Mid-Week Events.

Merchant Event

Generating Money

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.


Worker Assignment

The code below shows Worker Assignment.

Worker Assignment Code Snippet

Purchasing Units

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.


Unit Purchase

The player can also print out a list of the units they have acess to with their stats and effects.


Unit Purchase 2

The code below shows Unit Purchase.

Unit Purchase Code Snippet

Other

To create a smooth expirience I added function to clear the screen and to print text gradually.


Erasing Lines Code
Text Output Code

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.

Reading txt files Code Snippet Narrative Text

I also made code for reading in player input for string and integer inputs, as the game requires this often.


Input Check Code

Contact

If you want to message me, please do so here: coreygfives@gmail.com, I'll be sure to respond as quick as possible!