예제 #1
0
        static void Main(string[] args)
        {
            GameBoard gb = new GameBoard();
            gb.GenerateNewGame();
            gb.PrintGameBoard();
            TopScore ts = new TopScore();

            ts.OpenTopScoreList();

            bool isCoordinates;
            Coordinates coordinates = new Coordinates();
            Command command = new Command();
            while (gb.RemainingBaloons > 0)
            {
                if (gb.ReadInput(out isCoordinates, ref coordinates, ref command))
                {
                    if (isCoordinates)
                    {
                        gb.Shoot(coordinates);
                        gb.PrintGameBoard();
                    }
                    else
                    {
                        switch (command.Value)
                        {
                            case "top":
                                {
                                    ts.PrintScoreList();
                                }
                                break;
                            case "restart":
                                {
                                    gb.GenerateNewGame();
                                    gb.PrintGameBoard();
                                }
                                break;
                            case "exit":
                                {
                                    return;
                                }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Wrong Input!");
                }
            }

            Person player = new Person();
            player.Score = gb.ShootCounter;

            if (ts.IsTopScore(player))
            {
                Console.WriteLine("Please enter your name for the top scoreboard: ");
                player.Name = Console.ReadLine();
                ts.AddToTopScoreList(player);
            }
            ts.SaveTopScoreList();
        }
예제 #2
0
 public void AddToTopScoreList(Person person)
 {
     topScoreList.Add(person);
     PersonScoreComparer comparer = new PersonScoreComparer();
     topScoreList.Sort(comparer);
     while (topScoreList.Count > 5)
     {
         topScoreList.RemoveAt(5);
     }
 }
예제 #3
0
 public bool IsTopScore(Person person)
 {
     if (topScoreList.Count >= MAX_TOP_SCORE_COUNT)
     {
         PersonScoreComparer comparer = new PersonScoreComparer();
         topScoreList.Sort(comparer);
         if (topScoreList[MAX_TOP_SCORE_COUNT - 1] > person)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     return true;
 }
예제 #4
0
 public void OpenTopScoreList()
 {
     using (StreamReader TopScoreStreamReader = new StreamReader("..\\..\\TopScore.txt"))
     {
         string line = TopScoreStreamReader.ReadLine();
         while (line != null)
         {
             char[] separators = { ' ' };
             string[] substrings = line.Split(separators);
             int substringsCount = substrings.Count<string>();
             if (substringsCount > 0)
             {
                 Person player = new Person();
                 player.Name = substrings[1];
                 player.Score = int.Parse(substrings[substringsCount - 2]);
                 topScoreList.Add(player);
             }
             line = TopScoreStreamReader.ReadLine();
         }
     }
 }