public static void Main() { const int MaxPoints = 35; const int PlayfieldRows = 5; const int PlayfieldCols = 10; char[,] playfield = GenerateNewPlayfield(PlayfieldRows, PlayfieldCols); char[,] mines = GenerateMines(); List<PlayerScoreGenerator> highScores = new List<PlayerScoreGenerator>(6); string userCommand = string.Empty; int pointsCounter = 0; int currentRow = 0; int currentCol = 0; bool isMine = false; bool hasGameEnded = false; bool hasGameStarted = true; do { if (hasGameStarted) { Console.WriteLine("Let's play \"Minesweeper\". Test your luck finding all squares without a mine." + "enter 'top'to see the highscores, 'restart' - to start a new game, 'exit' - to getta hell out!"); DrawPlayfield(playfield); hasGameStarted = false; } Console.Write("Enter row and column of a square : "); userCommand = Console.ReadLine().Trim(); if (userCommand.Length >= 3) { if (int.TryParse(userCommand[0].ToString(), out currentRow) && int.TryParse(userCommand[2].ToString(), out currentCol) && currentRow <= playfield.GetLength(0) && currentCol <= playfield.GetLength(1)) { userCommand = "turn"; } } switch (userCommand) { case "top": PrintScoreBoard(highScores); break; case "restart": playfield = GenerateNewPlayfield(PlayfieldRows, PlayfieldCols); mines = GenerateMines(); DrawPlayfield(playfield); isMine = false; hasGameStarted = false; break; case "exit": Console.WriteLine("farewell!"); break; case "turn": if (mines[currentRow, currentCol] != '*') { if (mines[currentRow, currentCol] == '-') { MakeNextMove(playfield, mines, currentRow, currentCol); pointsCounter++; } if (MaxPoints == pointsCounter) { hasGameEnded = true; } else { DrawPlayfield(playfield); } } else { isMine = true; } break; default: Console.WriteLine("\nOops! Invalid command.\n"); break; } if (isMine) { DrawPlayfield(mines); Console.Write("\nHrrrrrr! You died a hero with {0} points. " + "Enter your name: ", pointsCounter); string playerName = Console.ReadLine(); PlayerScoreGenerator t = new PlayerScoreGenerator(playerName, pointsCounter); if (highScores.Count < 5) { highScores.Add(t); } else { for (int i = 0; i < highScores.Count; i++) { if (highScores[i].PlayerPoints < t.PlayerPoints) { highScores.Insert(i, t); highScores.RemoveAt(highScores.Count - 1); break; } } } highScores.Sort((PlayerScoreGenerator x, PlayerScoreGenerator y) => y.PlayerName.CompareTo(x.PlayerName)); highScores.Sort((PlayerScoreGenerator x, PlayerScoreGenerator y) => y.PlayerPoints.CompareTo(x.PlayerPoints)); PrintScoreBoard(highScores); playfield = GenerateNewPlayfield(PlayfieldRows, PlayfieldCols); mines = GenerateMines(); pointsCounter = 0; isMine = false; hasGameStarted = true; } if (hasGameEnded) { Console.WriteLine("\nYoo-hooooo! You uncovered 35 squares and you're still in one piece."); DrawPlayfield(mines); Console.WriteLine("Enter your name, dude: "); string playerName = Console.ReadLine(); PlayerScoreGenerator playerScore = new PlayerScoreGenerator(playerName, pointsCounter); highScores.Add(playerScore); PrintScoreBoard(highScores); playfield = GenerateNewPlayfield(PlayfieldRows, PlayfieldCols); mines = GenerateMines(); pointsCounter = 0; hasGameEnded = false; hasGameStarted = true; } } while (userCommand != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.WriteLine("Toodaloo, moth*rf*ckerRrRrRrRrRrRrR."); Console.Read(); }
public static void Main() { const int MaxPoints = 35; const int PlayfieldRows = 5; const int PlayfieldCols = 10; char[,] playfield = GenerateNewPlayfield(PlayfieldRows, PlayfieldCols); char[,] mines = GenerateMines(); List <PlayerScoreGenerator> highScores = new List <PlayerScoreGenerator>(6); string userCommand = string.Empty; int pointsCounter = 0; int currentRow = 0; int currentCol = 0; bool isMine = false; bool hasGameEnded = false; bool hasGameStarted = true; do { if (hasGameStarted) { Console.WriteLine("Let's play \"Minesweeper\". Test your luck finding all squares without a mine." + "enter 'top'to see the highscores, 'restart' - to start a new game, 'exit' - to getta hell out!"); DrawPlayfield(playfield); hasGameStarted = false; } Console.Write("Enter row and column of a square : "); userCommand = Console.ReadLine().Trim(); if (userCommand.Length >= 3) { if (int.TryParse(userCommand[0].ToString(), out currentRow) && int.TryParse(userCommand[2].ToString(), out currentCol) && currentRow <= playfield.GetLength(0) && currentCol <= playfield.GetLength(1)) { userCommand = "turn"; } } switch (userCommand) { case "top": PrintScoreBoard(highScores); break; case "restart": playfield = GenerateNewPlayfield(PlayfieldRows, PlayfieldCols); mines = GenerateMines(); DrawPlayfield(playfield); isMine = false; hasGameStarted = false; break; case "exit": Console.WriteLine("farewell!"); break; case "turn": if (mines[currentRow, currentCol] != '*') { if (mines[currentRow, currentCol] == '-') { MakeNextMove(playfield, mines, currentRow, currentCol); pointsCounter++; } if (MaxPoints == pointsCounter) { hasGameEnded = true; } else { DrawPlayfield(playfield); } } else { isMine = true; } break; default: Console.WriteLine("\nOops! Invalid command.\n"); break; } if (isMine) { DrawPlayfield(mines); Console.Write("\nHrrrrrr! You died a hero with {0} points. " + "Enter your name: ", pointsCounter); string playerName = Console.ReadLine(); PlayerScoreGenerator t = new PlayerScoreGenerator(playerName, pointsCounter); if (highScores.Count < 5) { highScores.Add(t); } else { for (int i = 0; i < highScores.Count; i++) { if (highScores[i].PlayerPoints < t.PlayerPoints) { highScores.Insert(i, t); highScores.RemoveAt(highScores.Count - 1); break; } } } highScores.Sort((PlayerScoreGenerator x, PlayerScoreGenerator y) => y.PlayerName.CompareTo(x.PlayerName)); highScores.Sort((PlayerScoreGenerator x, PlayerScoreGenerator y) => y.PlayerPoints.CompareTo(x.PlayerPoints)); PrintScoreBoard(highScores); playfield = GenerateNewPlayfield(PlayfieldRows, PlayfieldCols); mines = GenerateMines(); pointsCounter = 0; isMine = false; hasGameStarted = true; } if (hasGameEnded) { Console.WriteLine("\nYoo-hooooo! You uncovered 35 squares and you're still in one piece."); DrawPlayfield(mines); Console.WriteLine("Enter your name, dude: "); string playerName = Console.ReadLine(); PlayerScoreGenerator playerScore = new PlayerScoreGenerator(playerName, pointsCounter); highScores.Add(playerScore); PrintScoreBoard(highScores); playfield = GenerateNewPlayfield(PlayfieldRows, PlayfieldCols); mines = GenerateMines(); pointsCounter = 0; hasGameEnded = false; hasGameStarted = true; } }while (userCommand != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.WriteLine("Toodaloo, moth*rf*ckerRrRrRrRrRrRrR."); Console.Read(); }