<commit_before>function Game() {
  this.frameIndex = -1; // -1 as 0 needs to be first index
  this.currentFrameObject = null; // this will be refreshed every frame to the newly created Frame
  this.scoreSheet = []; //[Frame, Frame] stores individual frames
  this.totalScore = 0; // is this needed? if so -- does it belong in Frame?
  this.isGameOver = false;
  this.strikeCount = 0;
}

Game.prototype.rollBall = function(pinsKnocked) {
  this.logRoll(pinsKnocked);
};

Game.prototype.logRoll = function(pinsKnocked) {

  if (this.isGameOver == true) {
    fail('Game Over, please reset the game');
  }

  if (this.currentFrameObject == null) {
    this.currentFrameObject = new Frame(); //create the frame object for every new frame(round)
    this.frameIndex += 1;//
  }

  if (this.currentFrameObject.rollIndex == 0) { //if its on its first roll:
    this.currentFrameObject.firstRoll(pinsKnocked); //update the frame with firstRoll score
    this.checkStrike(); // checks if there was a strike
  } else { // if its on its second roll and there was no strike
    this.currentFrameObject.secondRoll(pinsKnocked); // updates frame with the results of the second roll
    this.scoreSheet.push(this.currentFrameObject); // frame finished add the frame to scoreSheet:
    this.calculateScore(); // calculates score at end of the frame
    // this.strikeCount = 0; // resets strike count to 0
    this.gameOver(); // checks if the game is over
    this.currentFrameObject = null; //resets current frame
  }
};

Game.prototype.checkStrike = function() {
  if (this.currentFrameObject.strike == true) {
    this.scoreSheet.push(this.currentFrameObject);
    this.calculateScore();
    this.gameOver();
    this.currentFrameObject = null;
    this.strikeCount += 1;
    return;
  }
};

Game.prototype.calculateScore = function() {
if (this.frameIndex != 0 && this.scoreSheet[this.frameIndex - 1].strike == true && this.scoreSheet[this.frameIndex].strike == false) {
    console.log('wee') // checking if previous frame was a strike
    this.totalScore += ((this.strikeCount * 10 + this.currentFrameObject.totalFrameScore) + this.currentFrameObject.totalFrameScore);

  }  // if on first frame or if there were no strikes/spares
  else  if ((this.frameIndex != 0 || this.frameIndex == 0) && (this.scoreSheet[this.frameIndex].strike == false && this.scoreSheet[this.frameIndex].spare == false )) {
      this.totalScore += this.currentFrameObject.totalFrameScore;
    }
  // //
  // get a variable/property that stores the roll of strikes we're on like in old code. when strike happens + 1, when it doesnt reset it.
  // could there be an accumulating variable that stores the points
};

Game.prototype.gameOver = function() {
  if (this.frameIndex == 9 && this.currentFrameObject.strike == false) {
    this.isGameOver = true;
  }
};

// what happens when there is a half strike?

// game.prototype.resetGame = function() {
//<commit_msg>working on strike score calculator<commit_after>function Game() {
  this.frameIndex = -1; // -1 as 0 needs to be first index
  this.currentFrameObject = null; // this will be refreshed every frame to the newly created Frame
  this.scoreSheet = []; //[Frame, Frame] stores individual frames
  this.totalScore = 0; // is this needed? if so -- does it belong in Frame?
  this.isGameOver = false;
  this.strikeCount = 0;
}

Game.prototype.rollBall = function(pinsKnocked) {
  this.logRoll(pinsKnocked);
};

Game.prototype.logRoll = function(pinsKnocked) {

  if (this.isGameOver == true) {
    fail('Game Over, please reset the game');
  }

  if (this.currentFrameObject == null) {
    this.currentFrameObject = new Frame(); //create the frame object for every new frame(round)
    this.frameIndex += 1;//
  }

  if (this.currentFrameObject.rollIndex == 0) { //if its on its first roll:
    this.currentFrameObject.firstRoll(pinsKnocked); //update the frame with firstRoll score
    this.checkStrike(); // checks if there was a strike
  } else { // if its on its second roll and there was no strike
    this.currentFrameObject.secondRoll(pinsKnocked); // updates frame with the results of the second roll
    this.scoreSheet.push(this.currentFrameObject); // frame finished add the frame to scoreSheet:
    this.calculateScore(); // calculates score at end of the frame
    this.strikeCount = 0; // resets strike count to 0
    this.gameOver(); // checks if the game is over
    this.currentFrameObject = null; //resets current frame
  }
};

Game.prototype.checkStrike = function() {
  if (this.currentFrameObject.strike == true) {
    this.scoreSheet.push(this.currentFrameObject);
    this.calculateScore();
    this.gameOver();
    this.currentFrameObject = null;
    this.strikeCount += 1;
    return;
  }
};

Game.prototype.strikeCalculator = function() {
  var i = 1
  while (this.scoreSheet[this.frameIndex - i].strike == true && this.strikeCount > 1) {
    this.totalScore += (this.strikeCount * 10); // X X 6 - 0
    this.strikeCount - 1; // 20 + 30 + 12
    i -= 1
    console.log(this.totalScore)
  }

  this.totalScore += 10 + (2 * this.currentFrameObject.totalFrameScore); // 42 but should be 45
};

Game.prototype.calculateScore = function() {
  if (this.frameIndex != 0 && this.scoreSheet[this.frameIndex - 1].strike == true && this.scoreSheet[this.frameIndex].strike == false) {
    console.log('wee');
    this.strikeCalculator();
  }  // if on first frame or if there were no strikes/spares
  else if ((this.frameIndex != 0 || this.frameIndex == 0) && (this.scoreSheet[this.frameIndex].strike == false && this.scoreSheet[this.frameIndex].spare == false)) {
    this.totalScore += this.currentFrameObject.totalFrameScore;
  }

};

Game.prototype.gameOver = function() {
  if (this.frameIndex == 9 && this.currentFrameObject.strike == false) {
    this.isGameOver = true;
  }
};

// what happens when there is a half strike?

// game.prototype.resetGame = function() {
//
{'fraction_non_alphanumeric': 0.1258031788975313, 'fraction_numerical': 0.009130875887724045, 'mean_word_length': 3.4641509433962265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3890812', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1774, 'n_words': 530}