How can I make a scoretable in which players with the same puntuatio have the same rate?
I am doing a game similar to Mario Party, but I have a problem and I don't know how to solve it. The problem is how can I make a scoretable in which players with the same puntuatio have the same rate? It´s a four local multiplayer game, of course.
For example: Player1 score 60 Player 2 score 30 Player 3 score 20 Player 4 score 30
I want to have for player 1 in first 100points player 2 and 4 in third position with 50 points player 3 in fourth postion with 25 points
Here is my sample code
private List<HighscoreEntry> highScoreEntryList;//scoretable list
public void AddToList()
{
//add score
highScoreEntryList = new List<HighscoreEntry>() {
new HighscoreEntry{score = player1score, name = "Player1" },
new HighscoreEntry{score = player2score, name = "Player2" },
new HighscoreEntry{score = player3score, name = "Player3" },
new HighscoreEntry{score = player4score, name = "Player4" }
};
//order puntuations
for (int i = 0; i < highScoreEntryList.Count; i++) {
for (int j = i + 1; j < highScoreEntryList.Count; j++)
{
if (highScoreEntryList[j].score > highScoreEntryList[i].score)
{
HighscoreEntry tmp = highScoreEntryList[i];
highScoreEntryList[i] = highScoreEntryList[j];
highScoreEntryList[j] = tmp;
}
}
}
}
private class HighscoreEntry //class for the list
{
public int score;
public string name;
}
Answer by g5fighter · Jun 25, 2019 at 11:07 PM
I tried to do it with this code:
highScoreEntryList = new List<HighscoreEntry>() {
new HighscoreEntry{score = player1score, name = "Player1" },
new HighscoreEntry{score = player2score, name = "Player2" },
new HighscoreEntry{score = player3score, name = "Player3" },
new HighscoreEntry{score = player4score, name = "Player4" }
};
//order the puntuation
for (int i = 0; i < highScoreEntryList.Count; i++)
{
for (int j = i + 1; j < highScoreEntryList.Count; j++)
{
if (highScoreEntryList[j].score > highScoreEntryList[i].score)
{
HighscoreEntry tmp = highScoreEntryList[i];
highScoreEntryList[i] = highScoreEntryList[j];
highScoreEntryList[j] = tmp;
}
}
}
for (int i = 0,tmp = 0; i < highScoreEntryList.Count; i++)
{
for (int j = i + 1; highScoreEntryList[i].score == highScoreEntryList[j].score; j++)
{
tmp++;
iqual = true;
}
if (iqual == true)
{
for (int j = i; j <= tmp; j++)
{
if (tmp==1)
{
highScoreEntryList[j].score = 75;
}
else if (tmp == 2)
{
highScoreEntryList[j].score = 50;
}
else if (tmp == 3)
{
highScoreEntryList[j].score = 25;
}
iqual = false;
}
} else if (iqual == false)
{
if (i==0)
{
highScoreEntryList[0].score = 125;
}else if (i == 1)
{
highScoreEntryList[1].score = 75;
}
else if (i == 2)
{
highScoreEntryList[2].score = 50;
}
else if (i == 3)
{
highScoreEntryList[3].score = 25;
}
tmp++;
}
i = tmp-1;
}
Your answer
Follow this Question
Related Questions
Problem with ScoreBoard in Ping Pong game 1 Answer
How do you make a scoreboard for a simple match three game?? 1 Answer
Highscore table C# HELP!!! 0 Answers
Score is being added up (in the background) and shows up at the end but not showing continuosly 1 Answer
My score system doesn't display or work? Please help me! 1 Answer