I'm making a game and I want to create a high score table. I do not know how to write this. Please, give me some suggestions.
I'm making a game and I want to create a high score table. I do not know how to write this. Please, give me some suggestions.
Current projects:
1) User Interface Development Kit (C++)
2) HTML SDK (C++)
3) Classes (C++)
4) INI Editor (Delphi)
Just write the scores to a hidden file. Read them when you want output. Do you need some help with the code? I'll be more than happy to assist you in it.
--Garfield
1978 Silver Anniversary Corvette
If the game keeps up with many numerous games, saved to a file and always included with each calculation, it get's complicated. You might typedef a linked-list structure and add nodes as needed, and after each game, a file of say the top-ten is opened and read into a "dynamically sized array" or a linked-list where the contents are added to the averaging process. the updated hi -scores would then be retrieved and displayed.
If you make it to where the hi-score is only kept during program execution, you would have it a little easier, but I would suggest the first approach.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Damnit. This timer is really starting to ........ me off.
Anyway...
Additionally, you could just do some fancy XOR-ing to your data also, in addition to writing in binary, if you wanted to make sure no one edited the file. Perhapse use a checksum also.
Quzah.
Hope is the first step on the road to disappointment.
Truly Hi-Tech, quzah. Hey-why do we pass the address into fwrite? You would think that distrupts the const-ness of the struct? Strange.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
I have no idea. I was wondering that myself. When I first threw the code together, I left off the &, but then checked and it states to use a pointer. Shrug. I suspect it's for cases like this:Truly Hi-Tech, quzah. Hey-why do we pass the address into
fwrite? You would think that distrupts the const-ness of the
struct? Strange.
fwrite( array, sizeof( arrayMember ), numberOfMembers, filePointer );
So this way, arrays are written nicely and cleanly, but when just writing a single one, you pass it's address.
Quzah.
Hope is the first step on the road to disappointment.
Quzah, I'm truly surprised (grin)...
The reason you use an '&' is because you are passing the address of a buffer to fwrite(). It doesn't care whether you pass it an array, a struct, a char, what-- it wants an address to that block of RAM...
It's a general purpose block device driver. It has nothing to do with 'const'.
enjoy.
> Quzah, I'm truly surprised (grin)...
>
> The reason you use an '&' is because you are passing the
> address of a buffer to fwrite(). It doesn't care whether you
> pass it an array, a struct, a char, what-- it wants an address to
> that block of RAM...
Yeah. I'll blame it on being tired. :P I sort of explained as you did with my array example. I was thinking initially that you didn't use it's address there. (Usually I think of it as with *scanf and *printf, where with the *printf functions, you don't use a pointer, and the *scanf functions you do. I was thinking that fwrite was the same way initially.
Quzah.
Hope is the first step on the road to disappointment.