Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Scores/Scores.cpp@16:a2c945279b79, 2019-04-24 (annotated)
- Committer:
- el17mcd
- Date:
- Wed Apr 24 13:44:12 2019 +0000
- Revision:
- 16:a2c945279b79
- Child:
- 17:cb39d9fa08dc
! Player now receives score at the end of the game. leaderboard added in the menus.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17mcd | 16:a2c945279b79 | 1 | /* Scores.cpp |
el17mcd | 16:a2c945279b79 | 2 | Processes new scores and saves |
el17mcd | 16:a2c945279b79 | 3 | the highest ones. |
el17mcd | 16:a2c945279b79 | 4 | 23.4.19 |
el17mcd | 16:a2c945279b79 | 5 | */ |
el17mcd | 16:a2c945279b79 | 6 | #include "Scores.h" |
el17mcd | 16:a2c945279b79 | 7 | |
el17mcd | 16:a2c945279b79 | 8 | Scores::Scores() |
el17mcd | 16:a2c945279b79 | 9 | { |
el17mcd | 16:a2c945279b79 | 10 | _top_three[0] = 0; |
el17mcd | 16:a2c945279b79 | 11 | _top_three[1] = 0; |
el17mcd | 16:a2c945279b79 | 12 | _top_three[2] = 0; |
el17mcd | 16:a2c945279b79 | 13 | } |
el17mcd | 16:a2c945279b79 | 14 | |
el17mcd | 16:a2c945279b79 | 15 | Scores::~Scores() |
el17mcd | 16:a2c945279b79 | 16 | { |
el17mcd | 16:a2c945279b79 | 17 | |
el17mcd | 16:a2c945279b79 | 18 | } |
el17mcd | 16:a2c945279b79 | 19 | |
el17mcd | 16:a2c945279b79 | 20 | float Scores::score_calculator(int turns, int health) |
el17mcd | 16:a2c945279b79 | 21 | { |
el17mcd | 16:a2c945279b79 | 22 | float new_score = health * 100 / turns; |
el17mcd | 16:a2c945279b79 | 23 | _add_to_top_scores(new_score); |
el17mcd | 16:a2c945279b79 | 24 | return new_score; |
el17mcd | 16:a2c945279b79 | 25 | } |
el17mcd | 16:a2c945279b79 | 26 | |
el17mcd | 16:a2c945279b79 | 27 | void Scores::display_score(float current, N5110 &lcd) |
el17mcd | 16:a2c945279b79 | 28 | { |
el17mcd | 16:a2c945279b79 | 29 | char buffer[14]; |
el17mcd | 16:a2c945279b79 | 30 | sprintf(buffer, "%.0f", current); |
el17mcd | 16:a2c945279b79 | 31 | lcd.printString(" Score :", 10, 4); |
el17mcd | 16:a2c945279b79 | 32 | lcd.printString(buffer, 60, 4); |
el17mcd | 16:a2c945279b79 | 33 | } |
el17mcd | 16:a2c945279b79 | 34 | |
el17mcd | 16:a2c945279b79 | 35 | void Scores::display_top_scores(N5110 &lcd) |
el17mcd | 16:a2c945279b79 | 36 | { |
el17mcd | 16:a2c945279b79 | 37 | char buffer[14]; |
el17mcd | 16:a2c945279b79 | 38 | sprintf(buffer, "%.0f", _top_three[0]); |
el17mcd | 16:a2c945279b79 | 39 | lcd.printString(" 1. ", 15, 2); |
el17mcd | 16:a2c945279b79 | 40 | lcd.printString(buffer, 45, 2); |
el17mcd | 16:a2c945279b79 | 41 | |
el17mcd | 16:a2c945279b79 | 42 | sprintf(buffer, "%.0f", _top_three[1]); |
el17mcd | 16:a2c945279b79 | 43 | lcd.printString(" 2. ", 15, 3); |
el17mcd | 16:a2c945279b79 | 44 | lcd.printString(buffer, 45, 3); |
el17mcd | 16:a2c945279b79 | 45 | |
el17mcd | 16:a2c945279b79 | 46 | sprintf(buffer, "%.0f", _top_three[2]); |
el17mcd | 16:a2c945279b79 | 47 | lcd.printString(" 3. ", 15, 4); |
el17mcd | 16:a2c945279b79 | 48 | lcd.printString(buffer, 45, 4); |
el17mcd | 16:a2c945279b79 | 49 | } |
el17mcd | 16:a2c945279b79 | 50 | |
el17mcd | 16:a2c945279b79 | 51 | void Scores::_add_to_top_scores(float new_score) |
el17mcd | 16:a2c945279b79 | 52 | { |
el17mcd | 16:a2c945279b79 | 53 | if (new_score > _top_three[0]) { |
el17mcd | 16:a2c945279b79 | 54 | _top_three[2] = _top_three[1]; |
el17mcd | 16:a2c945279b79 | 55 | _top_three[1] = _top_three[0]; |
el17mcd | 16:a2c945279b79 | 56 | _top_three[0] = new_score; |
el17mcd | 16:a2c945279b79 | 57 | } |
el17mcd | 16:a2c945279b79 | 58 | else if (new_score > _top_three[1]) { |
el17mcd | 16:a2c945279b79 | 59 | _top_three[2] = _top_three[1]; |
el17mcd | 16:a2c945279b79 | 60 | _top_three[1] = new_score; |
el17mcd | 16:a2c945279b79 | 61 | } |
el17mcd | 16:a2c945279b79 | 62 | else if (new_score > _top_three[2]) { |
el17mcd | 16:a2c945279b79 | 63 | _top_three[2] = new_score; |
el17mcd | 16:a2c945279b79 | 64 | } |
el17mcd | 16:a2c945279b79 | 65 | } |