C++ Projects

C++ ProjectsHangman exe

Programmer (C++)

Software: Visual Studio
Role: Programmer (C++)
Project Timeframe: January 2016

While serving as an AI Designer/Scripter intern at Avalanche Studios in Stockholm, I made small games in C++ during my free time. My main objective was to improve my programming skills.


I made Hangman in C++ to re-familiarize myself with C++ since, at the time of starting this project, I had most recently used C# in Unity and C++ in Unreal 4.


I decided to go beyond the core mechanics of Hangman and learn how to use localized game strings in code, as well as string IDs for different functions. This allows the user to set their desired language, word category (i.e. animal, food), and difficulty level.

– stdafx.h: I kept global enums and includes in the stdafx.h file, since I knew I would need to use items like strings across my .cpp files. I also knew I would need to access general settings in all files, such as the player’s chosen language, word category, and difficulty level:

stdafx header enums
In addition to the Main.cpp file, I included 4 additional files:

– Gameboard.h: Resets gameboard. Draws gameboard. Sets current word. Checks if letters in word are correct.

– PlayerSettings.h: Data structure to store all information pertaining to player settings.

– Hangman.h: Handles the core game loop.

– Library.h: Reads the stringtable file with the library of localized words. Creates an array for each word category. Stores words into their category array based on string ID. Selects random string in given category (for specified language).

Hangman - Gameboard header

Hangman - Hangman header

Hangman - PlayerSettings header

Hangman - Library header

The following functions in the Gameboard.cpp file reset the gameboard, draw the board with an underscore (“_”) for each letter in the current word, and set the current word.

Hangman - Gameboard cpp 1

In order to return multiple types of information to Hangman.cpp, my mentor recommended using a struct, storing data such as whether the word is correct, the guess is correct, and the number of correct letters.

hangman - gameboard header file - struct

I returned the information from this struct so it could be used in the Hangman.cpp file.

– guessData.wordIsCorrect is used for the player win condition.
– guessData.guessIsCorrect is used to decrease the number of tries the player has left (if the player still has tries left, otherwise the player lose condition is triggered).
– guessData.numberOfCorrectLetters is used in Gameboard.cpp to return word is correct.

gameboard data struct highlighted

hangman 2 - struct used in CheckIfLettersInWordCorrect function

Since I worked at a game localization company previously (Language Automation, Inc.) and enjoy learning languages, I wanted to incorporate localized strings into my Hangman game. I was also interested in learning how to parse string IDs so I could use them in different ways, such as asking the player for different settings, providing feedback, and passing words into the game for gameplay.

I set up a comma-separated values (.csv) Excel file with string IDs and localized words and programmed the game loop, and then I sought help from a mentor to parse the csv file. He recommended using the commas to find the index of each language and then searching each new line for the word at the selected index and placing those words into an array for the specified language.

Hangman Stringtable

This image shows an overview of how the hangman library works: The first two lines were parsed in order to find the language index and category index. Once those indexes were attained, each additional line could be parsed.

The program scanned each new line for the word of the chosen language (in this case, French) and inserted the string ID (animal_01) and word string (chat) into the myWordLibrary array.
hangman language index example

The below image shows the debugged array – the first array [0] contains each category name (i.e. animal, food, place), and the second array [1] contains the string IDs of that category (i.e. animal array has animal_01, animal_02, animal_03). The following arrays continue in the same way, containing the string IDs for each additional category (the food array contains all of the food string IDs, and the place array contains all of the place string IDs).

array of category arrays

The following images show the complete Library.cpp file. You may skip to the next section “What I Would Change” if you prefer.

hangman - library cpp part 1

hangman - library cpp part 2

hangman - library cpp part 3

hangman - library cpp part 4

What I Would Change:
If I were to expand this project, I would create a more dynamic way of reading this file so new languages could easily be added, mirroring the dynamic system for reading different categories (currently, adding new languages requires updating the Language enum values in the stdafx.h file, as well as the switch case statement in Library.cpp).

I would also include all strings into the localization file, such as user input questions and feedback statements (i.e. “Hey, you there. Stop trying to break my game!”).

This cpp file provides the framework for the hangman game loop:
hangman cpp part 1

hangman cpp part 2

hangman cpp part 3

hangman cpp part 4

hangman cpp part 5

hangman cpp part 6

Leave a Reply

Your email address will not be published. Required fields are marked *