public static void Main(string[] аргументи) { const int FreeCells = 35; string command = string.Empty; char[,] playField = CreateField(); char[,] mines = PlaceBombs(); int counter = 0; bool onMine = false; List<Score> champions = new List<Score>(6); int row = 0; int col = 0; bool atStart = true; bool gameEnded = false; do { if (atStart) { Console.WriteLine("Lets play “Mines”. Try to open all cells without mines in" + " Command 'top' shows table, 'restart' restarts the game, 'exit' quits the game"); PrintField(playField); atStart = false; } Console.Write("Insert 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 <= playField.GetLength(0) && col <= playField.GetLength(1)) { command = "turn"; } } switch (command) { case "top": HighScores(champions); break; case "restart": playField = CreateField(); mines = PlaceBombs(); PrintField(playField); onMine = false; atStart = false; break; case "exit": Console.WriteLine("Bye! See you soon"); break; case "turn": if (mines[row, col] != '*') { if (mines[row, col] == '-') { ChangePlayer(playField, mines, row, col); counter++; } if (FreeCells == counter) { gameEnded = true; } else { PrintField(playField); } } else { onMine = true; } break; default: Console.WriteLine("\nError! invalid command\n"); break; } if (onMine) { PrintField(mines); Console.Write("\nYou stepped on a mine - {0} points. insert your name: ", counter); string nickName = Console.ReadLine(); Score playerScore = new Score(nickName, counter); 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 r1, Score r2) => r2.Name.CompareTo(r1.Points)); champions.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points)); HighScores(champions); playField = CreateField(); mines = PlaceBombs(); counter = 0; onMine = false; atStart = true; } if (gameEnded) { Console.WriteLine("\nCongratulations! You've opened all fields without mines."); PrintField(mines); Console.WriteLine("Put your name, buddy: "); string name = Console.ReadLine(); Score points = new Score(name, counter); champions.Add(points); HighScores(champions); playField = CreateField(); mines = PlaceBombs(); counter = 0; gameEnded = false; atStart = true; } } while (command != "exit"); Console.WriteLine("Made in Telerik"); Console.WriteLine("Good luck."); Console.Read(); }
public static void Main(string[] args) { string command = string.Empty; char[,] field = CreateGameField(); char[,] mines = PrintMines(); int counter = 0; bool onMine = false; List<Score> listOfChampoins = new List<Score>(6); int row = 0; int column = 0; bool flag = true; const int MaxScore = 35; bool flag2 = false; do { if (flag) { Console.WriteLine("Let's play “Mines”. Try your luck to find the cells without mines." + " The 'top' command shows high scores, 'restart' starts new game, 'exit' ends the game!"); PrintBoard(field); flag = false; } Console.Write("Daj row i 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": HighScores(listOfChampoins); break; case "restart": field = CreateGameField(); mines = PrintMines(); PrintBoard(field); onMine = false; flag = false; break; case "exit": Console.WriteLine("Bye, Bye, Bye!"); break; case "turn": if (mines[row, column] != '*') { if (mines[row, column] == '-') { PlayerTurn(field, mines, row, column); counter++; } if (MaxScore == counter) { flag2 = true; } else { PrintBoard(field); } } else { onMine = true; } break; default: Console.WriteLine("\nErowor! Invalid Command\n"); break; } if (onMine) { PrintBoard(mines); Console.Write("\nGame over: {0} points. " + "Enter your nickname: ", counter); string nickName = Console.ReadLine(); Score earnedPoints = new Score(nickName, counter); if (listOfChampoins.Count < 5) { listOfChampoins.Add(earnedPoints); } else { for (int i = 0; i < listOfChampoins.Count; i++) { if (listOfChampoins[i].Points < earnedPoints.Points) { listOfChampoins.Insert(i, earnedPoints); listOfChampoins.RemoveAt(listOfChampoins.Count - 1); break; } } } listOfChampoins.Sort((Score result1, Score result2) => result2.Name.CompareTo(result1.Name)); listOfChampoins.Sort((Score result1, Score result2) => result2.Points.CompareTo(result1.Points)); HighScores(listOfChampoins); field = CreateGameField(); mines = PrintMines(); counter = 0; onMine = false; flag = true; } if (flag2) { Console.WriteLine("\nCongratulations! You opened 35 cells."); PrintBoard(mines); Console.WriteLine("Enter you name: "); string playerName = Console.ReadLine(); Score scores = new Score(playerName, counter); listOfChampoins.Add(scores); HighScores(listOfChampoins); field = CreateGameField(); mines = PrintMines(); counter = 0; flag2 = false; flag = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria"); Console.Read(); }
public static void Main(string[] аргументи) { string command = string.Empty; char[,] gameBoard = CreateGameBoard(); char[,] mines = InitMines(); int boxCounter = 0; bool isMineDetonated = false; List<Score> rankList = new List<Score>(6); int row = 0; int col = 0; bool isGameStart = true; const int MaxBoxes = 35; bool isAllBoxesOpened = false; do { if (isGameStart) { Console.WriteLine("Let's play “Mines”. Try your luck to find all mineless boxes." + "\nCommands:\n'top' shows Highscores,\n'restart' start new game,\n'exit' Goodbye!"); Render(gameBoard); isGameStart = false; } Console.Write("Which box? (R)ow and (C)olumn: "); command = Console.ReadLine().Trim(); if (command.Length >= 3) { if (int.TryParse(command[0].ToString(), out row) && int.TryParse(command[2].ToString(), out col) && row <= gameBoard.GetLength(0) && col <= gameBoard.GetLength(1)) { command = "turn"; } } switch (command) { case "top": Highscores(rankList); break; case "restart": gameBoard = CreateGameBoard(); mines = InitMines(); Render(gameBoard); isMineDetonated = false; isGameStart = false; break; case "exit": Console.WriteLine("Bye! Bye!"); break; case "turn": if (mines[row, col] != '*') { if (mines[row, col] == '-') { Move(gameBoard, mines, row, col); boxCounter++; } if (MaxBoxes == boxCounter) { isAllBoxesOpened = true; } else { Render(gameBoard); } } else { isMineDetonated = true; } break; default: Console.WriteLine("\nOps! Invalid command\n"); break; } if (isMineDetonated) { Render(mines); Console.Write("\nHrrrrrr! You blow a mine... You succeeded to open {0} boxes.\nEnter your nickname: ", boxCounter); string nickname = Console.ReadLine(); Score currentScore = new Score(nickname, boxCounter); if (rankList.Count < 5) { rankList.Add(currentScore); } else { for (int i = 0; i < rankList.Count; i++) { if (rankList[i].Points < currentScore.Points) { rankList.Insert(i, currentScore); rankList.RemoveAt(rankList.Count - 1); break; } } } rankList.Sort((Score r1, Score r2) => r2.Name.CompareTo(r1.Name)); rankList.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points)); Highscores(rankList); gameBoard = CreateGameBoard(); mines = InitMines(); boxCounter = 0; isMineDetonated = false; isGameStart = true; } if (isAllBoxesOpened) { Console.WriteLine("\nCOOL! You succeeded to open 35 boxes without a drop of blood!"); Render(mines); Console.WriteLine("Please enter your name: "); string name = Console.ReadLine(); Score currentScore = new Score(name, boxCounter); rankList.Add(currentScore); Highscores(rankList); gameBoard = CreateGameBoard(); mines = InitMines(); boxCounter = 0; isAllBoxesOpened = false; isGameStart = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria!"); Console.WriteLine("So long!"); Console.Read(); }
static void Main(string[] args) { const int FIELDS_IN_PLAYGROUND = 35; string command = string.Empty; char[,] playground = createPlayground(); char[,] minesBoard = createMinesBoard(); int counter = 0; bool stepOverMine = false; List<Score> champions = new List<Score>(6); int row = 0; int column = 0; bool startNewGame = true; bool gameWin = false; do { if (startNewGame) { Console.WriteLine("Let's play “Mines”. Try your luck finding fields without mines." + " Command 'top' shows ratings, 'restart' starts a new game, 'exit' exits game."); dumpp(playground); startNewGame = 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 <= playground.GetLength(0) && column <= playground.GetLength(1)) { command = "turn"; } } switch (command) { case "top": Ratings(champions); break; case "restart": playground = createPlayground(); minesBoard = createMinesBoard(); dumpp(playground); stepOverMine = false; startNewGame = false; break; case "exit": Console.WriteLine("Bye, bye!"); break; case "turn": if (minesBoard[row, column] != '*') { if (minesBoard[row, column] == '-') { nextTurn(playground, minesBoard, row, column); counter++; } if (FIELDS_IN_PLAYGROUND == counter) { gameWin = true; } else { dumpp(playground); } } else { stepOverMine = true; } break; default: Console.WriteLine("\nError! Invalid command.\n"); break; } if (stepOverMine) { dumpp(minesBoard); Console.Write("\nGame over! Your score is {0} points. " + "Your name: ", 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 rating1, Score rating2) => rating2.Name.CompareTo(rating1.Name)); champions.Sort((Score rating1, Score rating2) => rating2.Points.CompareTo(rating1.Points)); Ratings(champions); playground = createPlayground(); minesBoard = createMinesBoard(); counter = 0; stepOverMine = false; startNewGame = true; } if (gameWin) { Console.WriteLine("\nCongratulations! You opened {0} cells without bombs to explode.", FIELDS_IN_PLAYGROUND); dumpp(minesBoard); Console.WriteLine("Your name: "); string nickname = Console.ReadLine(); Score score = new Score(nickname, counter); champions.Add(score); Ratings(champions); playground = createPlayground(); minesBoard = createMinesBoard(); counter = 0; gameWin = false; startNewGame = true; } } while (command != "exit"); Console.WriteLine("Made in Bulgaria!"); // Console.WriteLine("Bye."); // Console.Read(); }
static void Main() { string command = string.Empty; char[,] gamefield = CreateGameField(); char[,] boms = SetBombs(); int counter = 0; bool isFailed = false; List <Score> champions = new List <Score>(6); int row = 0; int col = 0; bool isGameStart = true; const int maks = 35; bool isComplete = false; do { if (isGameStart) { 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!"); DrawGameField(gamefield); isGameStart = 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 col) && row <= gamefield.GetLength(0) && col <= gamefield.GetLength(1)) { command = "turn"; } } switch (command) { case "top": TopScores(champions); break; case "restart": gamefield = CreateGameField(); boms = SetBombs(); DrawGameField(gamefield); isFailed = false; isGameStart = false; break; case "exit": Console.WriteLine("4a0, 4a0, 4a0!"); break; case "turn": if (boms[row, col] != '*') { if (boms[row, col] == '-') { MakeTurn(gamefield, boms, row, col); counter++; } if (maks == counter) { isComplete = true; } else { DrawGameField(gamefield); } } else { isFailed = true; } break; default: Console.WriteLine("\nGreshka! nevalidna Komanda\n"); break; } if (isFailed) { DrawGameField(boms); Console.Write("\nHrrrrrr! Umria gerojski s {0} to4ki. " + "Daj si niknejm: ", counter); string name = Console.ReadLine(); Score curentScore = new Score(name, counter); if (champions.Count < 5) { champions.Add(curentScore); } else { for (int i = 0; i < champions.Count; i++) { if (champions[i].Result < curentScore.Result) { champions.Insert(i, curentScore); champions.RemoveAt(champions.Count - 1); break; } } } champions.Sort((Score first, Score second) => second.Name.CompareTo(first.Name)); champions.Sort((Score first, Score second) => second.Result.CompareTo(first.Result)); TopScores(champions); gamefield = CreateGameField(); boms = SetBombs(); counter = 0; isFailed = false; isGameStart = true; } if (isComplete) { Console.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv."); DrawGameField(boms); Console.WriteLine("Daj si imeto, batka: "); string name = Console.ReadLine(); Score curentScore = new Score(name, counter); champions.Add(curentScore); TopScores(champions); gamefield = CreateGameField(); boms = SetBombs(); counter = 0; isComplete = false; isGameStart = true; } }while (command != "exit"); Console.WriteLine("Made in Bulgaria - Uauahahahahaha!"); Console.WriteLine("AREEEEEEeeeeeee."); Console.Read(); }