public void Shoot_ThrowsShootCellOutOfRangeException(int shootPointX, int shootPointY) { var shootStrategyAtPoint = new ShootStrategyAtPoint { ShootPoint = new Point(shootPointX, shootPointY) }; var field = new Field(5, 5); void Action() => shootStrategyAtPoint.Shoot(field); Assert.Throws <ShootCellOutOfRangeException>(Action); }
public void Shoot_OnEmptyCell_ThrowsShootCellCheckedException(int shootPointX, int shootPointY) { var shootStrategyAtPoint = new ShootStrategyAtPoint { ShootPoint = new Point(shootPointX, shootPointY) }; var field = new Field(5, 5); field.CellsMatrix[shootPointY, shootPointX].CellState = CellState.Empty; void Action() => shootStrategyAtPoint.Shoot(field); Assert.Throws <ShootCellCheckedException>(Action); }
public void Shoot_MissShipCell(int shootPointX, int shootPointY) { var shootStrategyAtPoint = new ShootStrategyAtPoint { ShootPoint = new Point(shootPointX, shootPointY) }; var field = new Field(5, 5); field.CellsMatrix[shootPointY + 1, shootPointX].CellState = CellState.Ship; var shootCell = shootStrategyAtPoint.Shoot(field); Assert.True(shootCell.CellState == CellState.Empty); }
public void MakeMove_CellIsChanged(bool isPlayerOneTurn, int shootPointX, int shootPointY) { var gameContext = new GameContext { FieldPlayerOne = new Field(5, 5), FieldPlayerTwo = new Field(5, 5) }; gameContext.FieldPlayerOne.CellsMatrix[0, 0].CellState = CellState.Ship; gameContext.FieldPlayerTwo.CellsMatrix[0, 0].CellState = CellState.Ship; gameContext.EventManager = new EventManager( new PlayerListener(gameContext.FieldPlayerOne), new PlayerListener(gameContext.FieldPlayerTwo) ) { IsPlayerOneTurn = isPlayerOneTurn }; var shootStrategy = new ShootStrategyAtPoint { ShootPoint = new Point(shootPointX, shootPointX) }; gameContext.MakeMove(shootStrategy); CellState changedCellState; if (isPlayerOneTurn) { changedCellState = gameContext.FieldPlayerTwo .CellsMatrix[shootPointY, shootPointX].CellState; } else { changedCellState = gameContext.FieldPlayerOne .CellsMatrix[shootPointY, shootPointX].CellState; } ; Assert.True(changedCellState == CellState.Empty); }
public void MakeMove_PlayerTurnIsChanged(bool isPlayerOneTurn) { var gameContext = new GameContext { FieldPlayerOne = new Field(5, 5), FieldPlayerTwo = new Field(5, 5) }; gameContext.FieldPlayerOne.CellsMatrix[0, 0].CellState = CellState.Ship; gameContext.FieldPlayerTwo.CellsMatrix[0, 0].CellState = CellState.Ship; gameContext.EventManager = new EventManager( new PlayerListener(gameContext.FieldPlayerOne), new PlayerListener(gameContext.FieldPlayerTwo) ) { IsPlayerOneTurn = isPlayerOneTurn }; var shootStrategy = new ShootStrategyAtPoint { ShootPoint = new Point(3, 3) }; gameContext.MakeMove(shootStrategy); bool isChangedMove; if (isPlayerOneTurn) { isChangedMove = !gameContext.IsPlayerOneTurn(); } else { isChangedMove = gameContext.IsPlayerOneTurn(); } Assert.True(isChangedMove); }