The Princess Is In Another Castle
Requirements:
-
Create a class for a player that has the following properties:
-
name
of typeString
-
totalCoins
of typeNumber
-
status
of typeString
(options arePowered Up
,Big
,Small
, andDead
) -
hasStar
of typeBoolean
(Is a star active?) -
setName
of typefunction
- Has a parameter callednamePicked
where you pass in "Mario" or "Luigi". Setsname
to "Mario" or "Luigi". -
gotHit
of typefunction
- this is called whenever the player is hit by an enemy.gotHit()
will set thestatus
property accordingly. (Statuses go from "Powered Up" to "Big" to "Small" to "Dead".) -
gotPowerup
of typefunction
- called when a powerup is received and sets the status accordingly. (Statuses go from "Small" to "Big" to "Powered Up". If you are Powered Up and it hits this function, you get a star) -
gameActive
of typeBoolean
, true by default, becomes false whenstatus
is Dead -
addCoin
offunction
- adds a coin to totalCoins -
print
of typefunction
- prints to the console the name, totalCoins, status, and star properties. Make sure you make this look nice such as:- Name: Luigi,
- Status: Small, etc, etc
Use that class to create the object.
Create a random range function that returns either 0, 1, or 2.
If the value is 0 call the gotHit()
function on the object.
If the value is 1 call the gotPowerup()
function on the object
If the value is 2 call the addCoin()
function
Then call the print method on the object.
Now put the random range function inside a setInterval
function that ends after gameActive === false
The end product will look something like this: