Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3965870
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:31:24+00:00 2026-05-20T03:31:24+00:00

I’ll start by saying I am very much a beginner programmer, this is essentially

  • 0

I’ll start by saying I am very much a beginner programmer, this is essentially my first real project outside of using learning material. I’ve been making a ‘Simon Says’ style game (the game where you repeat the pattern generated by the computer) using C# and XNA, the actual game is complete and working fine but while creating it, I wanted to also create a ‘top 10′ scoreboard. The scoreboard would record player name, level (how many ’rounds’ they’ve completed) and combo (how many buttons presses they got correct), the scoreboard would then be sorted by combo score. This led me to XML, the first time using it, and I eventually got to the point of having an XML file that recorded the top 10 scores. The XML file is managed within a scoreboard class, which is also responsible for adding new scores and sorting scores. Which gets me to the point… I’d like some feedback on the way I’ve gone about sorting the score list and how I could have done it better, I have no other way to gain feedback =(. I know .NET features Array.Sort() but I wasn’t too sure of how to use it as it’s not just a single array that needs to be sorted. When a new score needs to be entered into the scoreboard, the player name and level also have to be added. These are stored within an ‘array of arrays’ (10 = for ‘top 10’ scores)

scoreboardComboData = new int[10]; // Combo

scoreboardTextData = new string[2][];
scoreboardTextData[0] = new string[10]; // Name
scoreboardTextData[1] = new string[10]; // Level as string

The scoreboard class works as follows:

– Checks to see if ‘scoreboard.xml’ exists, if not it creates it
– Initialises above arrays and adds any player data from scoreboard.xml, from previous run
– when AddScore(name, level, combo) is called the sort begins
– Another method can also be called that populates the XML file with above array data

The sort checks to see if the new score (combo) is less than or equal to any recorded scores within the scoreboardComboData array (if it’s greater than a score, it moves onto the next element). If so, it moves all scores below the score it is less than or equal to down one element, essentially removing the last score and then places the new score within the element below the score it is less than or equal to. If the score is greater than all recorded scores, it moves all scores down one and inserts the new score within the first element. If it’s the only score, it simply adds it to the first element. When a new score is added, the Name and Level data is also added to their relevant arrays, in the same way. What a tongue twister. Below is the AddScore method, I’ve added comments in the hope that it makes things clearer O_o. You can get the actual source file HERE. Below the method is an example of the quickest way to add a score to follow through with a debugger.

    public static void AddScore(string name, string level, int combo)
    {
        // If the scoreboard has not yet been filled, this adds another 'active'
        // array element each time a new score is added. The actual array size is
        // defined within PopulateScoreBoard() (set to 10 - for 'top 10'
        if (totalScores < scoreboardComboData.Length)
            totalScores++;

        // Does the scoreboard even need sorting?
        if (totalScores > 1)
        {
            for (int i = totalScores - 1; i > - 1; i--)
            {
                // Check to see if score (combo) is greater than score stored in 
                // array
                if (combo > scoreboardComboData[i] && i != 0)
                {
                    // If so continue to next element
                    continue;
                }

                // Check to see if score (combo) is less or equal to element 'i'
                // score && that the element is not the last in the
                // array, if so the score does not need to be added to the scoreboard
                else if (combo <= scoreboardComboData[i] && i != scoreboardComboData.Length - 1)
                {
                    // If the score is lower than element 'i' and greater than the last
                    // element within the array, it needs to be added to the scoreboard. This is achieved
                    // by moving each element under element 'i' down an element. The new score is then inserted
                    // into the array under element 'i'
                    for (int j = totalScores - 1; j > i; j--)
                    {
                        // Name and level data are moved down in their relevant arrays
                        scoreboardTextData[0][j] = scoreboardTextData[0][j - 1];
                        scoreboardTextData[1][j] = scoreboardTextData[1][j - 1];
                        // Score (combo) data is moved down in relevant array
                        scoreboardComboData[j] = scoreboardComboData[j - 1];
                    }

                    // The new Name, level and score (combo) data is inserted into the relevant array under element 'i'
                    scoreboardTextData[0][i + 1] = name;
                    scoreboardTextData[1][i + 1] = level;
                    scoreboardComboData[i + 1] = combo;
                    break;
                }

                // If the method gets the this point, it means that the score is greater than all scores within
                // the array and therefore cannot be added in the above way. As it is not less than any score within
                // the array.
                else if (i == 0)
                {
                    // All Names, levels and scores are moved down within their relevant arrays
                    for (int j = totalScores - 1; j != 0; j--)
                    {
                        scoreboardTextData[0][j] = scoreboardTextData[0][j - 1];
                        scoreboardTextData[1][j] = scoreboardTextData[1][j - 1];
                        scoreboardComboData[j] = scoreboardComboData[j - 1];
                    }

                    // The new number 1 top name, level and score, are added into the first element
                    // within each of their relevant arrays.
                    scoreboardTextData[0][0] = name;
                    scoreboardTextData[1][0] = level;
                    scoreboardComboData[0] = combo;

                    break;
                }

                // If the methods get to this point, the combo score is not high enough
                // to be on the top10 score list and therefore needs to break
                break;
            }
        }

        // As totalScores < 1, the current score is the first to be added. Therefore no checks need to be made
        // and the Name, Level and combo data can be entered directly into the first element of their relevant
        // array.
        else
        {
            scoreboardTextData[0][0] = name;
            scoreboardTextData[1][0] = level;
            scoreboardComboData[0] = combo;
        }


    }
}

Example for adding score:

    private static void Initialize()
    {
        scoreboardDoc = new XmlDocument();
        if (!File.Exists("Scoreboard.xml"))
            GenerateXML("Scoreboard.xml");

        PopulateScoreBoard("Scoreboard.xml");

        // ADD TEST SCORES HERE!
        AddScore("EXAMPLE", "10", 100);
        AddScore("EXAMPLE2", "24", 999);

        PopulateXML("Scoreboard.xml");
    }

In it’s current state the source file is just used for testing, initialize is called within main and PopulateScoreBoard handles the majority of other initialising, so nothing else is needed, except to add a test score.

I thank you for your time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:31:24+00:00Added an answer on May 20, 2026 at 3:31 am

    As a programming tip, you should replace the 3 different arrays with a single array of Score Objects, each of these objects would have all 3 properties you mentioned (Name, Level and Score). You can then create a comparator-like function (based on the score attribute) for it which can be used to sort it via the Arrays.Sort() method.

    If you want to keep you current 3 arrays then you can look up sorting algorithms here: http://en.wikipedia.org/wiki/Sorting_algorithm#Comparison_of_algorithms and just make it so that any changes are done to the 3 arrays simultaneously instead of one by one (since you keep the data in them synchronized by index).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.