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(); }
public bool ReadInput(out bool IsCoordinates, ref Coordinates coordinates, ref Command command) { Console.Write("Enter a row and column: "); string consoleInput = Console.ReadLine(); coordinates = new Coordinates(); command = new Command(); if (Command.IsValidCommand(consoleInput)) { IsCoordinates = false; command.Name = consoleInput; return true; } else if (Coordinates.TryParse(consoleInput, ref coordinates)) { IsCoordinates = true; return true; } else { IsCoordinates = false; return false; } }
public static bool TryParse(string input, ref Command result) { if (input == "top") { result.Value = input; return true; } if (input == "restart") { result.Value = input; return true; } if (input == "exit") { result.Value = input; return true; } return false; }