public static void Main() { const int BOARD_ROWS = 5; const int BOARD_COLS = 10; const int MAX_OPENED_CELLS = 35; int openedCells = 0; char[,] questionsPlayBoard = CreatePlayBoard('?', BOARD_ROWS, BOARD_COLS); char[,] bombsPlayBoard = PutBombs(BOARD_ROWS, BOARD_COLS); List<Score> highScores = new List<Score>(6); string command = string.Empty; int row = 0; int col = 0; bool isBombOpened = false; bool isPlayBoardDrawn = false; bool allCellsOpened = false; do { if (!isPlayBoardDrawn) { Console.WriteLine("Let's play Minesweeper. Try your luck to find all fields without mines. " + "Command 'top' shows high scores, 'restart' initiates a new game, 'exit' exits the application."); DrawPlayBoard(questionsPlayBoard); isPlayBoardDrawn = true; } Console.Write("Enter row and col, separated by a space: "); command = Console.ReadLine().Trim(); if (command.Length == 3) { if (int.TryParse(command[0].ToString(), out row) && string.IsNullOrWhiteSpace(command[1].ToString()) && int.TryParse(command[2].ToString(), out col) && row < questionsPlayBoard.GetLength(0) && col < questionsPlayBoard.GetLength(1)) { command = "turn"; } } switch (command) { case "top": DrawHighScores(highScores); break; case "restart": questionsPlayBoard = CreatePlayBoard('?', BOARD_ROWS, BOARD_COLS); bombsPlayBoard = PutBombs(BOARD_ROWS, BOARD_COLS); DrawPlayBoard(questionsPlayBoard); isBombOpened = false; isPlayBoardDrawn = true; break; case "exit": Console.WriteLine("Bye, bye!"); break; case "turn": if (bombsPlayBoard[row, col] != '*') { if (bombsPlayBoard[row, col] == '-') { UpdatePlayBoards(questionsPlayBoard, bombsPlayBoard, row, col); openedCells++; } if (MAX_OPENED_CELLS == openedCells) { allCellsOpened = true; } else { DrawPlayBoard(questionsPlayBoard); } } else { isBombOpened = true; } break; default: Console.WriteLine("\nError! Invalid choise!\n"); break; } if (isBombOpened) { DrawPlayBoard(bombsPlayBoard); Console.Write("\nYou died with {0} points. Enter your name: ", openedCells); string nickname = Console.ReadLine(); Score score = new Score(nickname, openedCells); if (highScores.Count < 5) { highScores.Add(score); } else { for (int i = 0; i < highScores.Count; i++) { if (highScores[i].Points < score.Points) { highScores.Insert(i, score); highScores.RemoveAt(highScores.Count - 1); break; } } } highScores.Sort((Score x1, Score x2) => x2.Name.CompareTo(x1.Name)); highScores.Sort((Score x1, Score x2) => x2.Points.CompareTo(x1.Points)); DrawHighScores(highScores); questionsPlayBoard = CreatePlayBoard('?', BOARD_ROWS, BOARD_COLS); bombsPlayBoard = PutBombs(BOARD_ROWS, BOARD_COLS); openedCells = 0; isBombOpened = false; isPlayBoardDrawn = false; } if (allCellsOpened) { Console.WriteLine("\nCongratulations! You have opened all 35 cells without stepping on mine."); DrawPlayBoard(bombsPlayBoard); Console.WriteLine("Enter your name: "); string name = Console.ReadLine(); Score score = new Score(name, openedCells); highScores.Add(score); DrawHighScores(highScores); questionsPlayBoard = CreatePlayBoard('?', BOARD_ROWS, BOARD_COLS); bombsPlayBoard = PutBombs(BOARD_ROWS, BOARD_COLS); openedCells = 0; allCellsOpened = false; isPlayBoardDrawn = false; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria!"); Console.Read(); }
public static void Main() { char[,] gameField = InitializeGameField(); char[,] minesField = InitializeMinesField(); List<Score> topScores = new List<Score>(6); int points = 0; int row = 0; int col = 0; bool isStarting = true; bool hasHitMine = false; bool hasMaxPoints = false; string command = string.Empty; do { if (isStarting) { Console.WriteLine("***Let's play \"Minesweeper\"! Try your luck finding all cells without mines***"); Console.WriteLine("---Enter 'top' to view the top scores board---"); Console.WriteLine("---Enter 'restart' to start a new game---"); Console.WriteLine("---Enter 'exit' to exit the game---"); PrintGameField(gameField); isStarting = false; } Console.Write("Enter a row and a column separated by a space: "); command = Console.ReadLine().Trim(); string[] coordinates = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (coordinates.Length == 2) { if (int.TryParse(coordinates[0], out row) && int.TryParse(coordinates[1], out col) && row >= 0 && col >= 0 && row < gameField.GetLength(0) && col < gameField.GetLength(1)) { command = "turn"; } } switch (command) { case "top": PrintTopScoresBoard(topScores); break; case "restart": gameField = InitializeGameField(); minesField = InitializeMinesField(); PrintGameField(gameField); hasHitMine = false; isStarting = false; break; case "exit": Console.WriteLine("Goodbye! :)"); break; case "turn": if (minesField[row, col] != '*') { if (minesField[row, col] == '-') { UpdateFields(gameField, minesField, row, col); points++; } if (points == MaxPoints) { hasMaxPoints = true; } else { PrintGameField(gameField); } } else { hasHitMine = true; } break; default: Console.WriteLine("\nInvalid command! Try again...\n"); break; } if (hasHitMine) { PrintGameField(minesField); Console.Write("\nGame over! Your score is {0} points. Enter your name: ", points); string playerName = Console.ReadLine(); Score score = new Score(playerName, points); if (topScores.Count < 5) { topScores.Add(score); } else { for (int index = 0; index < topScores.Count; index++) { if (topScores[index].Points < score.Points) { topScores.Insert(index, score); topScores.RemoveAt(topScores.Count - 1); break; } } } topScores.Sort((Score r1, Score r2) => r2.Name.CompareTo(r1.Name)); topScores.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points)); PrintTopScoresBoard(topScores); gameField = InitializeGameField(); minesField = InitializeMinesField(); points = 0; hasHitMine = false; isStarting = true; } if (hasMaxPoints) { Console.WriteLine("\nCongratulations! You opened all 35 cells without mines!"); PrintGameField(minesField); Console.WriteLine("Enter your name: "); string playerName = Console.ReadLine(); Score score = new Score(playerName, points); topScores.Add(score); PrintTopScoresBoard(topScores); gameField = InitializeGameField(); minesField = InitializeMinesField(); points = 0; hasMaxPoints = false; isStarting = true; } } while (command != "exit"); Console.WriteLine("Minesweeper v1.0"); Console.WriteLine("Copyright (c) 2013 Telerik Academy. All rights reserved."); Console.Read(); }
public static void Main() { const int MaxFieldsWithoutMine = 35; string currentCommand = string.Empty; char[,] field = CreateField(); char[,] mines = PutMines(); int pointsCounter = 0; int row = 0; int col = 0; bool isOnMine = false; bool isNewGame = true; bool isGameWon = false; List<Score> highscore = new List<Score>(6); do { if (isNewGame) { Console.WriteLine("Let's play Minesweeper. Take your chance to find the fields without mines." + "Command 'top' shows the highscore, 'restart' starts a new game, 'exit' stops the game!"); PrintPlayground(field); isNewGame = false; } Console.Write("Enter a row and a 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 <= field.GetLength(0) && col <= field.GetLength(1)) { currentCommand = "turn"; } } switch (currentCommand) { case "top": GetHighscore(highscore); break; case "restart": field = CreateField(); mines = PutMines(); PrintPlayground(field); isOnMine = false; isNewGame = false; break; case "exit": Console.WriteLine("Good buy!"); break; case "turn": if (mines[row, col] != '*') { if (mines[row, col] == '-') { MakeMove(field, mines, row, col); pointsCounter++; } if (MaxFieldsWithoutMine == pointsCounter) { isGameWon = true; } else { PrintPlayground(field); } } else { isOnMine = true; } break; default: Console.WriteLine("\nError! Invalid command!\n"); break; } if (isOnMine) { PrintPlayground(mines); string playerName = Console.ReadLine(); Score score = new Score(playerName, pointsCounter); Console.Write("\nYou died like a hero with {0} points. " + "Write your name: ", pointsCounter); if (highscore.Count < 5) { highscore.Add(score); } else { for (int i = 0; i < highscore.Count; i++) { if (highscore[i].Points < score.Points) { highscore.Insert(i, score); highscore.RemoveAt(highscore.Count - 1); break; } } } highscore.Sort((Score r1, Score r2) => r2.Name.CompareTo(r1.Name)); highscore.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points)); GetHighscore(highscore); field = CreateField(); mines = PutMines(); pointsCounter = 0; isOnMine = false; isNewGame = true; } if (isGameWon) { Console.WriteLine("\nGood job! You steped on 35 fields without succesfully!"); PrintPlayground(mines); Console.WriteLine("Write your name: "); string playerName = Console.ReadLine(); Score score = new Score(playerName, pointsCounter); highscore.Add(score); GetHighscore(highscore); field = CreateField(); mines = PutMines(); pointsCounter = 0; isGameWon = false; isNewGame = true; } } while (currentCommand != "exit"); Console.WriteLine("Thanks for playing !"); Console.Read(); }
private static void Main() { char[,] playField = CreatePlayField(); char[,] bombField = CreateBombField(); List<Score> champions = new List<Score>(); string command = string.Empty; int row = 0; int col = 0; int turnCounter = 0; bool isFirstTurn = true; bool boom = false; bool isLastTurn = false; do { if (isFirstTurn) { Console.WriteLine("Let's play 'Mines'! " + "Try your luck finding fields without bombs." + " Command 'top' shows the standing, 'restart' starts" + " a new game and 'exit' closes the game and says " + "'Goodbye and thank you !'"); PrintField(playField); isFirstTurn = false; } Console.Write("Please, enter row and column (separated by space) : "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out col) && row <= playField.GetLength(0) && col <= playField.GetLength(1)) { command = "turn"; } } switch (command) { case "top": Standing(champions); break; case "restart": playField = CreatePlayField(); bombField = CreateBombField(); PrintField(playField); boom = false; isFirstTurn = false; break; case "exit": Console.WriteLine("Bye, bye!"); break; case "turn": if (bombField[row, col] != '*') { if (bombField[row, col] == '-') { SetSurroundingBombsCount(playField, bombField, row, col); turnCounter++; } if (MAX == turnCounter) { isLastTurn = true; } else { PrintField(playField); } } else { boom = true; } break; default: Console.WriteLine( Environment.NewLine + "Error! Invalid command, please try again" + Environment.NewLine); break; } if (boom) { PrintField(bombField); Console.Write( Environment.NewLine + "Grrrrr! You died heroically with {0} points. " + "Please, give your nickname : ", turnCounter); string nickName = Console.ReadLine(); Score result = new Score(nickName, turnCounter); if (champions.Count < 5) { champions.Add(result); } else { for (int i = 0; i < champions.Count; i++) { if (champions[i].Points < result.Points) { champions.Insert(i, result); champions.RemoveAt(champions.Count - 1); break; } } } // Sorting the current result by name and points champions.Sort((Score firstResult, Score secondResult) => secondResult.Name.CompareTo(firstResult.Name)); champions.Sort((Score firstResult, Score secondResult) => secondResult.Points.CompareTo(firstResult.Points)); Standing(champions); // Setting the variables to their default values playField = CreatePlayField(); bombField = CreateBombField(); turnCounter = 0; boom = false; isFirstTurn = true; } if (isLastTurn) { Console.WriteLine(Environment.NewLine + "Well done ! You've reached to the end."); PrintField(bombField); Console.WriteLine("Give your nickname, tough guy : "); string nickName = Console.ReadLine(); Score result = new Score(nickName, turnCounter); champions.Add(result); Standing(champions); // Resetting playField = CreatePlayField(); bombField = CreateBombField(); turnCounter = 0; isLastTurn = false; isFirstTurn = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria motherfuckers!"); Console.WriteLine("Yeah!!!"); Console.Read(); }
public static void Main(string[] args) { string command = string.Empty; char[,] field = CreateField(); char[,] bombs = InitializeBomb(); int pointsCount = 0; bool isGameOver = false; List<Score> players = new List<Score>(6); int row = 0; int col = 0; bool isNewGameStarted = true; const int MAX_POINTS = 35; bool maxPoints = false; do { if (isNewGameStarted) { Console.WriteLine("Let's play “Minesweapers”. You should find out all fields without mines" + ": with 'top' you can view the scorelist, 'restart' to start a new game , 'exit' to exit."); DrawField(field); isNewGameStarted = false; } Console.Write("Enter row and col(ex. 1,2) or /top/restart/exit : "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out col) && row <= field.GetLength(0) && col <= field.GetLength(1)) { command = "turn"; } } switch (command) { case "top": ShowTopPlayers(players); break; case "restart": field = CreateField(); bombs = InitializeBomb(); DrawField(field); isGameOver = false; isNewGameStarted = false; break; case "exit": Console.WriteLine("Bye! See you soon!"); break; case "turn": if (bombs[row, col] != '*') { if (bombs[row, col] == '-') { NextMove(field, bombs, row, col); pointsCount++; } if (MAX_POINTS == pointsCount) { maxPoints = true; } else { DrawField(field); } } else { isGameOver = true; } break; default: Console.WriteLine("\nThere's no such command\n"); break; } if (isGameOver) { DrawField(bombs); Console.Write("\nGame Over! Score:{0}" + "\nEnter your name: ", pointsCount); string name = Console.ReadLine(); Score t = new Score(name, pointsCount); 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((Score r1, Score r2) => r2.Name.CompareTo(r1.Name)); players.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points)); ShowTopPlayers(players); field = CreateField(); bombs = InitializeBomb(); pointsCount = 0; isGameOver = false; isNewGameStarted = true; } if (maxPoints) { Console.WriteLine("\nCongratulation! You have the MAX Score!"); DrawField(bombs); Console.WriteLine("Enter your name: "); string name = Console.ReadLine(); Score points = new Score(name, pointsCount); players.Add(points); ShowTopPlayers(players); field = CreateField(); bombs = InitializeBomb(); pointsCount = 0; maxPoints = false; isNewGameStarted = true; } } while (command != "exit"); Console.Read(); }
static void Main(string[] args) { char[,] gameField = CreateGameField(); char[,] bombField = CreateBombField(); int row = 0; int col = 0; int currentScore = 0; string command = string.Empty; bool newGame = true; bool stepOnBomb = false; bool win = false; do { if (newGame) { PrintHelp(); PrintGameField(gameField); newGame = false; } Console.Write("Enter row and col or command: "); command = Console.ReadLine().Trim(); string[] coordinates = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (coordinates.Length == 2) { if (int.TryParse(coordinates[0], out row) && int.TryParse(coordinates[1], out col) && row < BoardRows && col < BoardCols && row >= 0 && col >= 0) { command = "OpenCell"; } } switch (command) { case "top": { PrintTopScores(TopScores); break; } case "restart": { gameField = CreateGameField(); bombField = CreateBombField(); PrintGameField(gameField); stepOnBomb = false; newGame = false; break; } case "exit": { Console.WriteLine("Goodbye!"); break; } case "OpenCell": if (bombField[row, col] != BombSymbol) { if (bombField[row, col] == EmptyCellSymbol) { PrintSurroundingBombCount(gameField, bombField, row, col); currentScore++; } if (currentScore == MaxScore) { win = true; } else { PrintGameField(gameField); } } else { stepOnBomb = true; } break; default: { Console.WriteLine("\nInvalid Command! Try again.\n"); break; } } if (stepOnBomb) { PrintGameField(bombField); Console.Write("\nYou step on bomb. Your points: {0}. Enter your name: ", currentScore); string playerName = Console.ReadLine(); Score currentPlayerScore = new Score(playerName, currentScore); SavePlayerScore(currentPlayerScore); PrintTopScores(TopScores); gameField = CreateGameField(); bombField = CreateBombField(); currentScore = 0; stepOnBomb = false; newGame = true; } if (win) { Console.WriteLine("\nCongratulations! You Won."); PrintGameField(bombField); Console.WriteLine("Enter your name: "); string playerName = Console.ReadLine(); Score currentPlayerScore = new Score(playerName, currentScore); TopScores.Add(currentPlayerScore); PrintTopScores(TopScores); gameField = CreateGameField(); bombField = CreateBombField(); currentScore = 0; win = false; newGame = true; } } while (command != "exit"); Console.WriteLine("Just Minesweeper \u00A9"); Console.Read(); }
private static void Main(string[] args) { string command = string.Empty; char[,] field = CreateGameField(); char[,] bombs = InputBombs(); int counter = 0; bool isBoom = false; List<Score> champions = new List<Score>(6); int row = 0; int col = 0; bool hasLost = true; const int max = 35; bool hasWon = false; do { if (hasLost) { Console.WriteLine( "Let's Play Minesweeper. Try finding the field without mines." + " The command 'top' shows the ShowScoreboard, 'restart' restarts the game, 'exit' quits the current game!"); DisplayGameField(field); hasLost = false; } Console.Write("Please insert a row and col: "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out col) && row <= field.GetLength(0) && col <= field.GetLength(1)) { command = "turn"; } } switch (command) { case "top": ShowScoreboard(champions); break; case "restart": field = CreateGameField(); bombs = InputBombs(); DisplayGameField(field); isBoom = false; hasLost = false; break; case "exit": Console.WriteLine("Farewell, stranger!"); break; case "turn": if (bombs[row, col] != '*') { if (bombs[row, col] == '-') { ChangePlayerTurn(field, bombs, row, col); counter++; } if (max == counter) { hasWon = true; } else { DisplayGameField(field); } } else { isBoom = true; } break; default: Console.WriteLine("\nError. Wrong command.\n"); break; } if (isBoom) { DisplayGameField(bombs); Console.Write("\nSuch a tragic death... " + "Well, atleast give us your nickname: ", counter); string nickname = Console.ReadLine(); Score currentScore = new Score(nickname, counter); if (champions.Count < 5) { champions.Add(currentScore); } else { for (int i = 0; i < champions.Count; i++) { if (champions[i].Points < currentScore.Points) { champions.Insert(i, currentScore); champions.RemoveAt(champions.Count - 1); break; } } } champions.Sort((Score r1, Score r2) => r2.Player.CompareTo(r1.Player)); champions.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points)); ShowScoreboard(champions); field = CreateGameField(); bombs = InputBombs(); counter = 0; isBoom = false; hasLost = true; } if (hasWon) { Console.WriteLine("\nCongratulations! You have successfully found all the mines on the field."); DisplayGameField(bombs); Console.WriteLine("Plase, insert your name: "); string name = Console.ReadLine(); Score points = new Score(name, counter); champions.Add(points); ShowScoreboard(champions); field = CreateGameField(); bombs = InputBombs(); counter = 0; hasWon = false; hasLost = true; } } while (command != "exit"); Console.WriteLine("This game has been created in Bulgaria."); Console.WriteLine("Farewell."); Console.Read(); }
public static void Main(string[] args) { const int TOTAL_SAFE_CELLS = 35; string command = string.Empty; char[,] field = InitiaiteGamingField(); char[,] bombs = PlaceBombs(); int currentPoints = 0; bool mineDetonated = false; List<Score> highScores = new List<Score>(6); int row = 0; int column = 0; bool isNewGame = true; bool fieldCleared = false; do { if (isNewGame) { Console.WriteLine("Lets play 'Minesweeper'! Try to find all mine-free fields! " + "'top' displays the high scores, 'restart' starts a new game, 'exit' quits the application. " + "Good luck!"); PrintField(field); isNewGame = false; } Console.Write("Enter 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 <= field.GetLength(0) && column <= field.GetLength(1)) { command = "turn"; } } switch (command) { case "top": PrintHighScores(highScores); break; case "restart": field = InitiaiteGamingField(); bombs = PlaceBombs(); PrintField(field); mineDetonated = false; isNewGame = false; break; case "exit": Console.WriteLine("Bye, bye!"); break; case "turn": if (bombs[row, column] != '*') { if (bombs[row, column] == '-') { UpdateField(field, bombs, row, column); currentPoints++; } if (currentPoints == TOTAL_SAFE_CELLS) { fieldCleared = true; } else { PrintField(field); } } else { mineDetonated = true; } break; default: Console.WriteLine(Environment.NewLine + "Invalid command!" + Environment.NewLine); break; } if (mineDetonated) { PrintField(bombs); Console.Write( Environment.NewLine + "You died honorably with {0} points. " + "Enter your name: ", currentPoints); string playerName = Console.ReadLine(); Score playerScore = new Score(playerName, currentPoints); if (highScores.Count < 5) { highScores.Add(playerScore); } else { for (int i = 0; i < highScores.Count; i++) { if (highScores[i].Points < playerScore.Points) { highScores.Insert(i, playerScore); highScores.RemoveAt(highScores.Count - 1); break; } } } highScores.Sort((Score r1, Score r2) => r2.Name.CompareTo(r1.Name)); highScores.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points)); PrintHighScores(highScores); field = InitiaiteGamingField(); bombs = PlaceBombs(); currentPoints = 0; mineDetonated = false; isNewGame = true; } if (fieldCleared) { Console.WriteLine( Environment.NewLine + "Congratulations! You revealed {0} cells without detonating a mine!", TOTAL_SAFE_CELLS); PrintField(bombs); Console.WriteLine("Enter your name: "); string playerName = Console.ReadLine(); Score playerScore = new Score(playerName, currentPoints); highScores.Add(playerScore); PrintHighScores(highScores); field = InitiaiteGamingField(); bombs = PlaceBombs(); currentPoints = 0; fieldCleared = false; isNewGame = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria!"); Console.Read(); }
public static void Main() { const int emptyFields = 35; string command = string.Empty; char[,] field = createGamingField(); char[,] bombs = putBombs(); int counter = 0; bool hitBomb = false; List<Score> champions = new List<Score>(6); int row = 0; int col = 0; bool isSGameOver = true; bool isGameEnd = false; do { if (isSGameOver) { Console.WriteLine("Let's play “Minesweeper”. Try your luck to find all fields without mines." + "Command 'top' shows ranking, 'restart' start new game, 'exit' quit game and bye-bye!"); dump(field); isSGameOver = false; } Console.Write("Write 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 col) && row <= field.GetLength(0) && col <= field.GetLength(1)) { command = "turn"; } } switch (command) { case "top": Ranking(champions); break; case "restart": field = createGamingField(); bombs = putBombs(); dump(field); hitBomb = false; isSGameOver = false; break; case "exit": Console.WriteLine("Bye-bye!"); break; case "turn": if (bombs[row, col] != '*') { if (bombs[row, col] == '-') { tisinahod(field, bombs, row, col); counter++; } if (emptyFields == counter) { isGameEnd = true; } else { dump(field); } } else { hitBomb = true; } break; default: Console.WriteLine("\nError! Invalid command\n"); break; } if (hitBomb) { dump(bombs); Console.Write("\nHrrrrrr! Game over! {0} points. " + "Write your alias: ", counter); string alias = Console.ReadLine(); Score rank = new Score(alias, counter); if (champions.Count < 5) { champions.Add(rank); } else { for (int i = 0; i < champions.Count; i++) { if (champions[i].Points < rank.Points) { champions.Insert(i, rank); champions.RemoveAt(champions.Count - 1); break; } } } champions.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.Name.CompareTo(firstPlayer.Name)); champions.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.Points.CompareTo(firstPlayer.Points)); Ranking(champions); field = createGamingField(); bombs = putBombs(); counter = 0; hitBomb = false; isSGameOver = true; } if (isGameEnd) { Console.WriteLine("\n Congratulations! You open 35 fields."); dump(bombs); Console.WriteLine("Write your alias: "); string alias = Console.ReadLine(); Score rank = new Score(alias, counter); champions.Add(rank); Ranking(champions); field = createGamingField(); bombs = putBombs(); counter = 0; isGameEnd = false; isSGameOver = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.WriteLine("Bye-bye!"); Console.Read(); }
static void Main(string[] arguments) { string command = string.Empty; char[,] gameField = CreateField(); char[,] bombs = CreateBombs(); int actionCounter = 0; bool hitMine = false; List<Score> topScores = new List<Score>(6); int row = 0; int column = 0; bool initialization = true; bool gameIsWon = false; do { if (initialization) { HelpMenu(); Console.Write("Press the \"any\" key to continue."); Console.ReadKey(); DrawField(gameField); initialization = false; } Console.Write("Enter \"<x>\" \"<y>\" coordiantes or a command: "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out column)) { if (row < gameField.GetLength(0) && column < gameField.GetLength(1)) { command = "turn"; } else { command = "InvalidCoordinate"; } } } switch (command) { case "top": PrintScores(topScores); break; case "restart": gameField = CreateField(); bombs = CreateBombs(); DrawField(gameField); hitMine = false; initialization = false; Console.Clear(); break; case "exit": Console.WriteLine("Bye, bye, bye!"); break; case "turn": if (bombs[row, column] != '*') { if (bombs[row, column] == '-') { PlayerAction(gameField, bombs, row, column); actionCounter++; } if (MAX_SIZE_OF_FIELD == actionCounter) { gameIsWon = true; } else { DrawField(gameField); } } else { hitMine = true; } break; case "InvalidCoordinate": Console.WriteLine("\nInvalid coordinate!\n"); break; case "help": HelpMenu(); break; default: Console.WriteLine("\nInvalid command!\n"); break; } if (hitMine) { DrawField(bombs); Console.Write("\nYou have ended your game with {0} actions. " + "Enter your nickname : ", actionCounter); string nickname = Console.ReadLine(); Score curowentScore = new Score(nickname, actionCounter); if (topScores.Count < 5) { topScores.Add(curowentScore); } else { for (int i = 0; i < topScores.Count; i++) { if (topScores[i].Points < curowentScore.Points) { topScores.Insert(i, curowentScore); topScores.RemoveAt(topScores.Count - 1); break; } } } topScores.Sort((Score firstScore, Score secondScore) => secondScore.Name.CompareTo(firstScore.Name)); topScores.Sort((Score firstScore, Score secondScore) => secondScore.Points.CompareTo(firstScore.Points)); PrintScores(topScores); gameField = CreateField(); bombs = CreateBombs(); actionCounter = 0; hitMine = false; initialization = true; } if (gameIsWon) { Console.WriteLine("\nCongratulations you made it through the mine field!"); DrawField(bombs); Console.WriteLine("Enter your nickname: "); string nickName = Console.ReadLine(); Score curowentScore = new Score(nickName, actionCounter); topScores.Add(curowentScore); PrintScores(topScores); gameField = CreateField(); bombs = CreateBombs(); actionCounter = 0; gameIsWon = false; initialization = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.Read(); }
public static void Main() { const int MaxScore = 35; List<Score> champions = new List<Score>(6); string command = string.Empty; char[,] board = CreateMineField(); char[,] mineField = PlaceBombs(); int score = 0; int row = 0; int col = 0; bool hitBomb = false; bool isNewGame = true; bool hasCompletedGame = false; do { if (isNewGame) { Console.WriteLine("Lets play Minesweeper, try your luck finding the mines. The command \'top\' shows the Top Score, \'restart\' starts a New Game, \'exit\' quits the game!"); DisplayBoard(board); isNewGame = false; } Console.Write("Enter row and colomn (separated by blankspace!) : "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out col) && row <= board.GetLength(0) && col <= board.GetLength(1)) { command = "turn"; } } switch (command) { case "top": TopScore(champions); break; case "restart": board = CreateMineField(); mineField = PlaceBombs(); DisplayBoard(board); hitBomb = false; isNewGame = false; break; case "exit": Console.WriteLine("Good bye!"); break; case "turn": if (mineField[row, col] != '*') { if (mineField[row, col] == '-') { NextTurn(board, mineField, row, col); score++; } if (MaxScore == score) { hasCompletedGame = true; } else { DisplayBoard(board); } } else { hitBomb = true; } break; default: Console.WriteLine("\nInvalid Command!\n"); break; } if (hitBomb) { DisplayBoard(mineField); Console.Write("\nBoom! You died. You have {0} points.", score); Console.Write("Your nickname: "); string name = Console.ReadLine(); Score playerScore = new Score(name, score); if (champions.Count < 5) { champions.Add(playerScore); } else { for (int i = 0; i < champions.Count; i++) { if (champions[i].Points < playerScore.Points) { champions.Insert(i, playerScore); champions.RemoveAt(champions.Count - 1); break; } } } champions.Sort((Score first, Score second) => second.Name.CompareTo(first.Name)); champions.Sort((Score first, Score second) => second.Points.CompareTo(first.Points)); TopScore(champions); board = CreateMineField(); mineField = PlaceBombs(); score = 0; hitBomb = false; isNewGame = true; } if (hasCompletedGame) { Console.WriteLine("\nCongratulations, you won!"); DisplayBoard(mineField); Console.WriteLine("Please enter your name: "); string name = Console.ReadLine(); Score playerScores = new Score(name, score); champions.Add(playerScores); TopScore(champions); board = CreateMineField(); mineField = PlaceBombs(); score = 0; hasCompletedGame = false; isNewGame = true; } } while (command != "exit"); Console.Read(); }
/// <summary> /// Standard program entry /// </summary> internal static void Main() { char[,] playField = CreatePlayField(FieldRows, FieldCols); char[,] mineField = CreateMineField(FieldRows, FieldCols, Mines); int row = 0; int col = 0; int playerScore = 0; bool isStarting = true; bool isHitMine = false; bool isWon = false; string command = string.Empty; List <Score> bestScores = new List <Score>(TopResultsToKeep); do { if (isStarting) { PrintStartText(); PrintGameInterface(playField); isStarting = false; } Console.Write("Please input row and col : "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out col) && row <= playField.GetLength(0) && col <= playField.GetLength(1)) { command = "checkField"; } } switch (command) { case "top": { PrintTopScores(bestScores); break; } case "restart": { playField = CreatePlayField(FieldRows, FieldCols); mineField = CreateMineField(FieldRows, FieldCols, Mines); PrintGameInterface(playField); isHitMine = false; break; } case "exit": { Console.WriteLine("The end. Bye Bye!"); break; } case "checkField": { if (mineField[row, col] != '*') { if (mineField[row, col] == '-') { UpdateFields(playField, mineField, row, col); playerScore++; } if (MaxScore == playerScore) { isWon = true; } else { PrintGameInterface(playField); } } else { isHitMine = true; } break; } default: { Console.WriteLine(Environment.NewLine + "Error! Invalid Command!" + Environment.NewLine); break; } } if (isHitMine) { PrintGameInterface(mineField); Console.Write(Environment.NewLine + "You just hit mine. Game over! Your Score: {0}", playerScore); Console.WriteLine("Please input your Name: "); string playerName = Console.ReadLine(); Score score = new Score(playerName, playerScore); if (bestScores.Count < TopResultsToKeep - 1) { bestScores.Add(score); } else { for (int i = 0; i < bestScores.Count; i++) { if (bestScores[i].Points < score.Points) { bestScores.Insert(i, score); bestScores.RemoveAt(bestScores.Count - 1); break; } } } bestScores.Sort((Score r1, Score r2) => r2.PlayerName.CompareTo(r1.PlayerName)); bestScores.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points)); PrintTopScores(bestScores); playField = CreatePlayField(FieldRows, FieldCols); mineField = CreateMineField(FieldRows, FieldCols, Mines); playerScore = 0; isHitMine = false; isStarting = true; } if (isWon) { Console.WriteLine(Environment.NewLine + "Congratulation!You Won!"); PrintGameInterface(mineField); Console.WriteLine("Please input your name: "); string playerName = Console.ReadLine(); Score currentScore = new Score(playerName, playerScore); bestScores.Add(currentScore); PrintTopScores(bestScores); playField = CreatePlayField(FieldRows, FieldCols); mineField = CreateMineField(FieldRows, FieldCols, Mines); playerScore = 0; isWon = false; isStarting = true; } }while (command != "exit"); PrintInfoText(); Console.Read(); }
public static void Main() { const int MAXIMUM_CELLS = 35; string command = ""; //<--- Equals to string.Empty char[,] gamingField = CreateGamingField(); char[,] mines = PlantBombs(); int pointsCounter = 0; int rows = 0; int cols = 0; bool showGameIntro = true; bool gameOver = false; bool gameWon = false; List<Score> highScores = new List<Score>(6); do { if (showGameIntro) { Console.WriteLine("Lets play Minesweeper!\nTry to find all fields without mines.\n" + "Command 'top' shows the scoreboard.\nComand 'start' starts a new game.\n" + "Command 'exit' terminates the game!\nHave fun Playing Minesweeper"); CreateGameBoard(gamingField); showGameIntro = false; } Console.Write("Enter row and col separated by space or a command: "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if ((int.TryParse(command[0].ToString(), out rows)) && (int.TryParse(command[2].ToString(), out cols)) && (rows <= gamingField.GetLength(0) && cols <= gamingField.GetLength(1))) { command = "turn"; } } switch (command) { case "top": PrintRankList(highScores); break; case "restart": gamingField = CreateGamingField(); mines = PlantBombs(); CreateGameBoard(gamingField); gameOver = false; showGameIntro = false;break; case "exit": Console.WriteLine("Farewell!"); break; case "turn": if (mines[rows, cols] != '*') { if (mines[rows, cols] == '-') { UpdatePlayBoard(gamingField, mines, rows, cols); pointsCounter++; } if (MAXIMUM_CELLS == pointsCounter) { gameWon = true; } else { CreateGameBoard(gamingField); } } else { gameOver = true; } break; default: Console.WriteLine("\nError! Invalid command\n"); break; } if (gameOver) { CreateGameBoard(mines); Console.Write("\nGame Over you died with {0} points. " + "Enter your nickname: ", pointsCounter); string nickName = Console.ReadLine(); Score result = new Score(nickName, pointsCounter); if (highScores.Count < 5) { highScores.Add(result); } else { for (int i = 0; i < highScores.Count; i++) { if (highScores[i]. < result.UserPoints)
private static void SavePlayerScore(Score currentPlayerScore) { if (TopScores.Count < TopScores.Capacity - 1) { TopScores.Add(currentPlayerScore); } else { for (int index = 0; index < TopScores.Count; index++) { if (currentPlayerScore.Points > TopScores[index].Points) { TopScores.Insert(index, currentPlayerScore); TopScores.RemoveAt(TopScores.Count - 1); break; } } } TopScores.Sort((Score s1, Score s2) => s2.Name.CompareTo(s1.Name)); TopScores.Sort((Score s1, Score s2) => s2.Points.CompareTo(s1.Points)); }
public static void Main(string[] arguments) { const int MAXIMAL_NUMBER_OF_MOVES = 35; string command = string.Empty; char[,] gameField = CreateGameField(); char[,] bombMap = MapBombs(); int counter = 0; bool isBombExplode = false; List<Score> hightScore = new List<Score>(6); int row = 0; int column = 0; bool isStratOfTheGame = true; bool isSuccesfulFinishedTheGame = false; GameEngine engine = new GameEngine(); do { if (isStratOfTheGame) { 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!"); PrintFieldOnConsole(gameField); isStratOfTheGame = false; } Console.Write("Daj red i kolona : "); 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": ShowHightScores(hightScore); break; case "restart": gameField = CreateGameField(); bombMap = MapBombs(); PrintFieldOnConsole(gameField); isBombExplode = false; isStratOfTheGame = false; break; case "exit": Console.WriteLine("4a0, 4a0, 4a0!"); break; case "turn": if (bombMap[row, column] != '*') { if (bombMap[row, column] == '-') { EvaluatePredictionOfBombsNumberForCurrentField(gameField, bombMap, row, column); counter++; } if (MAXIMAL_NUMBER_OF_MOVES == counter) { isSuccesfulFinishedTheGame = true; } else { PrintFieldOnConsole(gameField); } } else { isBombExplode = true; } break; default: Console.WriteLine("\nGreshka! nevalidna Komanda\n"); break; } if (isBombExplode) { PrintFieldOnConsole(bombMap); Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " + "Daj si niknejm: ", counter); string niknejm = Console.ReadLine(); Score t = new Score(niknejm, counter); if (hightScore.Count < 5) { hightScore.Add(t); } else { for (int i = 0; i < hightScore.Count; i++) { if (hightScore[i].Points < t.Points) { hightScore.Insert(i, t); hightScore.RemoveAt(hightScore.Count - 1); break; } } } hightScore.Sort((Score r1, Score r2) => r2.PlayerName.CompareTo(r1.PlayerName)); hightScore.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points)); ShowHightScores(hightScore); gameField = CreateGameField(); bombMap = MapBombs(); counter = 0; isBombExplode = false; isStratOfTheGame = true; } if (isSuccesfulFinishedTheGame) { Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv."); PrintFieldOnConsole(bombMap); Console.WriteLine("Daj si imeto, batka: "); string imeee = Console.ReadLine(); Score to4kii = new Score(imeee, counter); hightScore.Add(to4kii); ShowHightScores(hightScore); gameField = CreateGameField(); bombMap = MapBombs(); counter = 0; isSuccesfulFinishedTheGame = false; isStratOfTheGame = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.WriteLine("AREEEEEEeeeeeee."); Console.Read(); }
public static void Main(string[] args) { string inputCommand = string.Empty; char[,] playingField = CreatePlayingField(); char[,] bombsField = PlaceBombsOnField(); int personalScore = 0; bool isBombHit = false; List<Score> scoreBoardTopPlayers = new List<Score>(6); int row = 0; int col = 0; bool isNewGame = true; bool isWon = false; const int MaxScore = 35; do { if (isNewGame) { Console.WriteLine("Let's play some Minesweeper! "); Console.WriteLine("Find the cells without bombsField. If you hit a bomb the game ends."); Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); Console.WriteLine("Menu:"); Console.WriteLine("'top' - show the score board"); Console.WriteLine("'restart' - start a new game"); Console.WriteLine("'exit' - exit the game"); Console.WriteLine("'4x7' - example for entering row and col"); Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); Console.WriteLine(); DrawPlayingField(playingField); isNewGame = false; } Console.Write("Enter row and column : "); inputCommand = Console.ReadLine().Trim(); if (inputCommand.Length >= 3) { if (int.TryParse(inputCommand[0].ToString(), out row) && int.TryParse(inputCommand[2].ToString(), out col) && row <= playingField.GetLength(0) && col <= playingField.GetLength(1)) { inputCommand = "turn"; } } switch (inputCommand) { case "top": ShowScoreBoard(scoreBoardTopPlayers); break; case "restart": playingField = CreatePlayingField(); bombsField = PlaceBombsOnField(); DrawPlayingField(playingField); isBombHit = false; isNewGame = false; break; case "exit": Console.WriteLine("Good bye."); break; case "turn": if (bombsField[row, col] != '*') { if (bombsField[row, col] == '-') { SetSurroundingBombsCount(playingField, bombsField, row, col); personalScore++; } if (MaxScore == personalScore) { isWon = true; } else { DrawPlayingField(playingField); } } else { isBombHit = true; } break; default: Console.WriteLine("Wrong command."); break; } if (isBombHit) { DrawPlayingField(bombsField); Console.WriteLine("You just hit a bomb. Sorry."); Console.WriteLine("Enter your nickname for the score board: ", personalScore); string nickname = Console.ReadLine(); Score playerPersonalScore = new Score(nickname, personalScore); if (scoreBoardTopPlayers.Count < 5) { scoreBoardTopPlayers.Add(playerPersonalScore); } else { for (int i = 0; i < scoreBoardTopPlayers.Count; i++) { if (scoreBoardTopPlayers[i].PlayerPoints < playerPersonalScore.PlayerPoints) { scoreBoardTopPlayers.Insert(i, playerPersonalScore); scoreBoardTopPlayers.RemoveAt(scoreBoardTopPlayers.Count - 1); break; } } } scoreBoardTopPlayers.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.PlayerName.CompareTo(firstPlayer.PlayerName)); scoreBoardTopPlayers.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.PlayerPoints.CompareTo(firstPlayer.PlayerPoints)); ShowScoreBoard(scoreBoardTopPlayers); playingField = CreatePlayingField(); bombsField = PlaceBombsOnField(); personalScore = 0; isBombHit = false; isNewGame = true; } if (isWon) { Console.WriteLine("Congrats! You won the game!"); DrawPlayingField(bombsField); Console.WriteLine("Enter your nickname for the score board: "); string playerNickname = Console.ReadLine(); Score playerCurrentScore = new Score(playerNickname, personalScore); scoreBoardTopPlayers.Add(playerCurrentScore); ShowScoreBoard(scoreBoardTopPlayers); playingField = CreatePlayingField(); bombsField = PlaceBombsOnField(); personalScore = 0; isWon = false; isNewGame = true; } } while (inputCommand != "exit"); Console.WriteLine("Press any key to exit the game."); Console.Read(); }
public static void Main(string[] аргументи) { char[,] gameField = GenerateGameField(); char[,] bombs = PlaceMines(); List<Score> scoreBoard = new List<Score>(6); int row = 0; int col = 0; int currentScore = 0; bool isPlayerAtGameStart = true; bool hitMine = false; bool hasPlayerWon = false; string command = string.Empty; do { if (isPlayerAtGameStart) { Console.WriteLine("Let's play “Minesweeper”. Try your luck finding out the fields without mines." + " The command 'top' shows the scoreboard, 'restart' starts a new game and 'exit' quits the game."); PrintField(gameField); isPlayerAtGameStart = false; } Console.Write("Enter 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 col) && row <= gameField.GetLength(0) && col <= gameField.GetLength(1)) { command = "turn"; } } switch (command) { case "top": PrintScoreBoard(scoreBoard); break; case "restart": gameField = GenerateGameField(); bombs = PlaceMines(); PrintField(gameField); hitMine = false; isPlayerAtGameStart = false; break; case "exit": Console.WriteLine("Exiting.."); break; case "turn": if (bombs[row, col] != '*') { if (bombs[row, col] == '-') { PlayerTurn(gameField, bombs, row, col); currentScore++; } if (MAX_SCORE == currentScore) { hasPlayerWon = true; } else { PrintField(gameField); } } else { hitMine = true; } break; default: Console.WriteLine("\nError: invalid command given.\n"); break; } if (hitMine) { PrintField(bombs); Console.Write("\nYou died. Score: {0}. Please enter your nickname: ", currentScore); string playerNickname = Console.ReadLine(); Score currentPlayerScore = new Score(playerNickname, currentScore); if (scoreBoard.Count < 5) { scoreBoard.Add(currentPlayerScore); } else { for (int i = 0; i < scoreBoard.Count; i++) { if (scoreBoard[i].Points < currentPlayerScore.Points) { scoreBoard.Insert(i, currentPlayerScore); scoreBoard.RemoveAt(scoreBoard.Count - 1); break; } } } scoreBoard.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.Name.CompareTo(firstPlayer.Name)); scoreBoard.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.Points.CompareTo(firstPlayer.Points)); PrintScoreBoard(scoreBoard); gameField = GenerateGameField(); bombs = PlaceMines(); currentScore = 0; hitMine = false; isPlayerAtGameStart = true; } if (hasPlayerWon) { Console.WriteLine("\nCongratulation. You have won the game!."); PrintField(bombs); Console.WriteLine("Insert your nickname: "); string playerNickname = Console.ReadLine(); Score currentPlayerScore = new Score(playerNickname, currentScore); scoreBoard.Add(currentPlayerScore); PrintScoreBoard(scoreBoard); gameField = GenerateGameField(); bombs = PlaceMines(); currentScore = 0; hasPlayerWon = false; isPlayerAtGameStart = true; } } while (command != "exit"); Console.Read(); }
static void Main() { string command = string.Empty; char[,] gameField = CreateGameField(); char[,] minesPositions = PlaceMines(); int pointsCounter = 0; bool mineExploded = false; List<PlayerDetails> championsList = new List<PlayerDetails>(6); int row = 0; int column = 0; bool newGame = true; const int MaxMines = 35; bool finishedGame = false; do { if (newGame) { Console.WriteLine("Let's play Minesweeper. Try to find all cells without mines inside." + " \nCommands: \n'top' shows champion's list, \n'restart' starts new game, \n'exit' exits and Bye Bye!"); UpdateField(gameField); newGame = false; } Console.Write("Row and Column of cell to open : "); 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": { ShowScore(championsList); break; } case "restart": { gameField = CreateGameField(); minesPositions = PlaceMines(); UpdateField(gameField); mineExploded = false; newGame = false; break; } case "exit": { Console.WriteLine("Bye Bye!"); break; } case "turn": { if (minesPositions[row, column] != '*') { if (minesPositions[row, column] == '-') { OpenCell(gameField, minesPositions, row, column); pointsCounter++; } if (MaxMines == pointsCounter) { finishedGame = true; } else { UpdateField(gameField); } } else { mineExploded = true; } break; } default: { Console.WriteLine("\nError. Invalid command input\n"); break; } } if (mineExploded) { UpdateField(minesPositions); Console.Write("\nHrrrrrr! Died a hero with {0} points. " + "Nickname: ", pointsCounter); string nickName = Console.ReadLine(); PlayerDetails t = new PlayerDetails(nickName, pointsCounter); if (championsList.Count < 5) { championsList.Add(t); } else { for (int i = 0; i < championsList.Count; i++) { if (championsList[i].PointsField < t.PointsField) { championsList.Insert(i, t); championsList.RemoveAt(championsList.Count - 1); break; } } } championsList.Sort((Score r1, Score r2) => r2.Name.CompareTo(r1.Name)); championsList.Sort((Score r1, Score r2) => r2.PointsField.CompareTo(r1.PointsField)); ShowScore(championsList); gameField = CreateGameField(); minesPositions = PlaceMines(); pointsCounter = 0; mineExploded = false; newGame = true; } if (finishedGame) { Console.WriteLine("\nBRAVOOO! Opened all 35 cells and no blood was shed!"); UpdateField(minesPositions); Console.WriteLine("Nickname: "); string name = Console.ReadLine(); Score points = new Score(name, pointsCounter); championsList.Add(points); ShowScore(championsList); gameField = CreateGameField(); minesPositions = PlaceMines(); pointsCounter = 0; finishedGame = false; newGame = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.WriteLine("AREEEEEEeeeeeee."); Console.Read(); }
internal static void Main(string[] args) { const int ScoresTableRows = 5; int freeCellsCount = (BoardRows * BoardColumns) - MinesCount; string command = string.Empty; char[,] board = GenerateInitialBoard(); char[,] mines = GenerateMines(); int openedCells = 0; List<Score> championsTable = new List<Score>(ScoresTableRows + 1); int currentRow = 0; int currentCol = 0; bool isGameStart = true; bool isGameWon = false; bool isGameLost = false; do { if (isGameStart) { Console.WriteLine(@"Това е играта “Minesweeper”. Опитайте да откриете полетата без мини. КОМАНДИ: Команда top - показва класирането, Команда restart - започва нова игра Команда exit - край на играта"); DrawCurrentBoard(board); isGameStart = false; } Console.Write("Моля, команда или въведете ред и колона: "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out currentRow) && int.TryParse(command[2].ToString(), out currentCol) && currentRow < board.GetLength(0) && currentCol < board.GetLength(1)) { command = "turn"; } } switch (command) { case "top": DrawStandingsTable(championsTable); break; case "restart": board = GenerateInitialBoard(); mines = GenerateMines(); DrawCurrentBoard(board); isGameLost = false; isGameStart = false; break; case "exit": Console.WriteLine("Довиждане!"); break; case "turn": if (mines[currentRow, currentCol] != '*') { if (mines[currentRow, currentCol] == '-') { FillMinesCount(board, mines, currentRow, currentCol); openedCells++; } if (freeCellsCount == openedCells) { isGameWon = true; } else { DrawCurrentBoard(board); } } else { isGameLost = true; } break; default: Console.WriteLine("\nНевалидна команда!\n"); break; } if (isGameLost) { DrawCurrentBoard(mines); Console.Write("\nБуум! Стъпихте на мина и завършвате играта с {0} точки.\nМоля, въведете име: ", openedCells); string playersName = Console.ReadLine(); Score currentScore = new Score(playersName, openedCells); if (championsTable.Count < ScoresTableRows) { championsTable.Add(currentScore); } else { for (int i = 0; i < championsTable.Count; i++) { if (championsTable[i].Points < currentScore.Points) { championsTable.Insert(i, currentScore); championsTable.RemoveAt(championsTable.Count - 1); break; } } } championsTable.Sort((Score r1, Score r2) => r2.Name.CompareTo(r1.Name)); championsTable.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points)); DrawStandingsTable(championsTable); board = GenerateInitialBoard(); mines = GenerateMines(); openedCells = 0; isGameLost = false; isGameStart = true; } if (isGameWon) { Console.WriteLine("\nБраво! Отворихте 35 клетки без да стъпите на мина."); DrawCurrentBoard(mines); Console.WriteLine("Моля, въведете име: "); string playersName = Console.ReadLine(); Score currentScore = new Score(playersName, openedCells); championsTable.Add(currentScore); DrawStandingsTable(championsTable); board = GenerateInitialBoard(); mines = GenerateMines(); openedCells = 0; isGameWon = false; isGameStart = true; } } while (command != "exit"); Console.WriteLine("Натиснете клавиш за изход!"); Console.Read(); }
static void Main() { string command = string.Empty; char[,] board = CreateBoard(); char[,] bombs = CreateBombs(); int counter = 0; bool hasExpoded = false; List<Score> champions = new List<Score>(6); int row = 0; int col = 0; bool isGameStarting = true; const int MaxScore = 35; bool isGameCompleted = false; do { if (isGameStarting) { Console.WriteLine("Lets play “Minesweeper”. Try your luck and find the places without bombs."); Console.WriteLine("Commands:"); Console.WriteLine(" 'top' -> top players \n 'restart' -> new game \n 'exit' -> closes the program"); PrintBoard(board); isGameStarting = false; } Console.Write("Enter 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 col) && row <= board.GetLength(0) && col <= board.GetLength(1)) { command = "turn"; } } switch (command) { case "top": DisplayScores(champions); break; case "restart": board = CreateBoard(); bombs = CreateBombs(); PrintBoard(board); hasExpoded = false; isGameStarting = false; break; case "exit": Console.WriteLine("Good Bye!"); break; case "turn": if (bombs[row, col] != '*') { if (bombs[row, col] == '-') { PlayTurn(board, bombs, row, col); counter++; } if (MaxScore == counter) { isGameCompleted = true; } else { PrintBoard(board); } } else { hasExpoded = true; } break; default: Console.WriteLine("\nError! Invalid command.\n"); break; } if (hasExpoded) { PrintBoard(bombs); Console.Write("\nOops! You died! Your score is {0} points. " + "Enter your nickname: ", counter); string nickname = Console.ReadLine(); Score score = new Score(nickname, counter); if (champions.Count < 5) { champions.Add(score); } else { for (int i = 0; i < champions.Count; i++) { if (champions[i].Points < score.Points) { champions.Insert(i, score); champions.RemoveAt(champions.Count - 1); break; } } } champions.Sort((Score r1, Score r2) => r2.Name.CompareTo(r1.Name)); champions.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points)); DisplayScores(champions); board = CreateBoard(); bombs = CreateBombs(); counter = 0; hasExpoded = false; isGameStarting = true; } if (isGameCompleted) { Console.WriteLine("\nCongratulations!!! You cleared the field without hitting a bomb!"); PrintBoard(bombs); Console.WriteLine("Enter your nickname, master: "); string nickname = Console.ReadLine(); Score score = new Score(nickname, counter); champions.Add(score); DisplayScores(champions); board = CreateBoard(); bombs = CreateBombs(); counter = 0; isGameCompleted = false; isGameStarting = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria!"); Console.Read(); }
public static void Main(string[] arguments) { string command = string.Empty; char[,] playField = CreatePlayField(); char[,] bombField = CreateBombField(); int personalScore = 0; bool hitBomb = false; List<Score> topScorers = new List<Score>(6); int row = 0; int col = 0; bool isNewGame = true; const int MaxScore = 35; bool isWon = false; do { if (isNewGame) { Console.WriteLine("Let's play Minesweeper! :) "); Console.WriteLine("Try your luck :) and find the cells without bombs or ..."); Console.WriteLine("...you will die :))))))"); Console.WriteLine("\n####################################"); Console.WriteLine("Menu:"); Console.WriteLine("'top' - show the rating"); Console.WriteLine("'restart' - start a new game"); Console.WriteLine("'exit' - exit the game"); Console.WriteLine("'4x7' - example for entering row and col"); Console.WriteLine("####################################"); DrawPlayField(playField); isNewGame = false; } Console.Write("Enter row and col[row x col]: "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out col) && row <= playField.GetLength(0) && col <= playField.GetLength(1)) { command = "turn"; } } switch (command) { case "top": GetRating(topScorers); break; case "restart": playField = CreatePlayField(); bombField = CreateBombField(); DrawPlayField(playField); hitBomb = false; isNewGame = false; break; case "exit": Console.WriteLine("Bye Bye! :)"); break; case "turn": if (bombField[row, col] != '*') { if (bombField[row, col] == '-') { EnterSurroundingBombCount(playField, bombField, row, col); personalScore++; } if (MaxScore == personalScore) { isWon = true; } else { DrawPlayField(playField); } } else { hitBomb = true; } break; default: Console.WriteLine("\nError: Invalid call\n"); break; } if (hitBomb) { DrawPlayField(bombField); Console.WriteLine("You hit a bomb and ... you are dead. You should try Again"); Console.Write("\nPersonal Score: {0} Enter your Nickname: ", personalScore); string nickname = Console.ReadLine(); Score playerScore = new Score(nickname, personalScore); if (topScorers.Count < 5) { topScorers.Add(playerScore); } else { for (int index = 0; index < topScorers.Count; index++) { if (topScorers[index].Points < playerScore.Points) { topScorers.Insert(index, playerScore); topScorers.RemoveAt(topScorers.Count - 1); break; } } } topScorers.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.Nickname.CompareTo(firstPlayer.Nickname)); topScorers.Sort((Score firstPlayer, Score secondPlayer) => secondPlayer.Points.CompareTo(firstPlayer.Points)); GetRating(topScorers); playField = CreatePlayField(); bombField = CreateBombField(); personalScore = 0; hitBomb = false; isNewGame = true; } if (isWon) { Console.WriteLine("\nBRAVO! You just beat the sh*t out of me! Max Score: {0} reached! ", MaxScore); DrawPlayField(bombField); Console.WriteLine("Enter your Nickname/probably MASTER :)/: "); string nickname = Console.ReadLine(); Score playerScore = new Score(nickname, personalScore); topScorers.Add(playerScore); GetRating(topScorers); playField = CreatePlayField(); bombField = CreateBombField(); personalScore = 0; isWon = false; isNewGame = true; } } while (command != "exit"); Console.WriteLine("Have a nice day! :)"); Console.WriteLine("Made in Bulgaria!"); Console.WriteLine("Press any key to continue . . ."); Console.ReadKey(); }