<commit_before>var $ = require('jquery');

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

var Enemy = require("./enemies.js");
var Bluecifer = require('./bluecifer');

var themeSong = document.getElementById("theme-song");
var celebration = document.getElementById("celebration");

// var enemy = new Enemy();

var scoreCounter = 0;
var enemies = [];

function Game() {
  this.canvas = canvas;
  this.ctx = this.canvas.getContext('2d')
  this.bluecifer = new Bluecifer (150, 150, 50, 41);
  this.enemy = new Enemy();
  this.active = true;
  this.enemies = enemies;
}

Game.prototype.repeat = function() {
    this.clearCanvas();
    this.bluecifer.draw(this.ctx);
    this.bluecifer.gravity();
    this.createNewEnemies();
    this.drawNewEnemy(this.ctx);
    this.detectFloorCollision();
    this.keepScore();
}

Game.prototype.clearCanvas = function() {
  this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
}

Game.prototype.bluecifer = function() {
  this.bluecifer.draw(this.ctx);
}

Game.prototype.blueciferGravity = function() {
  this.bluecifer.gravity();
}

Game.prototype.createNewEnemies = function() {
if (scoreCounter % 50 === 0){
  if (this.enemies.length < 5){
    this.enemies.push(enemy);
  }
}
}

Game.prototype.drawNewEnemy = function() {
  enemies.forEach(function(enemy) {
    debugger;
    enemy.draw(this.ctx);
    this.collision(enemy, this.bluecifer);
    this.enemy.moveLeftRandom();
  });
}

//airplane collistion
Game.prototype.collision = function(a, b) {
  if (((a.y + a.height) < (b.y)) || (a.y > (b.y + b.height)) || ((a.x + a.width) < b.x) || (a.x > (b.x + b.width)) || collisionCanHappen === false) {
  //if there is no collision
  }
  else {
    // themeSong.pause();
    youAreDead();
    $('#game-over').css('visibility', 'visible')
    this.resetGame();
  }
}

//ceiling collision
Game.prototype.detectCeilingCollision = function() {
  if (this.bluecifer.y < 0) {
    this.bluecifer.y = this.bluecifer.y + 20;
  }
}

Game.prototype.detectFloorCollision = function() {
  if (this.bluecifer.y > 350) {
    // themeSong.pause();
    this.resetGame();
    this.youAreDead();
    this.bluecifer.y = 300;
  }
}

Game.prototype.airportCollision = function(a, b) {
  if (((a.y + a.height) < (b.y)) || (a.y > (b.y + b.height)) || ((a.x + a.width) < b.x) || (a.x > (b.x + b.width))) {
  //if there is no collision
  }
  else {
    // themeSong.pause();
    // celebration.play();
    $("#message-center").text("You win! Your score was " + scoreCounter);
    bluecifer.y = 1000;
    setTimeout(function() {
      resetGame();
    }, 3000);
  }
};

Game.prototype.resetGame = function() {
  location.reload();
  $('start-game').css('visibility', 'hidden');
  $('game-over').css('visibility', 'hidden');
  this.repeat();
}

Game.prototype.keepScore = function() {
  var currentScore = scoreCounter++;
  if (currentScore <= 100){
    $('#game-score').text("000" + currentScore);
  } else if (currentScore <= 1000){
    $('#game-score').text("00" + currentScore);
  } else if (currentScore <= 10000){
    $('#game-score').text("0" + currentScore);
    // drawAirport();
  } else {
    $('#game-score').text(currentScore);
  }
}

Game.prototype.youAreDead = function() {
  $('#game-over').css('visibility', 'visible');
  this.stop();
}



module.exports = Game;<commit_msg>working on refactoring the create new enemy functions in game.js<commit_after>var $ = require('jquery');

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

var Enemy = require("./enemies.js");
var Bluecifer = require('./bluecifer');

var themeSong = document.getElementById("theme-song");
var celebration = document.getElementById("celebration");

// var enemy = new Enemy();

var scoreCounter = 0;
var enemies = [];

function Game() {
  this.canvas = canvas;
  this.ctx = this.canvas.getContext('2d')
  this.bluecifer = new Bluecifer (150, 150, 50, 41);
  this.enemy = new Enemy();
  this.active = true;
  this.enemies = enemies;
}

Game.prototype.repeat = function() {
    this.clearCanvas();
    this.bluecifer.draw(this.ctx);
    this.bluecifer.gravity();
    this.createNewEnemies();
    this.drawNewEnemy(this.ctx);
    this.detectFloorCollision();
    this.keepScore();
}

Game.prototype.clearCanvas = function() {
  this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
}

Game.prototype.bluecifer = function() {
  this.bluecifer.draw(this.ctx);
}

Game.prototype.blueciferGravity = function() {
  this.bluecifer.gravity();
}

Game.prototype.createNewEnemies = function() {
if (scoreCounter % 50 === 0){
  if (this.enemies.length < 5){
    this.enemies.push(enemy);
  }
}
}

Game.prototype.drawNewEnemy = function() {
  enemies.forEach(function(enemy) {
    debugger;
    enemy.draw(this.ctx);
    this.collision(enemy, this.bluecifer);
    this.enemy.moveLeftRandom();
  });
}


//collision functions below. Refactor these late to be in their own file
//airplane collistion
Game.prototype.collision = function(a, b) {
  if (((a.y + a.height) < (b.y)) || (a.y > (b.y + b.height)) || ((a.x + a.width) < b.x) || (a.x > (b.x + b.width)) || collisionCanHappen === false) {
  //if there is no collision
  }
  else {
    // themeSong.pause();
    youAreDead();
    $('#game-over').css('visibility', 'visible')
    this.resetGame();
  }
}

//ceiling collision
Game.prototype.detectCeilingCollision = function() {
  if (this.bluecifer.y < 0) {
    this.bluecifer.y = this.bluecifer.y + 20;
  }
}

Game.prototype.detectFloorCollision = function() {
  if (this.bluecifer.y > 350) {
    // themeSong.pause();
    this.resetGame();
    this.youAreDead();
    this.bluecifer.y = 300;
  }
}

Game.prototype.airportCollision = function(a, b) {
  if (((a.y + a.height) < (b.y)) || (a.y > (b.y + b.height)) || ((a.x + a.width) < b.x) || (a.x > (b.x + b.width))) {
  //if there is no collision
  }
  else {
    // themeSong.pause();
    // celebration.play();
    $("#message-center").text("You win! Your score was " + scoreCounter);
    bluecifer.y = 1000;
    setTimeout(function() {
      resetGame();
    }, 3000);
  }
};





Game.prototype.resetGame = function() {
  location.reload();
  $('start-game').css('visibility', 'hidden');
  $('game-over').css('visibility', 'hidden');
  this.repeat();
}

Game.prototype.keepScore = function() {
  var currentScore = scoreCounter++;
  if (currentScore <= 100){
    $('#game-score').text("000" + currentScore);
  } else if (currentScore <= 1000){
    $('#game-score').text("00" + currentScore);
  } else if (currentScore <= 10000){
    $('#game-score').text("0" + currentScore);
    // drawAirport();
  } else {
    $('#game-score').text(currentScore);
  }
}

Game.prototype.youAreDead = function() {
  $('#game-over').css('visibility', 'visible');
  this.stop();
}



module.exports = Game;
{'fraction_non_alphanumeric': 0.19416336706261916, 'fraction_numerical': 0.01583809942806863, 'mean_word_length': 3.5195493704440026, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '45267', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2395, 'n_words': 448}