{"size": 1572, "ext": "js", "max_stars_repo_path": "states/game_over_state.js", "max_stars_repo_name": "fahseltc/SUPER-STARKILLER-3000", "max_stars_repo_stars_event_min_datetime": "2018-08-23T12:45:31.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-07T21:40:27.000Z", "max_issues_repo_path": "states/game_over_state.js", "max_issues_repo_name": "fahseltc/SUPER-STARKILLER-3000", "max_issues_repo_issues_event_min_datetime": "2018-03-01T04:29:00.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-11T02:54:51.000Z", "max_forks_repo_path": "states/game_over_state.js", "max_forks_repo_name": "fahseltc/phaser-space-game", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 5, "max_forks_count": null, "avg_line_length": 25.3548387097, "max_line_length": 78, "alphanum_fraction": 0.5928753181}
var game_over_state = {
  create: function() {
    game.stage.backgroundColor = BLACK_HEX_COLOR;

    Utils.create_centered_text(
      "SYSTEM MALFUNCTION\n\nSIGNAL LOST",
      200,
      70,
      RED_HEX_COLOR
    );
    Utils.create_centered_text("SCORE: " + GLOBAL_SCORE, 500, 50);
    var submit_score_button = Utils.create_button(
      game.width / 2,
      765,
      "SUBMIT SCORE",
      this.send_score,
      1.5
    );
    var play_again_button = Utils.create_button(
      game.width / 2,
      850,
      "MAIN MENU",
      function() {
        GLOBAL_SCORE = 0;
        game.state.start("menu");
      },
      1.5
    );
  },

  send_score: function() {
    var player_name = prompt("Enter your name", "");
    if (!player_name) {
      alert("Enter a name");
      return;
    }

    var spinner = game.add.sprite(700, 450, "spinner");
    spinner.scale.x = 3;
    spinner.scale.y = 3;
    spinner.anchor.set(0.5);
    spinner.visible = true;
    game.add.tween(spinner).to({ angle: 359 }, 1500, null, true, 0, Infinity);

    var body = "name=" + player_name + "&score=" + GLOBAL_SCORE;
    var request = new XMLHttpRequest();
    request.open("POST", game.config.backend_url + "/leaderboard", true);
    request.setRequestHeader(
      "Content-Type",
      "application/x-www-form-urlencoded; charset=UTF-8"
    );
    request.onload = function() {
      GLOBAL_SCORE = 0;
      game.state.start("leaderboard");
    };
    request.onerror = function() {
      console.log(request.responseText);
    }; // failure case
    request.send(body);
  }

};