Thread: High Score Table

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    High Score Table

    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)

  2. #2
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    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

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    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;
    }

  4. #4
    Unregistered
    Guest
    [code]
    FILE *fp;
    struct score { char name[25]; long score; } myscore;

    fp = fopen("MyScores.dat","wb"); //r for read, w for write
    fwrite( &myscore, sizeof( struct score ), 1, fp );

    Quzah.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    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;
    }

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    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:

    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.

  8. #8
    Sayeh
    Guest
    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.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C program using structs to calculate grades
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-06-2009, 12:33 PM
  2. Frustated with mess table printing
    By benedicttobias in forum C Programming
    Replies: 6
    Last Post: 04-16-2009, 05:50 PM
  3. trouble with creating a loop to read certain number of inputs
    By import tuner650 in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2008, 07:28 PM
  4. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM
  5. High Score Not Working...
    By pbjorge12 in forum C++ Programming
    Replies: 4
    Last Post: 01-25-2005, 01:17 AM