Uses accompanying Basket, Objects and Fruit libraries to create Fruit Basket game. If an object is caught, points are added; if an object in missed, a 'life' is lost.
Dependents: Game_Controller_Project
Diff: Catch_Model.cpp
- Revision:
- 15:1a0bd800f1f1
- Parent:
- 14:6764bb61d413
- Child:
- 16:dae98691cc0e
diff -r 6764bb61d413 -r 1a0bd800f1f1 Catch_Model.cpp --- a/Catch_Model.cpp Thu Apr 27 12:39:53 2017 +0000 +++ b/Catch_Model.cpp Fri Apr 28 17:15:01 2017 +0000 @@ -154,13 +154,21 @@ //DISPLAY FUNCTIONS// //Re-draw the screen after updates to positions, scores etc are made -void Catch_Model::draw(N5110 &lcd) +void Catch_Model::draw(N5110 &lcd, Gamepad &pad) { basket.draw(lcd); objects.draw(lcd); print_score(lcd); print_lives(lcd); print_delay(lcd); + + if(get_lives() == 0) + { + do{ + lcd.clear(); + final_score(lcd); + } while (pad.check_event(Gamepad::START_PRESSED) == false); + } } //Get the number of lives and print on the display @@ -200,6 +208,30 @@ } } +void Catch_Model::final_score(N5110 &lcd) +{ + char buffer[14]; + int score = basket.get_score(); + + int print_score; + + if ((score == 0)||(score <= 9)) { //if loop keeps the length of the string fixed... + print_score = sprintf(buffer, "000%d", score); + } else if (score <= 99) { + print_score = sprintf(buffer, "00%2d", score); + } else if (score <= 999 ) { + print_score = sprintf(buffer, "0%3d", score); + } else { + print_score = sprintf(buffer, "%4d", score); + } //...with maximum printable score of 9999 + + lcd.printString(" GAME OVER ",0,2); + if (print_score <= 14) { + lcd.printString(buffer,34,3); + lcd.refresh(); + } +} + //Print a tick if _delay = 1, otherwise print a cross void Catch_Model::print_delay(N5110 &lcd) {