I need help. I made a game, something like Stick Run and now, only thing I need to make is highscore, but I don`t know how. I tried to find it but I did not. Pleas, could somebody tell me hot to create it :D :D :D
I'd write it into a file like "score.data" and save it there, but I believe that isn't the fastest or secure way to do it. You can save it into registery but I don't know how to do that and if it is fast/secure or not.
You can look up these two things and use them, but if anyone knows better way to do it then these two ways I'd be glad to hear it.
For linux (locally), I have my game make a secret hidden file that is created at the end of the game. Then I read it and the public file in. If the public file doesn't match the hidden file, I use the hidden file to load the scores. I've never looked into hidden files on Windows so I can't advise on that.
This method makes it so your friends can't sneak and change the score on the public one and make it look like they beat you.
Now to do it online is a different story because unless they hack the game or use some cheating device, you shouldn't have to worry too much about the scores being inaccurate.
#include <iostream.h>
#include <stdio.h>
usingnamespace std;
//(I think it's tedious to right std:: on everything, so I think using extra //memory is worth it)
//I'm a beginner, so this might not be good:
void highscore(int score, int highscore)
{
if (score > highscore)
highscore = score;
//then cout << highscore or something
return 0;
}
//If there's a list of highscores, then
void highscore (int score, int highscore[])
{
longint temp;
longint temp2;
//long int highscore[listsize];
//long int score;
if (score > highscore[0])
{
temp = highscore[i];
highscore[i] = score;
for (int i = 1; i < listsize; i++)
{
temp2 = highscore[i];
highscore[i] = temp;
temp = temp2;
}
}
}
//so in main, with a bool hitObstacle and a goto label named endofgame,
if (hitObstacle)
goto endofgame;
//end brackets for the loop to keep the game going;
}
endofgame:
highscore(score, highscore[])
/*hope this might work*/
That code won't compile. Lines 30 and 31 will tell you i isn't declared because you don't declare it until line 32. Problem with your code is that it can't handle usernames so the high scores are assumed to be the same player every time (ie no friend competition). You can either use two static arrays in parallel (ie if you only want the top 10 scores, make string username[10] and int score[10]) or two vectors in parallel to go over the top 10 scores. You could also use a map container if you wanted.
There are several ways to go about this depending on how you want the high score table to be set up.
#include <iostream.h>
#include <stdio.h>
usingnamespace std;
//(I think it's tedious to right std:: on everything, so I think using extra //memory is worth it)
//I'm a beginner, so this might not be good:
void highscore(int score, int highscore)
{
if (score > highscore)
highscore = score;
//then cout << highscore or something
return 0;
}
//If there's a list of highscores, then
void highscore (int score, string scorename, int highscore[], string scorename[])
{
longint temp;
longint temp2;
string tempname;
string tempname2;
//long int highscore[listsize];
//long int score;
//string scorename;
//string highscorename[listsize];
if (score > highscore[0])
{
temp = highscore[0];
tempname = highscorename[0];
highscore[0] = score;
highscorename[0] = score;
for (int i = 0; i < listsize; i++)
{
temp2 = highscore[i];
tempname2 = highscorename[i];
highscore[i] = temp;
highscorename[i] = tempname;
temp = temp2;
tempname = tempname2;
}
}
}
//so in main, with a bool hitObstacle and a goto label named endofgame,
if (hitObstacle)
goto endofgame;
//end brackets for the loop to keep the game going;
}
endofgame:
highscore(score, highscore[])
/*hope this might work*/