Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Problem with making a high score always appear

Author
Message
mjmaurer
14
Years of Service
User Offline
Joined: 12th Jun 2010
Location:
Posted: 15th Jun 2010 18:39 Edited at: 15th Jun 2010 22:19
I was wondering if someone can help me with a program I need to modify. As of now, the program will display a message stating that the user achieved the new high score. I need to make the program always show the high score at the end of the game. I've changed it to ask for the user's name if they got the new high score, but I'm not sure how to display the high score at the end all the time. I've attached what I have so far. I made changes to the void function "newHighScore(int bugs)".

Attachments

Login to view attachments
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 15th Jun 2010 20:21
The file you attached is not the code, it's a Visual Studio project settings file. Your code is in the file with the extension cpp. You can see the file name in the Visual Studio editor as well (for example Main.cpp).
mjmaurer
14
Years of Service
User Offline
Joined: 12th Jun 2010
Location:
Posted: 15th Jun 2010 22:19
Oh, thanks. I think I've attached the new code now.
mjmaurer
14
Years of Service
User Offline
Joined: 12th Jun 2010
Location:
Posted: 16th Jun 2010 18:52
Here's the code I have so far:

void displayBugsZapped(int bugs)
{
// Get the center coordinates.
int centerX = dbScreenWidth() / 2;
int centerY = dbScreenHeight() / 2;

// Enable auto refresh.
dbSyncOff();

// Delete all sprites.
dbDeleteSprite(BUG_SPRITE);
dbDeleteSprite(POINTER_SPRITE);

// Clear the screen.
dbCLS();

// Display the number of bugs zapped.
dbCenterText(centerX, centerY, "Number of bugs zapped:");
dbCenterText(centerX, centerY + 20, dbStr(bugs));
dbCenterText(centerX, centerY + 40, "Press any key...");

// Wait for the user to press a key.
dbWaitKey();

// Determine whether this is the new high score.
checkForHighScore(bugs);

// Disable auto refresh.
dbSyncOn();
}

//******************************************************
// The checkForHighScore function reads the high score *
// from the HighScore.dat file and determines whether *
// the user's score is the new high score. *
//******************************************************
void checkForHighScore(int bugs)
{
// Variable to hold the high score so far.
int highScore;

// If the HighScore.dat file exists, open it and read
// its value. Otherwise, set highScore to 0.
if ( dbFileExist("HighScore.dat") )
{
// Open the HighScore.dat file.
dbOpenToRead( HIGH_SCORE_FILE, "HighScore.dat" );

// Read the current high score.
highScore = dbReadFile(HIGH_SCORE_FILE);

// Close the file.
dbCloseFile(HIGH_SCORE_FILE);
}
else
{
highScore = 0;
}

// Determine whether the user's score is the
// new high score.
if ( bugs > highScore )
{
newHighScore(bugs);
}
}

//******************************************************
// The newHighScore file congratulates the user for *
// attaining the new high score and updates the *
// HighScore.dat file. *
//******************************************************
void newHighScore(int bugs)
{
// Get the center coordinates.
int centerX = dbScreenWidth() / 2;
int centerY = dbScreenHeight() / 2;

// Clear the screen.
dbCLS();

// Congratulate the user.
dbCenterText(centerX, centerY, "Congratulations!");
dbCenterText(centerX, centerY + 20, "That's the new high score!");

// Have the user input their name.
dbCenterText(centerX, centerY + 40, "Enter your name: ");
dbCenterText(centerX, centerY + 60, dbInput() );

// If the HighScore.dat file exists, delete it.
if ( dbFileExist("HighScore.dat") )
{
dbDeleteFile("HighScore.dat");
}

// Open the HighScore.dat file for writing.
dbOpenToWrite( HIGH_SCORE_FILE, "HighScore.dat" );

// Write the user's score to the file.
dbWriteFile(HIGH_SCORE_FILE, bugs);

// Close the file.
dbCloseFile(HIGH_SCORE_FILE);

// Wait for the user to press a key.
dbCenterText(centerX, centerY + 80, "Press any key...");
dbWaitKey();
}

Login to post a reply

Server time is: 2024-07-04 10:23:06
Your offset time is: 2024-07-04 10:23:06