public static void Main(string[] args) { string action = string.Empty; char[,] playField = CreateGameField(); char[,] mines = PlaceMines(); int score = 0; bool gameStart = true; bool gameOver = false; bool gameWon = false; List<PlayerScore> leaderboard = new List<PlayerScore>(6); int row = 0; int col = 0; do { if (gameStart) { Console.WriteLine("Lets play “Mines”. Try not to step on the mine fields." + " The command 'top' shows the leaderboard, 'restart' starts new game, 'exit' quits the game!"); DrawPlayfield(playField); gameStart = false; } Console.Write("Enter row and column: "); action = Console.ReadLine().Trim(); if (action.Length >= 3) { if (int.TryParse(action[0].ToString(), out row) && int.TryParse(action[2].ToString(), out col) && row <= playField.GetLength(0) && col <= playField.GetLength(1)) { action = "turn"; } } switch (action) { case "top": ShowLeaderboard(leaderboard); break; case "restart": playField = CreateGameField(); mines = PlaceMines(); DrawPlayfield(playField); gameOver = false; gameStart = true; break; case "exit": Console.WriteLine("Bye, bye, bye!"); break; case "turn": if (mines[row, col] != MineField) { if (mines[row, col] == EmptyField) { NextTurn(playField, mines, row, col); score++; } if (ScoreLimit == score) { gameWon = true; } else { DrawPlayfield(playField); } } else { gameOver = true; } break; default: Console.WriteLine(Environment.NewLine + "Error! Invalid Command." + Environment.NewLine); break; } if (gameOver) { DrawPlayfield(mines); Console.Write( Environment.NewLine + "Hrrrrrr! You played valiantly and your score is {0}. " + "Please enter a nickname: ", score); string name = Console.ReadLine(); PlayerScore player = new PlayerScore(name, score); if (leaderboard.Count < 5) { leaderboard.Add(player); } else { for (int i = 0; i < leaderboard.Count; i++) { if (leaderboard[i].Points < player.Points) { leaderboard.Insert(i, player); leaderboard.RemoveAt(leaderboard.Count - 1); break; } } } leaderboard.Sort((PlayerScore r1, PlayerScore r2) => r2.Name.CompareTo(r1.Name)); leaderboard.Sort((PlayerScore r1, PlayerScore r2) => r2.Points.CompareTo(r1.Points)); ShowLeaderboard(leaderboard); playField = CreateGameField(); mines = PlaceMines(); score = 0; gameOver = false; gameStart = true; } if (gameWon) { Console.WriteLine(Environment.NewLine + "BRAVOOO! You managed to clear all the {0} mines.", ScoreLimit); DrawPlayfield(mines); Console.WriteLine("Enter your name champ: "); string name = Console.ReadLine(); PlayerScore player = new PlayerScore(name, score); leaderboard.Add(player); ShowLeaderboard(leaderboard); playField = CreateGameField(); mines = PlaceMines(); score = 0; gameWon = false; gameStart = true; } } while (action != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.WriteLine("Cyaaaaaaaa."); Console.Read(); }
public static void Main(string[] args) { string action = string.Empty; char[,] playField = CreateGameField(); char[,] mines = PlaceMines(); int score = 0; bool gameStart = true; bool gameOver = false; bool gameWon = false; List <PlayerScore> leaderboard = new List <PlayerScore>(6); int row = 0; int col = 0; do { if (gameStart) { Console.WriteLine("Lets play “Mines”. Try not to step on the mine fields." + " The command 'top' shows the leaderboard, 'restart' starts new game, 'exit' quits the game!"); DrawPlayfield(playField); gameStart = false; } Console.Write("Enter row and column: "); action = Console.ReadLine().Trim(); if (action.Length >= 3) { if (int.TryParse(action[0].ToString(), out row) && int.TryParse(action[2].ToString(), out col) && row <= playField.GetLength(0) && col <= playField.GetLength(1)) { action = "turn"; } } switch (action) { case "top": ShowLeaderboard(leaderboard); break; case "restart": playField = CreateGameField(); mines = PlaceMines(); DrawPlayfield(playField); gameOver = false; gameStart = true; break; case "exit": Console.WriteLine("Bye, bye, bye!"); break; case "turn": if (mines[row, col] != MineField) { if (mines[row, col] == EmptyField) { NextTurn(playField, mines, row, col); score++; } if (ScoreLimit == score) { gameWon = true; } else { DrawPlayfield(playField); } } else { gameOver = true; } break; default: Console.WriteLine(Environment.NewLine + "Error! Invalid Command." + Environment.NewLine); break; } if (gameOver) { DrawPlayfield(mines); Console.Write( Environment.NewLine + "Hrrrrrr! You played valiantly and your score is {0}. " + "Please enter a nickname: ", score); string name = Console.ReadLine(); PlayerScore player = new PlayerScore(name, score); if (leaderboard.Count < 5) { leaderboard.Add(player); } else { for (int i = 0; i < leaderboard.Count; i++) { if (leaderboard[i].Points < player.Points) { leaderboard.Insert(i, player); leaderboard.RemoveAt(leaderboard.Count - 1); break; } } } leaderboard.Sort((PlayerScore r1, PlayerScore r2) => r2.Name.CompareTo(r1.Name)); leaderboard.Sort((PlayerScore r1, PlayerScore r2) => r2.Points.CompareTo(r1.Points)); ShowLeaderboard(leaderboard); playField = CreateGameField(); mines = PlaceMines(); score = 0; gameOver = false; gameStart = true; } if (gameWon) { Console.WriteLine(Environment.NewLine + "BRAVOOO! You managed to clear all the {0} mines.", ScoreLimit); DrawPlayfield(mines); Console.WriteLine("Enter your name champ: "); string name = Console.ReadLine(); PlayerScore player = new PlayerScore(name, score); leaderboard.Add(player); ShowLeaderboard(leaderboard); playField = CreateGameField(); mines = PlaceMines(); score = 0; gameWon = false; gameStart = true; } }while (action != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.WriteLine("Cyaaaaaaaa."); Console.Read(); }