{"size": 1195, "ext": "js", "max_stars_repo_path": "Chapter16/game_over.js", "max_stars_repo_name": "davefeucht/eloquent-javascript-exercises", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapter16/game_over.js", "max_issues_repo_name": "davefeucht/eloquent-javascript-exercises", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter16/game_over.js", "max_forks_repo_name": "davefeucht/eloquent-javascript-exercises", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.7906976744, "max_line_length": 204, "alphanum_fraction": 0.6435146444}
/*

Chapter 16: 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.

<link rel="stylesheet" href="css/game.css">

<body>
<script>
  // The old runGame function. Modify it...
  async function runGame(plans, Display) {
    for (let level = 0; level < plans.length;) {
      let status = await runLevel(new Level(plans[level]),
                                  Display);
      if (status == "won") level++;
    }
    console.log("You've won!");
  }
  runGame(GAME_LEVELS, DOMDisplay);
</script>
</body>

*/

async function runGame(plans, Display) {
  let lives = 3;
  for (let level = 0; level < plans.length;) {
    console.log(`You have ${lives} lives left`); 
    let status = await runLevel(new Level(plans[level]), Display);
    if (status === "won") {
      level++;
    }
    else {
      lives--;
    }
  }
  console.log("You've won!");
}
runGame(GAME_LEVELS, DOMDisplay);
