Skip to content

Instantly share code, notes, and snippets.

@jonurry
Created March 27, 2018 13:11
Show Gist options
  • Save jonurry/590dab555331ac34f12fe2449b9f1643 to your computer and use it in GitHub Desktop.
Save jonurry/590dab555331ac34f12fe2449b9f1643 to your computer and use it in GitHub Desktop.
16.1 Project: A Platform Game (Eloquent JavaScript Solutions)
<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>
@jonurry
Copy link
Author

jonurry commented Mar 27, 2018

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 (using console.log) every time a level starts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment