Results 1 to 11 of 11

Thread: C++ question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default C++ question

    This should be quite easy for you mighty C++ veterans.

    How do I create a highscores table in a game, so that I can view it and add to it?

    I have a feeling it involves it looking in a .txt file and making changes to it.

    Thanks

  2. #2

    Default Re: C++ question

    I'm thinking file I/O. Search it on google, it's pretty simple.

  3. #3
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default Re: C++ question

    I found it, it does indeed look simple.

    Thanks

  4. #4
    Needs more flowers Moderator drone's Avatar
    Join Date
    Dec 2004
    Location
    Moral High Grounds
    Posts
    9,286

    Default Re: C++ question

    Definitely file I/O. Do you want the file to be human-readable (and easily modified) outside the game? Or do you want the uninitiated to not be able to decipher it from, say, notepad?
    The .Org's MTW Reference Guide Wiki - now taking comments, corrections, suggestions, and submissions

    If I werent playing games Id be killing small animals at a higher rate than I am now - SFTS
    Si je n'étais pas jouer à des jeux que je serais mort de petits animaux à un taux plus élevé que je suis maintenant - Louis VI The Fat

    "Why do you hate the extremely limited Spartan version of freedom?" - Lemur

  5. #5
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default Re: C++ question

    Things have gone a bit wrong, I asked my lecturer how to get the numbers from the text file (I don't think he understood what I was trying to do), he used the getline() code to get the numbers out of the file. The problem is that they are stored in a char array, which means each digit on the number is in a different part of the array and finding out which number is bigger will be very difficult.

    The program (which will be intergrated into the game) works like this:
    1. Open the file.
    2. Get the numbers from file.
    3. Input a number that called CS (Current score, this would normally come from the game).
    4. A big nested if statement to find out where the CS number should go in the list, or if it is too small display a message telling the player they do not have a high score.
    5. Display the updated high scores.
    6. Update the file with the new scores.
    7. Close the file

    Question:
    1. Should I be using a text file for this program?
    2. Is there any other way of getting the numbers out of the file?
    3. Is there a way to convert a char array into an int?

    Thanks.

  6. #6
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default Re: C++ question

    I think I have solved the problem by using the atoi() thing.

  7. #7
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default Re: C++ question

    I have got it all working now.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO