/// <summary> /// The main. /// </summary> /// <param name="arguments"> /// The arguments. /// </param> private static void Main(string[] arguments) { var currentCommand = string.Empty; var gameField = CreateField(); var bombs = CreateBombs(); var moves = 0; var isDoomed = false; var players = new List<Player>(6); var row = 0; var col = 0; var isNewGame = true; const int MaximumMoves = 35; var areMaximumMovesReached = false; do { if (isNewGame) { Console.WriteLine( "Welcome to \"MineSweeper\". You have to find the cells with no bombs inside. " + "Game commands: 'top' - show current results, 'restart - starts new game, exit - exits the game"); DisplayBoard(gameField); isNewGame = false; } Console.Write("Enter row and column: "); currentCommand = Console.ReadLine().Trim(); if (currentCommand.Length >= 3) { if (int.TryParse(currentCommand[0].ToString(), out row) && int.TryParse(currentCommand[2].ToString(), out col) && row <= gameField.GetLength(0) && col <= gameField.GetLength(1)) { currentCommand = "turn"; } } switch (currentCommand) { case "top": DisplayResult(players); break; case "restart": gameField = CreateField(); bombs = CreateBombs(); DisplayBoard(gameField); isDoomed = false; isNewGame = false; break; case "exit": Console.WriteLine("Bye, bye life, bye, bye happiness!"); break; case "turn": if (bombs[row, col] != '*') { if (bombs[row, col] == '-') { Move(gameField, bombs, row, col); moves++; } if (MaximumMoves == moves) { areMaximumMovesReached = true; } else { DisplayBoard(gameField); } } else { isDoomed = true; } break; default: Console.WriteLine("\nInvalid command!\n"); break; } if (isDoomed) { DisplayBoard(bombs); Console.Write("\nHrrrrrr! You died! Your score is {0} points. " + "Enter you nickname: ", moves); var name = Console.ReadLine(); var player = new Player(name, moves); if (players.Count < 5) { players.Add(player); } else { for (var i = 0; i < players.Count; i++) { if (players[i].Points < player.Points) { players.Insert(i, player); players.RemoveAt(players.Count - 1); break; } } } players.Sort( (Player firstPlayer, Player secondPlayer) => secondPlayer.Name.CompareTo(firstPlayer.Name)); players.Sort( (Player firstPlayer, Player secondPlayer) => secondPlayer.Points.CompareTo(firstPlayer.Points)); DisplayResult(players); gameField = CreateField(); bombs = CreateBombs(); moves = 0; isDoomed = false; isNewGame = true; } if (areMaximumMovesReached) { Console.WriteLine("\nCongratulations! You did 35 moves witout hitting a bomb!."); DisplayBoard(bombs); Console.WriteLine("Enter you nickname: "); var name = Console.ReadLine(); var player = new Player(name, moves); players.Add(player); DisplayResult(players); gameField = CreateField(); bombs = CreateBombs(); moves = 0; areMaximumMovesReached = false; isNewGame = true; } } while (currentCommand != "exit"); Console.WriteLine("Made in Bulgaria - :)"); Console.WriteLine("See ya!."); Console.Read(); }
public static void Main() { string command = string.Empty; char[,] gameField = CreateGameField(); char[,] mines = DeployMines(); int cellsOpened = 0; bool boom = false; var topPlayers = new List<Player>(6); int row = 0; int column = 0; bool startGame = true; bool gameFinished = false; do { if (startGame) { Console.WriteLine("Let's play “Minesweeper”. Try your chance to find the cells without mines." + " Command 'top' shows the scores, 'restart' starts new play, 'exit' to exit and say goodbye!"); DrawField(gameField); startGame = false; } Console.Write("Input row and column: "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out column) && row <= gameField.GetLength(0) && column <= gameField.GetLength(1)) { command = "turn"; } } switch (command) { case "top": PrintScoreBoard(topPlayers); break; case "restart": gameField = CreateGameField(); mines = DeployMines(); DrawField(gameField); boom = false; startGame = false; break; case "exit": Console.WriteLine("bye, bye, bye!"); break; case "turn": if (mines[row, column] != '*') { if (mines[row, column] == '-') { UpdateField(gameField, mines, row, column); cellsOpened++; } if (cellsOpened == MaxEmptyCells) { gameFinished = true; } else { DrawField(gameField); } } else { boom = true; } break; default: Console.WriteLine("\nInvalid command!\n"); break; } if (boom) { DrawField(mines); Console.Write("\nHrrrrrr! Died as a hero with {0} scores. Enter your nickname: ", cellsOpened); string nickname = Console.ReadLine(); var player = new Player(nickname, cellsOpened); if (topPlayers.Count < 5) { topPlayers.Add(player); } else { for (int i = 0; i < topPlayers.Count; i++) { if (topPlayers[i].Points < player.Points) { topPlayers.Insert(i, player); topPlayers.RemoveAt(topPlayers.Count - 1); break; } } } topPlayers.Sort((Player r1, Player r2) => r2.Name.CompareTo(r1.Name)); topPlayers.Sort((Player r1, Player r2) => r2.Points.CompareTo(r1.Points)); PrintScoreBoard(topPlayers); gameField = CreateGameField(); mines = DeployMines(); cellsOpened = 0; boom = false; startGame = true; } if (gameFinished) { Console.WriteLine("\nGood for you! You opened 35 cells without a drop of blood."); DrawField(mines); Console.WriteLine("Your name: "); string name = Console.ReadLine(); var score = new Player(name, cellsOpened); topPlayers.Add(score); PrintScoreBoard(topPlayers); gameField = CreateGameField(); mines = DeployMines(); cellsOpened = 0; gameFinished = false; startGame = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.WriteLine("Seeee you laaaaaaaaateeeeeeeeer."); Console.Read(); }
private static void Main() { do { if (flag) { Console.WriteLine( "Hajde da igraem na “Mini4KI”. Probvaj si kasmeta da otkriesh poleteta bez mini4ki." + " Komanda 'top' pokazva klasiraneto, 'restart' po4va nova igra, 'exit' izliza i hajde 4ao!"); PrintGameBoard(gameBoard); flag = false; } Console.Write("Daj red i kolona : "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out red) && int.TryParse(command[2].ToString(), out kolona) && red <= gameBoard.GetLength(0) && kolona <= gameBoard.GetLength(1)) { command = "turn"; } } switch (command) { case "top": Clasification(players); break; case "restart": gameBoard = CreateGameBoard(); bombs = InsertBombs(); PrintGameBoard(gameBoard); grum = false; flag = false; break; case "exit": Console.WriteLine("4a0, 4a0, 4a0!"); break; case "turn": if (bombs[red, kolona] != '*') { if (bombs[red, kolona] == '-') { tisinahod(gameBoard, bombs, red, kolona); pointsCounter++; } if (Max == pointsCounter) { flag2 = true; } else { PrintGameBoard(gameBoard); } } else { grum = true; } break; default: Console.WriteLine("\nGreshka! nevalidna Komanda\n"); break; } if (grum) { PrintGameBoard(bombs); Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " + "Daj si niknejm: ", pointsCounter); string niknejm = Console.ReadLine(); Player t = new Player(niknejm, pointsCounter); if (players.Count < 5) { players.Add(t); } else { for (int i = 0; i < players.Count; i++) { if (players[i].Points < t.Points) { players.Insert(i, t); players.RemoveAt(players.Count - 1); break; } } } players.Sort((Player r1, Player r2) => r2.Name.CompareTo(r1.Name)); players.Sort((Player r1, Player r2) => r2.Points.CompareTo(r1.Points)); Clasification(players); gameBoard = CreateGameBoard(); bombs = InsertBombs(); pointsCounter = 0; grum = false; flag = true; } if (flag2) { Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv."); PrintGameBoard(bombs); Console.WriteLine("Daj si imeto, batka: "); string imeee = Console.ReadLine(); Player player = new Player(imeee, pointsCounter); players.Add(player); Clasification(players); gameBoard = CreateGameBoard(); bombs = InsertBombs(); pointsCounter = 0; flag2 = false; flag = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.WriteLine("AREEEEEEeeeeeee."); Console.Read(); }
public static void Main() { const int MovesForWin = 35; string command = string.Empty; char[,] field = CreatePlayField(); char[,] mines = PlaceMines(); int counter = 0; bool doesExplode = false; var players = new List<Player>(6); int row = 0; int column = 0; bool displayGameInstructions = true; bool isGameWon = false; do { if (displayGameInstructions) { Console.WriteLine("Let's play \"Minesweeper\"! Try to locate all the fileds without mines on them!"); Console.WriteLine("Enter \"top\" to display the rankings, \"restart\" for a new game, or \"exit\" to leave the game"); RenderPlayField(field); displayGameInstructions = false; } Console.Write("Please enter a row and a column: "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out column) && row <= field.GetLength(0) && column <= field.GetLength(1)) { command = "turn"; } } switch (command) { case "top": GetRanking(players); break; case "restart": field = CreatePlayField(); mines = PlaceMines(); RenderPlayField(field); doesExplode = false; displayGameInstructions = false; break; case "exit": Console.WriteLine("See you!"); break; case "turn": if (mines[row, column] != '*') { if (mines[row, column] == '-') { MakeMove(field, mines, row, column); counter++; } if (MovesForWin == counter) { isGameWon = true; } else { RenderPlayField(field); } } else { doesExplode = true; } break; default: Console.WriteLine("Invalid command!"); break; } if (doesExplode) { RenderPlayField(mines); Console.Write("Score: {0} points. " + "Please enter nickname: ", counter); string nickname = Console.ReadLine(); Player newPlayer = new Player(nickname, counter); if (players.Count < 5) { players.Add(newPlayer); } else { for (int i = 0; i < players.Count; i++) { if (players[i].Points < newPlayer.Points) { players.Insert(i, newPlayer); players.RemoveAt(players.Count - 1); break; } } } players.Sort((Player firstPlayer, Player secondPlayer) => secondPlayer.Name.CompareTo(firstPlayer.Name)); players.Sort((Player firstPlayer, Player secondPlayer) => secondPlayer.Points.CompareTo(firstPlayer.Points)); GetRanking(players); field = CreatePlayField(); mines = PlaceMines(); counter = 0; doesExplode = false; displayGameInstructions = true; } if (isGameWon) { Console.WriteLine("Good Work! You located all the 35 safe fields!"); RenderPlayField(mines); Console.WriteLine("Please enter your name: "); string name = Console.ReadLine(); var player = new Player(name, counter); players.Add(player); GetRanking(players); field = CreatePlayField(); mines = PlaceMines(); counter = 0; isGameWon = false; displayGameInstructions = true; } } while (command != "exit"); Console.WriteLine("Hope you enjoyed the game!"); Console.WriteLine("Thank you for playing!"); Console.Read(); }