itch.io is community of indie game creators and players

Entry #7 UP2212859

Following on from my previous entry (Entry #6), I made a console mini game using all the knowledge I've accumulated.  It's nothing special, but it was fun and engaging to make and gave me a challenge.  It was a useful activity as I finally got to try out some switch case statements which are useful to restrict player input to a console.  Forcing the player to abide by the rules the developer intended the player to follow.

I made a simple treasure game that prints out the players location (coordinates) and they can move around until they find buried treasure, hidden at specific coordinates.

As you saw in my last entry, this code is far more optimised compared to my previous code.  I learned that you could use "and" to extend conditionals and use "|" as an or operator to extend my if statement and prevent me from having to type out three more if statements.

I started off initialising two integer variables acting as the player's X & Y coordinates and then initialised a character variable so that player's could input a character to use as a control scheme later on in my code.  I used a while loop to set the playable conditions and then an if statement to warn the player if they're in imminent danger.  Below that is just a simple explanation of what they have to do and the control scheme they have to follow to make their character move!

Below all that I set the win and loss conditions for my code!

Again, I used an if statement and set the buried treasure's coordinates.  So when the player eventually hits those coordinates they'll get their congratulations and the console will quit due to me adding "return 0;" which quits the console.

The console above displays that all my directions work and print new coordinates.

Above displays the output of the player's death.

Finally, the above image depicts the console's win screen.  It's unfortunately, not very flashy, but it was a fun little mini game to code and work out how to make everything work!  The switch case was a highlight for me as it was my first time actually using one in practical code.  It also helped me learn how important ascii values are when writing physical code.

This activity taught me how to optimise my conditional statements by using and operators and or operators, as well as increase my knowledge on switch case statements.  These are both incredibly important skills to have as optimised code takes up less memory which is very important for optimising video games due to file sizes of triple AAA games being so large nowadays!  Switch cases are also important as I assume they're how game dev's create the controls for their games.