Difference between revisions of "High score table feature"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
At the end of the game, take the high score and check the current table of high scores to see if it can go on the table. Then, add in the result and move or remove any other high scores lower in the table or that have fallen off the table. This text file could save every score played from the game, but I'll do top ten to add the removing feature. The scores also need a name attributed to them, so let the user input some letters to save with their score, and then add a way to display the table.  
+
At the end of the game, take the high score and check the current table of high scores to see if it can go on the table. Then, add in the result and move or remove any other high scores lower in the table or that have fallen off the table. This text file could save every score played from the game, but I'll do top ten to add the removing feature. The scores the need a way to be displayed.
 +
 
 +
(needs the addition of a way to display the highscore table.)
 +
 
  
 
<syntaxhighlight lang="csharp" line>
 
<syntaxhighlight lang="csharp" line>
Line 5: Line 8:
 
{
 
{
 
     StreamReader UpdateHSTable = new StreamReader("highscores.txt");
 
     StreamReader UpdateHSTable = new StreamReader("highscores.txt");
     string[10] HSTable = System.IO.File.ReadAllLines("highscores.txt");;
+
     string[] HSTable = System.IO.File.ReadAllLines("highscores.txt");
      
+
    string[] TempTable;
 +
    int TempInt = 0;
 +
    for (int a = 0; a < 10; a++;)
 +
    {
 +
        if (PlayerOneScore >= Convert.ToInt32(HSTable[a]))
 +
        {
 +
        TempTable[TempInt] = HSTable[a];
 +
        TempInt++;
 +
        HSTable[a] = PlayerOneScore;
 +
        }
 +
        if (PlayerTwoScore >= Convert.ToInt32(HSTable[a]))
 +
        {
 +
        TempTable[TempInt] = HSTable[a];
 +
        TempInt++;
 +
        HSTable[a] = PlayerTwoScore;
 +
        }
 +
        if (TempTable[TempInt] >= HSTable[a+1])
 +
        {
 +
        TempTable[TempInt+1] = HSTable[a+1];
 +
        HSTable[a+1] = TempTable[TempInt];
 +
        TempTable[TempInt] = TempTable[TempInt+1];
 +
        TempTable[TempInt+1] = "";
 +
        }
 +
     }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 10:21, 19 February 2018

At the end of the game, take the high score and check the current table of high scores to see if it can go on the table. Then, add in the result and move or remove any other high scores lower in the table or that have fallen off the table. This text file could save every score played from the game, but I'll do top ten to add the removing feature. The scores the need a way to be displayed.

(needs the addition of a way to display the highscore table.)


 1 static void HSUpdate()
 2 {
 3     StreamReader UpdateHSTable = new StreamReader("highscores.txt");
 4     string[] HSTable = System.IO.File.ReadAllLines("highscores.txt");
 5     string[] TempTable;
 6     int TempInt = 0;
 7     for (int a = 0; a < 10; a++;)
 8     {
 9         if (PlayerOneScore >= Convert.ToInt32(HSTable[a]))
10         {
11         TempTable[TempInt] = HSTable[a];
12         TempInt++;
13         HSTable[a] = PlayerOneScore;
14         }
15         if (PlayerTwoScore >= Convert.ToInt32(HSTable[a]))
16         {
17         TempTable[TempInt] = HSTable[a];
18         TempInt++;
19         HSTable[a] = PlayerTwoScore;
20         }
21         if (TempTable[TempInt] >= HSTable[a+1])
22         {
23         TempTable[TempInt+1] = HSTable[a+1];
24         HSTable[a+1] = TempTable[TempInt];
25         TempTable[TempInt] = TempTable[TempInt+1];
26         TempTable[TempInt+1] = "";
27         }
28     }
29 }