This is another small command line game I created in C++
• Solo • 8 Weeks • Command Line • C++
This is a small game where you buy items and then earn money per few seconds. This game also includes a high score, this is because I wanted to expand my C++ knowledge.
This task counts the time you were in the game, allowing for stats for the user so it gives them a reason to play for more time. This also allows me to check the game time, so I have an internal counter counting up each second so if I need it to run something every so often I can do that.
This function allows me to "Buy Items" this creates an item selection with a custom function I made. This function allows me to give key and values, so I could find them and know which one I brought. I also have my own custom convert to currency function to make the int into a formatted currency value with commas. If you wanted to buy something you would enter the name of what you wanted to buy, and then I would check in the selection function if it existed, if not it will ask you again. If it existed then it would exit out and return the value you chose, and then it could go through and check if you had enough cash. If so it would remove that from your wallet in the game info. I then add the item to the inventory and then ask if they want to exit if you say yes it will go to the while loop that is a "do while" so the code is executed first then evaluated. This allows it to stay in a loop.
This is a function that allows the user to see their own high score if they have one. What this does is it checks if the file exists if it does not then it will tell the user, if it does exist then it will try to open the file and get the line of the score. It then will print the game header and then checks if the file exists again and tries to convert it to an int. It also decrypts the file so the saved file is more secure and the player can't change the variable. I created a very simple encrypt for this using the most basic function.
This encryption is very simple but what it does is it gets a random seed for the encryption which is 5 and then for each character it gets the character adds the random and then mods 25. This will make the character a random character. It will work on numbers as they are above 25 for the character value. Anything with an ASCI code below 25 won't work but this is hopefully avoided by adding the random number.
Very simple decrypter as it does the same but in reverse. This is just a prototype and a basic attempt at this. But I got it to function and the concept is there.
This command line game was made in C++. This allowed me to learn some more of C++ and it helped me learn about some other library's.
You can download and test out the program yourself
Download