Ive got a problem trying to maintaining to update the content of a list. After completing the game the users details will be stored within the 1st position within the list however if another user plays the game the previous users details would be replaced with the new details.I think the problem arises when the highscores form button is clicked as it opens up a new form causing the content of the list to be set to null.
1st User: https://cdn.discordapp.com/attachments/176014540268371968/556088180466647061/unknown.png 2nd User: https://cdn.discordapp.com/attachments/176014540268371968/556088457311682609/unknown.png
Is there any possible solutions to this issue. Any Help would be appreciated.
public partial class MainMenu : Form
{
private void HighScoresButton_Click(object sender, EventArgs e)
{
HighScoresMenu HighScoresMenu = new HighScoresMenu(newScore, newPoints, PlayersName);
HighScoresMenu.Show();
}
public static List<Player> GetPlayers(float newScore, float newPoints, string PlayersName)
{
var players = new List<Player>();
var newPlayer = new Player
{
Name = PlayersName,
Points = newPoints,
Timer = newScore
};
players.Add(newPlayer);
var TopTenLevel1 = players.OrderByDescending(x => x.Timer).Take(10);
return players;
}
public partial class HighScoresMenu : Form
{
private void HighScoresMenu_Load(object sender, EventArgs e)
{
Debug.Print(county.ToString());
foreach (Player players in MainMenu.GetPlayers(TempnewScore,
TempnewPoints, TempPlayersName))
{
string TemyPlayersName = "Player's Name";
float point = 0;
float time = 0.0f;
List<string> Allplayers = new List<string>();
for(int count = 1; count < 6;count++)
{
Allplayers.Add(string.Format("{0,-2:0}: {1,-40} : {2,9:0} Points : {3,9:0.0} secs", count, TemyPlayersName, point, time));
}
Allplayers[0] = (string.Format("{0,-2:0}: {1,-40} : {2,9:0} Points : {3,9:0.0} secs", 1, players.Name, players.Points, players.Timer));
ListBoxLevel1.DataSource = Allplayers;
}
}
}