public int getScore()
{
int score = 0; // initialize int
if(levelOne.goalReached()) // if level 1 is completed...
{
score += levelOne.getPoints(); // adds level 1 points
if(levelTwo.goalReached()) // if level 2 is completed...
{
score += levelTwo.getPoints(); // adds level 2 points
if(levelThree.goalReached()) // if level 3 is completed...
{
score += levelThree.getPoints(); // adds level 3 points
}
}
}
if(isBonus())
score *= 3; // if it is a bonus game, multiply by 3
return score; // returns int: final score
}
public int playManyTimes(int num)
{
int score = 0; // initialize int
for(int i = 0; g i < num; i++)
{
play(); // call play
if (getScore() > score) {
score = getScore(); // change score values
}
}
return bestScore; // return int: best score
}
Sources
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition_assignment
https://apcentral.collegeboard.org/media/pdf/ap22-frq-computer-science-a.pdf?course=ap-computer-science-a
https://www.w3schools.com/java/default.asp
https://www.w3schools.com/java/java_for_loop.asp
https://www.youtube.com/watch?v=1uHSJ08-zhA