Mario exists in a 2D grid. The top-left corner of the grid has an (x,y) co-ordinate of (0,0). Moving right, the x value increases. Moving down, the y value increases.
The grid is 400x400:
Every Mario object has 3 private properties:
At the start of a game, Mario's (x,y) position is always (200,200) and his health is 10.
In the game loop, Mario can jump around. Each jump is counted. Note, the jump count is not a property of Mario, it is just a game variable.
Every time he jumps off the grid, his health decreases by 1. The game ends when his health reaches 0 and the jump count, health and final location are displayed.
Mario is off-grid when:
Design the Mario class. Use private properties ie Data Hiding. Create:
Remember! Accessor methods allow programs to view the contents of an object's private variables.
Mutator methods allow programs to change the values stored in an object's private variables.
We will now create a game. It will have 1 object: a Mario object. In your Main program, construct a Mario object and run your program - hopefully no errors!
Create a variable to store the jump count and set it to 0.
Create a game loop where the game will continue while Mario's health is greater than 0.
Inside the game loop, create 2 random numbers in the range -5 to 405. One will be assigned to Mario's x co-ordinate and the other will be assigned to Mario's y co-ordinate.
In the game loop, after Mario jumps, we need to check his new location. If he is off the grid, we will decrease his health by 1.
In the game loop, after updating Mario's health, let's increase the jump count by 1 and display Mario's current location and health.
Also, when the game loop ends, let's write a line of code to confirm Mario's final location and health value.
Create a game where 2 Mario's are jumping around the grid - they have the same behaviour! The last Mario alive is the winner and his name will be displayed.
Hint: Every Mario now has a new property - a name! Don't forget to create an accessor method for this property. You will also need to redesign the constructor method.