public void TestAddPlayerInScoreBoard_NameIsNull() { int score = 7; ScoreBoard scoreBoard = new ScoreBoard(); scoreBoard.AddPlayer(null, score); }
public void TestAddPlayerInScoreBoard_ScoreIsNegative() { int score = -2; string name = "Sasho"; ScoreBoard scoreBoard = new ScoreBoard(); scoreBoard.AddPlayer(name, score); }
public void TestAddPlayerInScoreBoard_NameIsOnlyWhiteSpaces() { int score = 7; string name = " "; ScoreBoard scoreBoard = new ScoreBoard(); scoreBoard.AddPlayer(name, score); }
public void TestAddPlayerInScoreBoard_NameIsEmpty() { int score = 7; string name = string.Empty; ScoreBoard scoreBoard = new ScoreBoard(); scoreBoard.AddPlayer(name, score); }
public void TestAddPlayerInScoreBoard_ValidInput() { string playerName = "Misho"; int playerScore = 7; int currentPlayer = 1; string output = "\n\rScoreboard:\n\r" + currentPlayer + ". " + playerName + " --> " + playerScore + " cells" + Environment.NewLine; ScoreBoard scoreBoard = new ScoreBoard(); scoreBoard.AddPlayer(playerName, playerScore); Assert.AreEqual(output, scoreBoard.Generate()); }
public void TestGenerateScoreBoard() { ScoreBoard scoreBoard = new ScoreBoard(); int currentPlayer = 1; string playerName = "Pesho"; int playerScore = 10; string output = "\n\rScoreboard:\n\r" + currentPlayer + ". Pesho --> " + playerScore + " cells" + Environment.NewLine; scoreBoard.AddPlayer(playerName, playerScore); Assert.AreEqual(output, scoreBoard.Generate()); }
public void Start() { FieldFactory minesweeperFactory = new MinesweeperFieldFactory(); IField minesweeperField = minesweeperFactory.CreateField(); FieldFactory playingFieldFactory = new PlayingFieldFactory(); IField playingField = playingFieldFactory.CreateField(); IRenderer consoleRenderer = new ConsoleRenderer(); IReadInput inputReader = new ConsoleReader(); IScoreBoard scoreboard = new ScoreBoard(); IEngine engine = new Engine(minesweeperField, playingField, consoleRenderer, inputReader, scoreboard); engine.Play(); }
public void TestGenerateScoreBoard() { ScoreBoard scoreBoard = new ScoreBoard(); scoreBoard.AddPlayer("Sasho", 10); scoreBoard.AddPlayer("Pesho", 7); scoreBoard.AddPlayer("Tosho", 7); scoreBoard.AddPlayer("Gosho", 3); string output = Environment.NewLine + "Scoreboard:" + Environment.NewLine + "1. Sasho --> 10 cells" + Environment.NewLine + "2. Pesho --> 7 cells" + Environment.NewLine + "3. Tosho --> 7 cells" + Environment.NewLine + "4. Gosho --> 3 cells" + Environment.NewLine; Assert.AreEqual(output, scoreBoard.Generate()); }
/// <summary> /// Controls the gameplay throughout other methods for validation and I/O. /// </summary> public void Play() { IScoreBoard scoreBoard = new ScoreBoard(); IField gameField = new Field(); IIOManager ioManager = new ConsoleIOManager(); int row = 0; int col = 0; int minesCounter = 0; int revealedCellsCounter = 0; bool hasExploded = false; while (true) { ioManager.PrintInitialMessage(); StartNewGame(gameField, ref row, ref col, ref minesCounter, ref revealedCellsCounter, ref hasExploded); ioManager.PrintGameField(gameField, hasExploded); bool rowAndColAreValid = false; string input = string.Empty; while (true) { input = ioManager.GetUserInput(); if (IsMoveEntered(input)) { string[] inputParams = input.Split(); row = int.Parse(inputParams[0]); col = int.Parse(inputParams[1]); rowAndColAreValid = ValidateRowAndCol(gameField, row, col); if (rowAndColAreValid) { bool cellHasMine = gameField.IsMine(row, col); if (cellHasMine) { hasExploded = true; ioManager.PrintGameField(gameField, hasExploded); ioManager.PrintExplosionMessage(revealedCellsCounter); string currentPlayerName = ioManager.GetUserNickname(); scoreBoard.AddPlayer(currentPlayerName, revealedCellsCounter); ioManager.PrintScoreBoard(scoreBoard); break; } bool winner = IsWinner(gameField.Matrix, minesCounter); if (winner) { ioManager.PrintWinnerMessage(); string currentPlayerName = ioManager.GetUserNickname(); scoreBoard.AddPlayer(currentPlayerName, revealedCellsCounter); break; } gameField.Update(row, col); revealedCellsCounter++; ioManager.PrintGameField(gameField, cellHasMine); } else { ioManager.PrintInvalidCommandMessage(); } } else if (IsCommandEntered(input)) { bool isRestart = false; switch (input) { case "top": { ioManager.PrintScoreBoard(scoreBoard); continue; } case "exit": { ioManager.PrintQuitMessage(); return; } case "restart": { isRestart = true; break; } } if (isRestart) { break; } } else { ioManager.PrintInvalidCommandMessage(); } } } }