Assignment 4B – C++ – Lucky 7
Posted by Andrew Wegener on 10th October 2012
This is my first experience touching the C++ language. Overwhelming while reading the chapters, but slightly more comprehensive once it became hands-on. For this assignment, I wanted to create a short minigame from Mario Party 3. Since my arrival in Hong Kong, my group of friends and I play Mario Party a couple times a week, so I thought this fit in well. The game is simple – here is a screenshot of the instructions.
Basically, roll the dice, once or twice (rhyme!), and finish equal to or higher than the computer without falling off the staircase.
First, I needed a random number generator. Here’s how to do that.
This says “I can pick a random number!” (above)
This is a nifty little formula to imitate rolling a die. Melissa helped our class understand this. So, someNumber = the random number (anything between + or – a “gazillion” (quoting Professor Rueda)). diceRoll will equal the [huge random number "modulus" 6] + 1 . Modulus was a new term for me. Simply put, it the remainder of the division of the following number. For example, if the huge random number is 34821, mod (short for modulus) by 6. To start, divide 34821 by 6. The answer is 5803.5 . OR 5803 with a remainder of 3. Therefore, 34821 % 6 = 3. Some smart people figured out that dividing any integer by 6 will always have a remainder of 0-5, so, if you add 1 (like the formula does) you will always get a number 1-6 aka a dice roll. Like Pikachu on toast. Swag.
So let’s get started, first, I needed a game board to show the progress of the player and computer. Rather than figuring the roughly 72 possibilities of where each player could be located, I can call on a function! Check it out (below – click to enlarge this one)
It’s simply a series of If statements saying “if computer is here, and player is (or isn’t) here, show the player piece on this step”. All it had to do is use the inputs of the computer’s height and the player’s height which are stored in global variables.
Now that rolling works, I wanted the computer to “cheat”. Okay, yes it cheats – no quotation marks. But not to the point that it always wins. Here’s what I mean (below).
This says ” if it’s the computer’s (I call it Nemesis for no reason) second turn only, add it’s current height to the dice roll. If it’s more than 7 (if it would fall off the staircase), say “I pass this turn.” and pretend it never rolled.” This just means that the computer will never fall off the stairs but will always make use of it’s highest possible score. So if the total is less than 7, it will state the roll and still move.
That basically sums it up. Unfortunately, I’m not allowed to post my game for security reasons. Lame. This is not Pikachu on toast. Oh well! Play Mario Party 3 and play the Game Guy game Lucky 7!
Yay! I win!
Posted in C++ Game, C++ Programming | 1 Comment »





