private void UpdateScoreboard() { Action <int> add = count =>//function to get the player name and add a tuple to the scoreboard { Console.Write("Enter Name: "); string name = Console.ReadLine(); Tuple <string, int> player = Tuple.Create <string, int>(name, count); this.scoreBoard.Add(player); }; if (scoreBoard.Count < 5) { add(baloonsGame.PopCount); return; } else { if (scoreBoard.ElementAt <Tuple <string, int> >(4).Item2 >= baloonsGame.PopCount) { add(baloonsGame.PopCount); scoreBoard.RemoveRange(4, 1);//if the new name replaces one of the old ones, remove the old one } } scoreBoard.Sort(delegate(Tuple <string, int> p1, Tuple <string, int> p2)//re-sort the list { return(p1.Item2.CompareTo(p2.Item2)); }); baloonsGame = new BaloonsGame(); }
public GameUI() { Console.WriteLine("Welcome to “Balloons Pops” game. Please try to pop the balloons."); Console.WriteLine(" Use 'top' to view the top scoreboard, 'restart' to start a new game and 'exit' to quit the game."); baloonsGame = new BaloonsGame(); scoreBoard = new List <Tuple <string, int> >(); }
private void Restart() { baloonsGame = new BaloonsGame(); }