public List <Cell> MineLocations(int gridSize) { var generatedMineList = new List <Cell>(); var gameGrid = GridFactory.NewGameGrid(gridSize); for (var row = 0; row < gameGrid.Size; row++) { for (var column = 0; column < gameGrid.Size; column++) { generatedMineList.Add(gameGrid.GeneratedGameCell[row, column]); gameGrid.GeneratedGameCell[row, column].IsMine = true; } } var selectedMineLocations = new List <Cell>(); for (var cell = 0; cell < gameGrid.Size; cell++) { var rnd = new Random(); var randomMine = generatedMineList.Count; var mine = rnd.Next(randomMine); selectedMineLocations.Add(generatedMineList[mine]); generatedMineList.Remove(generatedMineList[mine]); } return(selectedMineLocations); }
public void GenerateABoardOfTheCorrectSize(int size, int expected) { //Arrange //Act var result = GridFactory.NewGameGrid(size); //Assert Assert.Equal(expected, result.Size); }
public void DisplayABoardWithTheCorrectDimensions(int size, string expected) { //Arrange var newDisplay = GridFactory.NewDisplayGrid(); var gameGrid = GridFactory.NewGameGrid(size); //Act var result = newDisplay.GenerateGameDisplay(gameGrid); //Assert Assert.Equal(expected, result); }
public void UpdateTheStatusOfACellToRecordAMineAsFalse() { //Arrange var gridSize = 2; var newGame = GridFactory.NewGameGrid(gridSize); var updateMineStatus = new MineUpdater(); var mineStub = new StubForMineLocationZeroZero(); //Act updateMineStatus.UpdateCellWithMineStatus(mineStub.MineLocations(newGame.Size), newGame); //Assert Assert.False(newGame.GeneratedGameCell[1, 1].IsMine); }
public void ReturnTwoAdjacentMinesOnASizeTwoGridAfterAPlayerMove() { //Arrange var newGameGrid = GridFactory.NewGameGrid(2); var updateMineStatus = new MineUpdater(); var mineStub = new StubForTwoMineLocations(); var userInputMove = new PlayerMove(1, 1); //Act updateMineStatus.UpdateCellWithMineStatus(mineStub.MineLocations(newGameGrid.Size), newGameGrid); var result = updateMineStatus.CalculateAdjacentMineTotal(newGameGrid, userInputMove); //Assert Assert.Equal(2, result); }
public void ReturnTrueIfPlayerHasSelectedAMine() { //Arrange var size = 2; var newValidation = Factory.NewUserInputValidation(); var gameGrid = GridFactory.NewGameGrid(size); var userInput = new PlayerMove(0, 0); var updateMineStatus = new MineUpdater(); var mineStub = new StubForMineLocationZeroZero(); //Act updateMineStatus.UpdateCellWithMineStatus(mineStub.MineLocations(gameGrid.Size), gameGrid); //Assert Assert.True(newValidation.IsGameOver(gameGrid, userInput)); }
public void DisplayBoardWithGeneratedMinesCorrectly() { //Arrange var gridSize = 2; var newGrid = GridFactory.NewGameGrid(gridSize); var gameDisplay = GridFactory.NewDisplayGrid(); var mineLogic = MineFactory.NewMineChecker(); var mineLocations = new StubForTwoMineLocations(); mineLogic.UpdateCellWithMineStatus(mineLocations.MineLocations(gridSize), newGrid); //Act var result = gameDisplay.GenerateGameDisplay(newGrid); //Assert Assert.Equal(". + \n+ . \n", result); }
public void ShowTheCorrectGameWinningMessageWhenAPlayerCompletesAGridWithoutHittingAMine() { //Arrange var gridSize = 2; var newMessageDisplay = Factory.NewMessageDisplay(); var gameGrid = GridFactory.NewGameGrid(gridSize); var gameCellUpdater = Factory.NewCellUpdater(); var mineUpdater = MineFactory.NewMineChecker(); var mineStub = new StubForTwoMineLocations(); var userMove = new PlayerMove(0, 1); var expected = $"* 2 {Environment.NewLine}* 2 {Environment.NewLine}Congrats!{Environment.NewLine}You have won!"; //Act mineUpdater.UpdateCellWithMineStatus(mineStub.MineLocations(gridSize), gameGrid); gameCellUpdater.UpdateAdjacentMineTotalAtGameStart(gameGrid); var result = newMessageDisplay.EndGameMessage(gameGrid, userMove); //Assert Assert.Equal(expected, result); }
public void ShowTheCorrectGameLosingMessageWhenAPlayerHitsAMine() { //Arrange var gridSize = 2; var newMessageDisplay = Factory.NewMessageDisplay(); var gameGrid = GridFactory.NewGameGrid(gridSize); var gameCellUpdater = Factory.NewCellUpdater(); var mineUpdater = MineFactory.NewMineChecker(); var mineStub = new StubForTwoMineLocations(); var userMove = new PlayerMove(0, 0); var expected = $"* 2 {Environment.NewLine}* 2 {Environment.NewLine}Sorry, you have lost.{Environment.NewLine}Game over!"; //Act mineUpdater.UpdateCellWithMineStatus(mineStub.MineLocations(gridSize), gameGrid); gameCellUpdater.UpdateAdjacentMineTotalAtGameStart(gameGrid); var result = newMessageDisplay.EndGameMessage(gameGrid, userMove); //Assert Assert.Equal(expected, result); }
public void NewGame() { //For the game, [0,0] is located in the top left corner, with the largest row/column being bottom right. //Player move is always entered as Row then Column. var gridSize = GetGridSize(); var currentGameGrid = GridFactory.NewGameGrid(gridSize); var userInputMove = new PlayerMove(0, 0); var maxNonMineCells = gridSize * gridSize - gridSize; var turnCount = 0; while (!_userInputValidation.IsGameOver(currentGameGrid, userInputMove) && turnCount < maxNonMineCells) { var runAtGameStart = turnCount == 0; userInputMove = RunGame(userInputMove, currentGameGrid, runAtGameStart); turnCount++; } Console.Clear(); Console.WriteLine(_gameMessageDisplay.EndGameMessage(currentGameGrid, userInputMove)); }