Advertisement

top score

Started by September 03, 2002 05:14 PM
2 comments, last by MTT 22 years, 1 month ago
im making a small text gambeling game and i was wodering how u could make a top score save thing so it still keeps it even when u quit the game then start again? [edited by - MTT on September 3, 2002 6:20:23 PM]
--------------------------http://www.gamedev.net/community/forums/icons/icon51.gif ... Hammer time

  #include <iostream>#include <stdio> // for file handling functionsint score; // tracks the player''s scoreint main(){    GameLoop(); // here''s your game code    // when the game is over...    /* open the file containing the old high score, and copy the old    high score to a variable */    int oldhighscore;    FILE *scorefile = fopen("score.txt","r");    fscanf(scorefile,"%d",oldhighscore);    fclose(scorefile);    /* overwrite the file with the new high score if needed */    if (score > oldhighscore){        FILE *newfile = fopen("score.txt","w");        fprintf(newfile,"%d",score);        fclose(newfile);    }    return 0;}  


Something like this? Please note I didn''t actually check this code to work. Just look up functions like fprintf, fscanf, fopen, and fclose, and do something like this. Sorry if my comments are vague.

All you need is a file that contains the current high score. You check at the end to see if the new score is higher, and overwrite the file if needed.

-Arek the Absolute
-Arek the Absolute"The full quartet is pirates, ninjas, zombies, and robots. Create a game which involves all four, and you risk being blinded by the sheer level of coolness involved." - Superpig
Advertisement
lol, mtt is that against the rules????
So what if I'm 13, I can still code better than like 95% of Americans, and probably 99.9% of the people in the world. Whoa, I feel proud.
I dont even think ther is rules. Maybe il try sabbotage. Then il definately win. Muahahahahah.
--------------------------http://www.gamedev.net/community/forums/icons/icon51.gif ... Hammer time

This topic is closed to new replies.

Advertisement