Posted By
SVS on 2023-04-09 06:22:06
| Re: adding high scores to a game
Hi, to do this you have to work with a file on disk where you'll save the top scores, say 10. When the game is run, it should load from disk the array of the scores and when requested it will insert the new score, of course if it is greater than the 10th. For example: 1. ABC 5400; 2. DEF 5100; 3. GHI 4700; ... 10 XYZ 3200.
If the player achieves a score lower than 3200, nothing is to do. If the player achieves a score say 5200, it has to replace the old 2nd score (in the example DEF 5100). Before to write it, you have to scroll down the current array data starting from element 2 to element 9 (the 10th will be lost). After this just save on disk the updated array.
|