public void AddPlayerScoreTest() { const string playerName = "Pesho"; const int playerScore = 20; var scoreBoard = new ScoreBoard(); scoreBoard.AddPlayer(playerName, playerScore); Assert.AreEqual(true, scoreBoard.scoreBoard.ContainsKey(playerScore)); }
public void AddNegativePlayerScoreTest() { const string playerName = "Pesho"; const int playerScore = -1; var newScoreBoard = new ScoreBoard(); newScoreBoard.AddPlayer(playerName, playerScore); }
public void PrintEmtyScoreBoardTest() { var output = new StringBuilder(); var textWriter = new StringWriter(output); Console.SetOut(textWriter); var newScoreboard = new ScoreBoard(); newScoreboard.PrintScoreBoard(); string outputStr = output.ToString(); Assert.AreEqual("\r\nScoreboard is empty!\r\n\r\n", outputStr); }
public void AddEmptyPlayerNameTest() { var output = new StringBuilder(); var textWriter = new StringWriter(output); Console.SetOut(textWriter); const string playerName = ""; const int playerScore = 20; const string expected = "unknown"; var newScoreBoard = new ScoreBoard(); newScoreBoard.AddPlayer(playerName, playerScore); Assert.IsTrue(newScoreBoard.ScoreBoardd.Contains(20, "unknown")); }
public void PrintFivePlayersInScoreBoardTest() { var output = new StringBuilder(); var textWriter = new StringWriter(output); Console.SetOut(textWriter); var newScoreboard = new ScoreBoard(); newScoreboard.AddPlayer("Pesho", 29); newScoreboard.AddPlayer("Angel", 5); newScoreboard.AddPlayer("John", 35); newScoreboard.AddPlayer("Mike", 4); newScoreboard.AddPlayer("Ben", 3); newScoreboard.PrintScoreBoard(); string outputStr = output.ToString(); Assert.AreEqual("Scoreboard:\r\n1. John --> 35 cells\r\n2. Pesho --> 29 cells\r\n3. Angel --> 5 cells\r\n4. Mike --> 4 cells\r\n5. Ben --> 3 cells\r\n\r\n", outputStr); }
public void PrintOnePlayerInScoreBoardTest() { var output = new StringBuilder(); var textWriter = new StringWriter(output); Console.SetOut(textWriter); var newScoreboard = new ScoreBoard(); newScoreboard.AddPlayer("Pesho", 29); newScoreboard.PrintScoreBoard(); string outputStr = output.ToString(); Assert.AreEqual("Scoreboard:\r\n1. Pesho --> 29 cells\r\n\r\n", outputStr); }
public static void Main(string[] arguments) { string command = string.Empty; char[,] gameBoard = CreateBoard(); char[,] gameCells = SpreadMines(); int playerScore = 0; bool isExploded = false; List<ScoreBoard> champions = new List<ScoreBoard>(6); int row = 0; int column = 0; bool isStarting = true; const int MaximalScore = 35; bool isWinner = false; do { if (isStarting) { Console.WriteLine("Let\'s play “MineSweeper”. Try to find fields without mines." + " Command 'top' shows the ranking, 'restart' starts new game, 'exit' game over!"); RefreshBoard(gameBoard); isStarting = false; } Console.Write("Type 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 <= gameBoard.GetLength(0) && column <= gameBoard.GetLength(1)) { command = "turn"; } } switch (command) { case "top": GetScore(champions); break; case "restart": gameBoard = CreateBoard(); gameCells = SpreadMines(); RefreshBoard(gameBoard); isExploded = false; isStarting = false; break; case "exit": Console.WriteLine("Bye, bye!"); break; case "turn": try { if (gameCells[row, column] != '*') { if (gameCells[row, column] == '-') { SetCell(gameBoard, gameCells, row, column); playerScore++; } if (MaximalScore == playerScore) { isWinner = true; } else { RefreshBoard(gameBoard); } } else { isExploded = true; } } catch (IndexOutOfRangeException e) { Console.WriteLine("Your rows and columns are out of range.", e); } break; default: Console.WriteLine("\nError! Invalid command.\n"); break; } if (isExploded) { RefreshBoard(gameCells); Console.Write("\nSorry! You died with {0} points. " + "Please write your name: ", playerScore); string playerName = Console.ReadLine(); ScoreBoard playerRank = new ScoreBoard(playerName, playerScore); if (champions.Count < 5) { champions.Add(playerRank); } else { for (int i = 0; i < champions.Count; i++) { if (champions[i].PlayerPoints < playerRank.PlayerPoints) { champions.Insert(i, playerRank); champions.RemoveAt(champions.Count - 1); break; } } } champions.Sort((ScoreBoard r1, ScoreBoard r2) => r2.PlayerName.CompareTo(r1.PlayerName)); champions.Sort((ScoreBoard r1, ScoreBoard r2) => r2.PlayerPoints.CompareTo(r1.PlayerPoints)); GetScore(champions); gameBoard = CreateBoard(); gameCells = SpreadMines(); playerScore = 0; isExploded = false; isStarting = true; } if (isWinner) { Console.WriteLine("\nBravo! You opened 35 cells without losing a drop of blood."); RefreshBoard(gameCells); Console.WriteLine("Please write your name: "); string playerName = Console.ReadLine(); ScoreBoard rankPosition = new ScoreBoard(playerName, playerScore); champions.Add(rankPosition); GetScore(champions); gameBoard = CreateBoard(); gameCells = SpreadMines(); playerScore = 0; isWinner = false; isStarting = true; } } while (command != "exit"); Console.WriteLine("The game is over!"); Console.WriteLine("Try again."); Console.Read(); }