function instead of WriteFile(). Following is the ReadFile()
This call makes sure that the high score list is properly initialized before the game attempts to draw the scores later in the GamePaint() function. The GameEnd() function cleans up resources used by the game, and serves as a great place to write the high score list to a file. A simple addition to this function is all that is required to write the high score list: WriteHiScores(); Of course, the high score list wouldn’t be of much use if the game didn’t display it for all to see. This takes place in the GamePaint() function, which is shown in Listing 24.1. Listing 24.1 The GamePaint() Function Draws the High Score List if the Game Is in Demo Mode 1: void GamePaint(HDC hDC) 2: { 3: // Draw the background 4: _pBackground->Draw(hDC); 5: 6: // Draw the desert bitmap 7: _pDesertBitmap->Draw(hDC, 0, 371); 8: 9: // Draw the sprites 10: _pGame->DrawSprites(hDC); 11: 12: if (_bDemo) 13: { 14: // Draw the splash screen image 15: _pSplashBitmap->Draw(hDC, 142, 20, TRUE); 16: 17: // Draw the hi scores 18: TCHAR szText[64]; 19: RECT rect = { 275, 230, 325, 250}; 20: SetBkMode(hDC, TRANSPARENT); 21: SetTextColor(hDC, RGB(255, 255, 255)); 22: for (int i = 0; i < 5; i++) 23: { 24: wsprintf(szText, "%d", _iHiScores[i]); 25: DrawText(hDC, szText, -1, &rect, DT_SINGLELINE | DT_CENTER | 26: DT_VCENTER); 27: rect.top += 20; 28: rect.bottom += 20; 29: } 30: } 31: else 32: { 33: // Draw the score 34: TCHAR szText[64]; 35: RECT rect = { 460, 0, 510, 30 }; 36: wsprintf(szText, "%d", _iScore); 37: SetBkMode(hDC, TRANSPARENT); 38: SetTextColor(hDC, RGB(255, 255, 255)); 39: DrawText(hDC, szText, -1, &rect, DT_SINGLELINE | DT_RIGHT | 40: DT_VCENTER); 41: 42: // Draw the number of remaining lives (cars) 43: for (int i = 0; i < _iNumLives; i++) 44: _pSmCarBitmap->Draw(hDC, 520 + (_pSmCarBitmap->GetWidth() * i), 45: 10, TRUE); 46: 47: // Draw the game over message, if necessary 48: if (_bGameOver) 49: _pGameOverBitmap->Draw(hDC, 170, 100, TRUE); 50: } 51: } The high score list is drawn just after the splash screen image by looping through each score and drawing it a little below the previous score (lines 17 29). Notice that the high score list is only drawn if the game is in demo mode (line 12), which makes sense when you consider that the high score list is something you want to see in between games. The last game function impacted by the high score list is the SpriteCollision() function,
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services