-=>Quoting Phil Ohl to All <=-
PO>Say I created a game and I prompted the user for his/her name to
PO>be placed on the high score list. How could I place the name in a
PO>seprate file so it can be retrieved the next time the game is
PO>played and the high scores displayed.
PO>Thanx,
PO>Phil
Hi Phil;
When you start the program you open a file for reading, read the file
into a data area. This can be done when you end the game and want to
display the high scores.
If there is a new top-ten score to add, you need to add it into the
table at the appropriate. This will require some sort of sorting
algorithm. You can write your own for practice, or you can use one of
the many pre-written library and class objects to do this. I would
recommend a "heap." If you are not familar with heaps, or other
sorting algorithms, you would do well to buy a "programming is
databases" or similar titled book. There are lots of good ones. An
alternative would be to tap a programming friends brain. [grin]
C++ is a good, effient language. It allows you to get down into the
trenches where you can really do some effective stuff... or some
mysterious dammage. [grin]
One more suggestion. Since you are learning, you need a book, or some
source code that you can look at and study. You want to know about
implementing a "high-scores" list, look at some snippets that have
"fstream" operators, learn how they are read. For sorting, look at
some snippets of various sort routines. If they are similar to what
you want, by all means, made use of them. There's no need to
duplicate someone elses efforts.
I suggest that you program incrementally, that is make a small
addition of change at a time to your prog, then run it to see what
effect, or the desired effect. You can learn a lot this way. And as
you get better, you can take bigger steps.
Have fun.
___ Blue Wave/QWK v2.12
--- Maximus/2 3.01
---------------
* Origin: Madman BBS * Chico, California * 530-893-8079 * (1:119/88)
|