Skip to content

Commit

Permalink
REQ: getLives method in case a user types a password (previous scene …
Browse files Browse the repository at this point in the history
…was not played); it gives either 5 lives or lives from previous (finished) scene or 1 life
  • Loading branch information
pe-pan committed Dec 2, 2016
1 parent a5cbc0f commit 7f0f4ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions mobile/src/main/java/com/mz800/flappy/FlappyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,21 @@ int[] loadScore(int scNo) {
for (int i = 0; i < scNo - 1; i++) {
previousScores += ScreenScore.screenScores[i].myBestScore;
}
return new int[]{previousScores,
(scNo - 1) % 5 == 0 // for every fifth scene
? 5 : // give 5 lives
ScreenScore.screenScores[scNo - 2].myLives}; // or the previous num of lives
int lives = getLives(scNo - 1);
return new int[]{previousScores, lives};
}

/**
* How many lives this scene should start with?
* @param scNo
* @return
*/
int getLives(int scNo) {
int lives = scNo % 5 == 0 // for every fifth scene
? 5 : // give 5 lives
ScreenScore.screenScores[scNo - 1].myLives; // or the previous num of lives
if (lives <= 0) lives = 1; // if the previous game was not played (user typed a password), give it 1 life
return lives;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private Bitmap drawSceneBitmap(int num) {
}
Scene scene = new Scene(num+1, new VRAM());
ScreenScore score = ScreenScore.screenScores[num];
int lives = num % 5 == 0 ? 5 : ScreenScore.screenScores[num-1].myLives; // take number of lives from previous scene
int lives = getLives(num);
if (num <= openScenes) {
scene.predrawScene(true, lives, score.myBestScore);
} else {
Expand Down

0 comments on commit 7f0f4ee

Please sign in to comment.