AnimeGalleries [dot] NetAnimeWallpapers [dot] ComAnimeLyrics [dot] ComAnimePedia [dot] ComAnimeGlobe [dot] Com

User Tag List

+ Reply to Thread
Results 1 to 6 of 6

Thread: [Help - C++] Saving high scores

  1. #1
    Fearless Red Mage SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13's Avatar
    Gil
    7,106.46
    Gender
    My Mood
    Talkative
    Gifts Ice Ornament Ouran Patch
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    06-25-2013 07:13 AM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Dec 2011
    Location
    Philippines
    Age
    18
    Threads
    18
    Posts
    692
    Blog Entries
    35
    Rep Power
    194

    Default [Help - C++] Saving high scores

    So, our C++ professor told us that our project will be a game designed using c++.

    We're done with the codes however our professor pointed out that the game should record the highest score.

    Can anyone tell me the specific codes to record the highest score?

    Please, anybody. help us! Our project's submission is friday.
    Please help us A.S.A.P. Thanks! )

  2. #2
    Copyright 2013 FS FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD's Avatar
    Gil
    3,914.94
    Gender
    My Mood
    Lonely
    Gifts Ice Cream Bamboo Cup Notebook
    Mentioned
    144 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    10-17-2014 02:29 PM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Jun 2005
    Location
    I would like to know that too. O_o;;
    Age
    29
    Threads
    146
    Posts
    2,721
    Blog Entries
    5
    AW Wallpapers
    3
    Rep Power
    2191
    Gamer IDs

    Gamertag: Felsho

    Default Re: C++ Game Help!

    Well, high scores are recorded inside files, so creating a new file and just append the latest score to the file should work well. As for reading the score, you simply read the file, sort the entries by score and use a function to split the data appropriately. Of course you can choose to sort before saving to file, too, but then use the option to rewrite the file instead of append. Probably the easiest way to save the score, is to write it in the following format: score|name|date
    The provided format will make any sorting algorithm sort by score.

    Actual code shouldn't be hard to write considering you are in advanced programming.

  3. #3
    Fearless Red Mage SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13's Avatar
    Gil
    7,106.46
    Gender
    My Mood
    Talkative
    Gifts Ice Ornament Ouran Patch
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    06-25-2013 07:13 AM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Dec 2011
    Location
    Philippines
    Age
    18
    Threads
    18
    Posts
    692
    Blog Entries
    35
    Rep Power
    194

    Default Re: [Help - C++] Saving high scores

    Actually, Programming isn't my forte and I suck at writing codes.
    Can you please provide a sample of codes that will record the highest score?

  4. #4
    Copyright 2013 FS FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD's Avatar
    Gil
    3,914.94
    Gender
    My Mood
    Lonely
    Gifts Ice Cream Bamboo Cup Notebook
    Mentioned
    144 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    10-17-2014 02:29 PM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Jun 2005
    Location
    I would like to know that too. O_o;;
    Age
    29
    Threads
    146
    Posts
    2,721
    Blog Entries
    5
    AW Wallpapers
    3
    Rep Power
    2191
    Gamer IDs

    Gamertag: Felsho

    Default Re: [Help - C++] Saving high scores

    In the next 2 weeks is not possible, but then it will be too late. We have some C/C++ devs here though. Maybe, if you are lucky, somebody will write it for you, otherwise I might post one as reference, in case anybody else needs it.

  5. #5
    Senior Member nslay has much to be proud of nslay has much to be proud of nslay has much to be proud of nslay has much to be proud of nslay has much to be proud of nslay has much to be proud of nslay has much to be proud of nslay has much to be proud of nslay has much to be proud of nslay has much to be proud of nslay's Avatar
    Gil
    198,964.31
    Gender
    Gifts Chicken Glasses Red Glasses Red
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    06-08-2014 09:24 AM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Sep 2012
    Threads
    3
    Posts
    174
    Rep Power
    17

    Default Re: [Help - C++] Saving high scores

    Here, I'll get you started. All of the below can be found out quite easily through http://www.cplusplus.com/reference/

    If you know enough of the basic language, the above reference is a great way to expand your knowledge.

    Code:
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <functional>
    #include <fstream>
    
    struct Score {
      // The fields of our score
      std::string strName;
      float fScore;
    
      // Default constructor
      Score() {
        fScore = 0.0f;
      }
    
      // Comparison operator for std::sort()
      bool operator>(const Score &clScore) const {
        return fScore > clScore.fScore; 
      }
    };
    
    // Let's define stream operations for Score to make it easier to read and write ... oh and let's suppose strName is one word for simplicity (otherwise we need to use std::getline())
    
    // First output streams (e.g. std::cout)
    std::ostream & operator<<(std::ostream &os, const Score &clScore) {
      return os << clScore.strName << ' ' << clScore.fScore;
    }
    
    // Now input streams (e.g. std::cin)
    std::istream & operator>>(std::istream &is, Score &clScore) {
      return is >> clScore.strName >> clScore.fScore;
    }
    
    // ...
    
    // Now, then let's say you filled this up already
    std::vector<Score> vScores;
    
    // Sort these in ascending order ...
    std::sort(vScores.begin(), vScores.end(), std::greater<Score>());
    
    // Now, these are sorted and can be saved
    Saving can be done with a loop, or if you want to use STL, through std::copy and std::ostream_iterator (try these out for fun, look under <algorithm> and <iterator> ... though they're often lengthy to use). I'll demonstrate this with a loop since it's simpler.
    Code:
    std::ofstream scoreStream("Scores.txt");
    
    for (size_t i = 0; i < vScores.size(); ++i)
      scoreStream << vScores[i] << std::endl;
    Reading can be done in a similar fashion. If you want to use STL, you can also use std::copy and std::istream_iterator, but you'll need std::back_inserter too (it's quite goofy).
    Code:
    std::ifstream scoreStream("Scores.txt");
    
    std::vector<Score> vScores;
    Score clScore;
    while (scoreStream >> clScore)
      vScores.push_back(clScore);
    For all of these examples, see the references for the included headers above. Good luck. I practically gave you an answer. Try to come up with your own. I hope you learned something.

  6. #6
    Fearless Red Mage SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13 has a reputation beyond repute SakuraKiss13's Avatar
    Gil
    7,106.46
    Gender
    My Mood
    Talkative
    Gifts Ice Ornament Ouran Patch
    Mentioned
    45 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    06-25-2013 07:13 AM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Dec 2011
    Location
    Philippines
    Age
    18
    Threads
    18
    Posts
    692
    Blog Entries
    35
    Rep Power
    194

    Default Re: [Help - C++] Saving high scores

    Thanks @nslay )
    The information you gave will be a great help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Act scores
    By Dreruto in forum Miscellaneous Miscellany
    Replies: 10
    Last Post: 04-08-2012, 03:48 AM
  2. Arcade scores not sending.
    By Daenerys in forum Site Issues / Questions
    Replies: 2
    Last Post: 10-25-2005, 02:06 PM
  3. Game not saving scores.
    By Bunny Tsuki in forum Site Issues / Questions
    Replies: 5
    Last Post: 09-07-2005, 01:37 PM

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