Your objective for this project is to work on several classes to construct a game called CSnowman. It is the politically correct version for "Hangman" with the same rules. You'll have eight (8) tries to guess the correct word/phrase. For every incorrect guess, a body part of the snowman will be drawn. Now how will the game be constructed and what classes are we going to make in order for the game to work.

Fortunately, you won't need to construct the entire project yourself as I created a starter kit called CSnowmanStarterKit.tar.gz. The starter kit is located in your Project_CSnowman folder. The starter kit includes 11 files: main.cpp, CPlayer.h, CPlayer.cpp, CSnowmanGame.h, CSnowmanGame.cpp, CWords.h, CWords.cpp, IntToCString.h, IntToCString.o, ListOfMarvelCharacters.txt, and SampleExecutable.out. Your objective is to implement all the .cpp files only. The headers file and main.cpp have been completed for you.

The description of the files below is the recommended order you should work on them.

1. CWords Class - I recommend that you get the class below to run on its own before you proceed to the next phase. Create a temporary main.cpp to test the features of your class.

  • CWords.h -- This header file contains the declaration for the CWords class. This class is used to read and store locally the words/lines in a file and randomly select a word.
  • CWords.cpp - This is the implementation file of CWords.h. The file is filled with function headers with comments/descriptions to guide you in the implementation. As a note, you'll need to use the libraries cstdlib and ctime to for the functions srand, time, and rand. Youll need to seed the random function with the current time to make sure each run is unique. To set it youll use the code srand(time(NULL)). To obtain a random number after you seeded the random function is call the function rand. Be sure to do your research on what the random function returns. (Hint: Youll be using the modulus operator to get the range you like).

2. CSnowmanGame Class - This class contains the entire structure of the game and will take the majority of your time. Perhaps, it may be best to go to step 3 and do CPlayer class before implementing this class.

  • CSnowmanGame.h - This header file contains the declaration for the CSnowmanGame class. This class includes the header file CWords.h. It contains four global constants with the explanations below:
    • NUM_TRIES: The number of tries to give the user
    • NUM_ALPHA_CHARS: The number of alphabetical characters
    • SCREEN_DIM: The dimension of the screen to center the titles
    • SLEEP_NUM_SNOWMAN: The number of seconds for the program to sleep when displaying a message to the user. This will give them some time to read the message before proceeding to the next statement.
  • The class contains three (3) public functions: the default constructor, Start, and Reset. The constructor initializes the game. The Start function begins the game and the Reset functions reset the game environment should the player decide to play again after winning or losing.
  • The class has eight (8) private data members.
    • m_numTries: The number of tries to give the user
    • m_wordToGuess: A char array to store the word to guess
    • m_letterGuessed: A bool array that stores true/false whether each letter was guessed correctly based on the position of the array. Element zero (0) represents the letter A and element 25 represents the letter Z.
    • m_lettersInWord: A bool array that stores true/false whether each letter exists in the word.
    • m_wordLen: The length of the random word selected
    • m_guessedWord: A bool to represent whether the random word was guessed correctly or not.
    • m_numUniqueLetters: An int that represents the number of unique letters in the random word selected.
    • m_words: A CWords object used to read items in a file and randomly select a word/phrase.
  • The class contains 17 private member functions. These functions cannot be called outside of the class. Only public member functions have access to call the private member functions. The explanation of each function is given in the implementation file.
  • CSnowmanGame.cpp - This is the implementation file of CSnowmanGame.h. The file is filled with function headers with comments/descriptions to guide you in the implementation. As a note, you'll use the sleep function described in step One (1) to sleep the program for SLEEP_NUM_SNOWMAN seconds to display the appropriate message when needed. Ive left some functions fully implemented for you to use to save you time and research in this project. Furthermore, Ive included my own header file called "IntToCStringLib.h" should you want to convert an integer to a CString. Ill note how youll compile it in a later section.

3. CPlayer Class -- This class contains the class CPlayer that will initiate to play the game. It may be easier to start the implementation of this class before step two (2).

  • CPlayer.h -- This header file contains the declaration for the CPlayer class. This class includes the header file CSnowmanGame.h. It contains a global constant with for the sleep function so the game "sleeps" or pauses for SLEEP_NUM_PLAYER seconds to simulate the game is loading. The class has two constructors and a destructor. Furthermore, it has three private data members. One is a char pointer to store dynamically the player's name. The second is a bool to know if the game was reset. Lastly, a CSnowmanGame object called m_game, use to start the game. The class header contains public member functions to Start and Reset the game.
  • CPlayer.cpp -- This is the implementation file of CPlayer.h. The file is filled with function headers with comments/descriptions to guide you in the implementation.

4. Main.cpp - Contains a fully implemented function to use with all the classes.

5. ListOfMarvelCharacters.txt - Contains a listing of 1253 words/phrases separated by newlines. This file will be used to be read by the CWords class.

6. IntToCStringLib - This contains the header and implementation for two functions to convert an int to a CString. You don't need to use this, but I included it in case you want to convert an int to a CString.

  • IntToCStringLib.h - A header file that contains the function prototypes of the two functions and a description of how to use them.
  • IntToCStringLib.o - An object file of the two functions. This file has already been compiled (to keep hidden the implementation of the two functions). If you are going to use the functions, you don't need to compile it, but simply use the linker to link it to your executable file.

7. SampleExecutable.out -- This is a sample executable for you to see and play with the game/program. Your program should mimic the executable file. To run it: ./SampleExecutable.out

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.