public static void Main(string[] args) { const int MAX = 35; string command = string.Empty; char[,] playfield = GeneratePlayfield(); char[,] mines = GenerateMines(); int countedTurns = 0; bool isMine = false; List<Scores> scores = new List<Scores>(6); int row = 0; int column = 0; bool startedGame = true; bool endedGame = false; do { // Try your luck to find cells without mines. if (startedGame) { Console.WriteLine("Let's play on “Mines”. Try your luck to find cells without mines." + " Command 'top' shows ranking, 'restart' begin new game, 'exit' quit game and say goodbye!"); PrintGame(playfield); startedGame = false; } Console.Write("Please 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 <= playfield.GetLength(0) && column <= playfield.GetLength(1)) { command = "turn"; } } switch (command) { case "top": PrintRanking(scores); break; case "restart": playfield = GeneratePlayfield(); mines = GenerateMines(); PrintGame(playfield); isMine = false; startedGame = false; break; case "exit": Console.WriteLine("Bye, Bye, Bye!"); break; case "turn": if (mines[row, column] != '*') { if (mines[row, column] == '-') { MakeTurn(playfield, mines, row, column); countedTurns++; } if (MAX == countedTurns) { endedGame = true; } else { PrintGame(playfield); } } else { isMine = true; } break; default: Console.WriteLine("\nError! Invalid command\n"); break; } if (isMine) { PrintGame(mines); Console.Write("\nBOOM! You died with {0} points. " + "What is your name: ", countedTurns); string name = Console.ReadLine(); Scores players = new Scores(name, countedTurns); if (scores.Count < 5) { scores.Add(players); } else { for (int index = 0; index < scores.Count; index++) { if (scores[index].Results < players.Results) { scores.Insert(index, players); scores.RemoveAt(scores.Count - 1); break; } } } scores.Sort((Scores result1, Scores result2) => result2.Name.CompareTo(result1.Name)); scores.Sort((Scores result1, Scores result2) => result2.Results.CompareTo(result1.Results)); PrintRanking(scores); playfield = GeneratePlayfield(); mines = GenerateMines(); countedTurns = 0; isMine = false; startedGame = true; } if (endedGame) { Console.WriteLine("\nCongratulations! You opened 35 cells and YOU WIN."); PrintGame(mines); Console.WriteLine("Please insert your name: "); string name = Console.ReadLine(); Scores score = new Scores(name, countedTurns); scores.Add(score); PrintRanking(scores); playfield = GeneratePlayfield(); mines = GenerateMines(); countedTurns = 0; endedGame = false; startedGame = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria!"); Console.WriteLine("Have a nice day!"); Console.Read(); }
static void Main(string[] args) { string command = string.Empty; char[,] putField = CreatePlayField(); char[,] putBomb = CreateBombField(); int counter = 0; bool thunder = false; List<Scores> champions = new List<Scores>(6); int row = 0; int column = 0; bool startGame = true; const int MaxScore = 35; bool endGame = false; do { if (startGame) { Console.WriteLine("Lets start Game”.Try you look and find places without mines"); Console.WriteLine("Enter 'top' to view top players"); Console.WriteLine("Enter 'restart' to begin new game"); Console.WriteLine("Enter 'exit' to close the game"); DrawPlayField(putField); startGame = false; } Console.Write("Enter row and colomn: "); command = Console.ReadLine(); string[] arr = command.Split(); if (command.Length >= 3) { if (int.TryParse(arr[0].ToString(), out row) && int.TryParse(arr[1].ToString(), out column) && row <= putField.GetLength(0) && column <= putField.GetLength(1)) { command = "turn"; } } switch (command) { case "top": RankList(champions); break; case "restart": putField = CreatePlayField(); putBomb = CreateBombField(); DrawPlayField(putField); thunder = false; startGame = false; break; case "exit": Console.WriteLine("Bye Bye Bye!"); break; case "turn": if (putBomb[row, column] != '*') { if (putBomb[row, column] == '-') { Muving(putField, putBomb, row, column); counter++; } if (MaxScore == counter) { endGame = true; } else { DrawPlayField(putField); } } else { thunder = true; } break; default: Console.WriteLine("\nError! invalid command\n"); break; } if (thunder) { DrawPlayField(putBomb); Console.Write("\n Game Over! your score are: {0} . " + "Your Name plase: ", counter); string nickName = Console.ReadLine(); Scores playerScore = new Scores(nickName, counter); if (champions .Count < 5) { champions.Add(playerScore); } else { for (int i = 0; i < champions .Count; i++) { if (champions [i].Score < playerScore.Score) { champions .Insert(i, playerScore); champions .RemoveAt(champions.Count - 1); break; } } } champions.Sort((Scores firstPlayer, Scores secondPlayer) => secondPlayer.Name.CompareTo(firstPlayer.Name)); champions.Sort((Scores firstPlayer, Scores secondPlayer) => secondPlayer.Score.CompareTo(firstPlayer.Score)); RankList(champions ); putField = CreatePlayField(); putBomb = CreateBombField(); counter = 0; thunder = false; startGame = true; } if (endGame) { Console.WriteLine("\nCongratulations! achieved a perfect score 35."); DrawPlayField(putBomb); Console.WriteLine("You are champion! enter name:"); string name = Console.ReadLine(); Scores score = new Scores(name, counter); champions .Add(score); RankList(champions); putField = CreatePlayField(); putBomb = CreateBombField(); counter = 0; endGame = false; startGame = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria!"); Console.Read(); }
static void Main(string[] args) { string command = string.Empty; char[,] putField = CreatePlayField(); char[,] putBomb = CreateBombField(); int counter = 0; bool thunder = false; List <Scores> champions = new List <Scores>(6); int row = 0; int column = 0; bool startGame = true; const int MaxScore = 35; bool endGame = false; do { if (startGame) { Console.WriteLine("Lets start Game”.Try you look and find places without mines"); Console.WriteLine("Enter 'top' to view top players"); Console.WriteLine("Enter 'restart' to begin new game"); Console.WriteLine("Enter 'exit' to close the game"); DrawPlayField(putField); startGame = false; } Console.Write("Enter row and colomn: "); command = Console.ReadLine(); string[] arr = command.Split(); if (command.Length >= 3) { if (int.TryParse(arr[0].ToString(), out row) && int.TryParse(arr[1].ToString(), out column) && row <= putField.GetLength(0) && column <= putField.GetLength(1)) { command = "turn"; } } switch (command) { case "top": RankList(champions); break; case "restart": putField = CreatePlayField(); putBomb = CreateBombField(); DrawPlayField(putField); thunder = false; startGame = false; break; case "exit": Console.WriteLine("Bye Bye Bye!"); break; case "turn": if (putBomb[row, column] != '*') { if (putBomb[row, column] == '-') { Muving(putField, putBomb, row, column); counter++; } if (MaxScore == counter) { endGame = true; } else { DrawPlayField(putField); } } else { thunder = true; } break; default: Console.WriteLine("\nError! invalid command\n"); break; } if (thunder) { DrawPlayField(putBomb); Console.Write("\n Game Over! your score are: {0} . " + "Your Name plase: ", counter); string nickName = Console.ReadLine(); Scores playerScore = new Scores(nickName, counter); if (champions.Count < 5) { champions.Add(playerScore); } else { for (int i = 0; i < champions.Count; i++) { if (champions [i].Score < playerScore.Score) { champions.Insert(i, playerScore); champions.RemoveAt(champions.Count - 1); break; } } } champions.Sort((Scores firstPlayer, Scores secondPlayer) => secondPlayer.Name.CompareTo(firstPlayer.Name)); champions.Sort((Scores firstPlayer, Scores secondPlayer) => secondPlayer.Score.CompareTo(firstPlayer.Score)); RankList(champions); putField = CreatePlayField(); putBomb = CreateBombField(); counter = 0; thunder = false; startGame = true; } if (endGame) { Console.WriteLine("\nCongratulations! achieved a perfect score 35."); DrawPlayField(putBomb); Console.WriteLine("You are champion! enter name:"); string name = Console.ReadLine(); Scores score = new Scores(name, counter); champions.Add(score); RankList(champions); putField = CreatePlayField(); putBomb = CreateBombField(); counter = 0; endGame = false; startGame = true; } }while (command != "exit"); Console.WriteLine("Made in Bulgaria!"); Console.Read(); }