public void TestIfBombWithSizeFiveExplodesAsExpectedWhenTheBombIsNearTheBottompLeftFieldCorner() { string testFieldSize = "6"; Engine.FieldSizeUnitTestSetter = new StringReader(testFieldSize); Engine.StartMenu.IsStartGameChosen = true; Engine gameEngine = new Engine(); Playfield testField = Playfield.Instance; testField.SetFieldSize(6); testField.InitializeEmptyField(); testField[1, 5] = new BombCell(5); PrivateObject enginePrivateInstance = new PrivateObject(gameEngine); enginePrivateInstance.Invoke("HandleExplosion", testField[1, 5]); Playfield engineField = (Playfield)enginePrivateInstance.GetFieldOrProperty("playField"); BombCell bomb = new BombCell(5); bomb.X = 4; bomb.Y = 4; engineField[1, 5] = bomb; enginePrivateInstance.Invoke("ChangeCurrentCell", 1, 5); enginePrivateInstance.Invoke("HandleExplosion", engineField[1, 5]); Assert.AreEqual(engineField[2, 5].CellType == CellType.BlownCell, true, "Expected that the cell on coordinates 2,5 is CellType.BlownCell. Received {0} ", engineField.ToString()); }
/// <summary> /// Cell factory implementation. /// </summary> /// <param name="cellType">Cell type.</param> /// <returns>Required cell.</returns> public static ICell CreateCell(CellType cellType) { //// Uses "lazy initialization". ICell cell; switch (cellType) { case CellType.EmptyCell: cell = new EmptyCell(); cell.CellView = CellView.Empty; break; case CellType.Bomb: int bombSize = RandomGenerator.GetRandomNumber(MIN_BOMB_SIZE, MAX_BOMB_SIZE); cell = new BombCell(bombSize); cell.CellView = (CellView)bombSize + ASCII_VIEW_OFFSET; break; case CellType.BlownCell: cell = new BlownCell(); cell.CellView = CellView.Blown; break; default: throw new ArgumentException("Invalid cell type give to the cell factory"); } return cell; }
/// <summary> /// Cell factory implementation. /// </summary> /// <param name="cellType">Cell type.</param> /// <returns>Required cell.</returns> public static ICell CreateCell(CellType cellType) { //// Uses "lazy initialization". ICell cell; switch (cellType) { case CellType.EmptyCell: cell = new EmptyCell(); cell.CellView = CellView.Empty; break; case CellType.Bomb: int bombSize = RandomGenerator.GetRandomNumber(MIN_BOMB_SIZE, MAX_BOMB_SIZE); cell = new BombCell(bombSize); cell.CellView = (CellView)bombSize + ASCII_VIEW_OFFSET; break; case CellType.BlownCell: cell = new BlownCell(); cell.CellView = CellView.Blown; break; default: throw new ArgumentException("Invalid cell type give to the cell factory"); } return(cell); }
public void CheckIfPlayfieldCellCanBeSetWithNewValue() { var playField = Playfield.Instance; playField.SetFieldSize(5); playField.InitializeEmptyField(); BombCell bombCell = new BombCell(5); playField[0, 0] = bombCell; Assert.AreEqual(playField[0, 0].Equals(bombCell), true, string.Format("Exprected that cell in position 0,0 in the field is set as bombcell with size 5. Received {0}", playField[0, 0].Equals(bombCell))); }
public void CellsTestIfBombCellIsCloned() { int bombSize = 1; BombCell bombCell = new BombCell(bombSize); bombCell.X = 2; bombCell.Y = 3; bombCell.Color = Color.White; bombCell.CellView = CellView.Bomb1; ICell clonedBombCell = bombCell.Clone(); Assert.AreEqual(bombCell.X, clonedBombCell.X, "X coordinate has not cloned."); Assert.AreEqual(bombCell.Y, clonedBombCell.Y, "Y coordinate has not cloned."); Assert.AreEqual(bombCell.Color, clonedBombCell.Color, "Cell Color has not cloned."); Assert.AreEqual(bombCell.CellView, clonedBombCell.CellView, "CellView Color has not cloned."); }
public void CheckIfFieldToStringMethodReturnsCorrectString() { var playField = Playfield.Instance; playField.SetFieldSize(5); playField.InitializeEmptyField(); BombCell bombCellOne = new BombCell(1); BombCell bombCellTwo = new BombCell(2); BombCell bombCellThree = new BombCell(3); BombCell bombCellFour = new BombCell(4); BombCell bombCellFive = new BombCell(5); playField[0, 0] = bombCellOne; playField[1, 1] = bombCellTwo; playField[2, 2] = bombCellThree; playField[3, 3] = bombCellFour; playField[4, 4] = bombCellFive; string playfieldStringExpected = playField.ToString(); Assert.AreEqual(playfieldStringExpected.Equals(playField.ToString()), true, string.Format("Exprected that cell in position 0,0 in the field is set as bombcell with size 5. Received {0} ",playfieldStringExpected)); }
/// <summary> /// Handle the explosion within two explosion radius. /// </summary> /// <param name="cell">BombCell cell.</param> private void HandleExplosionTwoRadius(BombCell cell) { this.HandleExplosionOneRadius(cell); int bombX = cell.X; int bombY = cell.Y; if (bombX - 1 >= 0) { this.MakeCellBlown(bombX - 1, bombY); } if (bombY + 1 < this.playField.PlayfieldSize) { this.MakeCellBlown(bombX, bombY + 1); } if (bombX + 1 < this.playField.PlayfieldSize) { this.MakeCellBlown(bombX + 1, bombY); } if (bombY - 1 >= 0) { this.MakeCellBlown(bombX, bombY - 1); } }
/// <summary> /// Handle the explosion within three explosion radius. /// </summary> /// <param name="cell">BombCell cell.</param> private void HandleExplosionThreeRadius(BombCell cell) { this.HandleExplosionTwoRadius(cell); int bombX = cell.X; int bombY = cell.Y; if (bombX - 2 >= 0) { this.MakeCellBlown(bombX - 2, bombY); } if (bombY + 2 < this.playField.PlayfieldSize) { this.MakeCellBlown(bombX, bombY + 2); } if (bombX + 2 < this.playField.PlayfieldSize) { this.MakeCellBlown(bombX + 2, bombY); } if (bombY - 2 >= 0) { this.MakeCellBlown(bombX, bombY - 2); } }
/// <summary> /// Handle explosion with a bomb cell. /// </summary> /// <param name="currentCell">BombCell currentCell.</param> private void HandleExplosion(BombCell currentCell) { this.gamePlayer.DetonatedMines++; switch (currentCell.BombSize) { case 1: this.HandleExplosionOneRadius(currentCell); break; case 2: this.HandleExplosionTwoRadius(currentCell); break; case 3: this.HandleExplosionThreeRadius(currentCell); break; case 4: this.HandleExplosionFourRadius(currentCell); break; case 5: this.HandleExplosionFiveRadius(currentCell); break; default: throw new NotImplementedException("Cannot handle explosion with radius more than 5."); } }
public void CellsTestIfBombCellYIsPositive() { var cellBomb = new BombCell(); cellBomb.Y = -1; }
public void CellsTestIfBombCellXIsPositive() { var bombCell = new BombCell(); bombCell.X = -1; }
public void CellsTestExceptionWhenBombSizeIsLessThanMinAllowed() { var bombCell = new BombCell(); bombCell.BombSize = 0; }