Created
March 27, 2018 13:11
-
-
Save jonurry/590dab555331ac34f12fe2449b9f1643 to your computer and use it in GitHub Desktop.
16.1 Project: A Platform Game (Eloquent JavaScript Solutions)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" href="css/game.css"> | |
<body> | |
<script> | |
// The old runGame function. Modify it... | |
async function runGame(plans, Display) { | |
let lives = 3; | |
for (let level = 0; level < plans.length;) { | |
console.log('lives:', lives); | |
let status = await runLevel(new Level(plans[level]), | |
Display); | |
if (status == "won") { | |
level++; | |
} else { | |
lives -= 1; | |
if (lives === 0) { | |
break; | |
} | |
} | |
} | |
if (lives > 0) { | |
console.log("You've won!"); | |
} else { | |
console.log("You're dead!"); | |
} | |
} | |
runGame(GAME_LEVELS, DOMDisplay); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Project: A Platform Game
16.1 Game Over
It’s traditional for platform games to have the player start with a limited number of lives and subtract one life each time they die. When the player is out of lives, the game restarts from the beginning.
Adjust
runGame
to implement lives. Have the player start with three. Output the current amount of lives (usingconsole.log
) every time a level starts.