Description
I wanted to improve my C++, so I searched for a tutorial and I came across one for the Hangman game. After completing the tutorial, I wanted to personify the project, so I came up with a math arithmetic game. You win by guessing the correct arithmetic symbol, and to do so, you’ll need to start guessing the digits to figure out how the num1 and num2 is combined to create the total.
Technologies
- C++
- Clion
Timeline
Total time: 3 days
This game took a lot longer than expected. What originally was intended to be few hours of work ended up dragging on for days. I ran into a lot of C++ variable assignment and comparison problems.
For example:
int num1 = '1';
int num2 = 1;
cout << "print " << (num1 == num2);
Returns print 0
which means false. To work around, I needed to write:
int num1 = '1'-'0';
int num2 = 1;
cout << "print " << (num1 == num2);
Learnings
- Taking the extra time to personify a tutorial is well worth the effort and frustration because I learned a lot more.
- Understanding the goal of the project is important. Since I did this project as an exercise, I cared more about whether the game works and gets completed quickly rather than the features it has.
- Making sure to understand why something isn’t working rather than just copying pasting stackOverflow to make the project run is still something I’m trying to get better at.
Improvements
- Taking more time to think about and design the game properly. Even though this game was intended as a quick exercise, not thinking through the game play in the beginning made coding a lot more challenging. Often, I had to refactor and rewrite lots of code because I realize that the design was wrong. As well, there were a lot of ugly code chunks that was repetitive. What ended up being the most troublesome was the type conversion. Due to poor design, I ended up having to refactor int to char to char array to string and vice versa many times.
- The gameplay could be better. Unlike the original hangman, this game relied more on luck. However, since it was intended for practicing C++ more than be an entertaining game, I’m satisfied with the result.
- Bugs. There are several bugs, like the number of guesses it takes to win the game and the how the arithmetic symbols are displayed, that I chose to leave unfixed because I wanted to move on and learn new things.