public void AttackOnBoard_Should_Result_With_Correct_AttackResultStatus(ShipPointLocationModel attackingPosition, AttackResult attackResult , bool needemptyBoard, bool configureBoard, bool isSunk, bool shouldGameOver) { //arrange if (configureBoard) { StateTrackingManager.ShipsOnBoard = SetupShipsOnBoard(); } if (needemptyBoard) { StateTrackingManager.ShipsOnBoard = new List <IBattleship>(); } var isGameOver = false; //act var result = _sutStateTrackingManager.AttackOnBoard(attackingPosition, out isGameOver); var shipUnderAttack = StateTrackingManager.ShipsOnBoard.FirstOrDefault(ship => ship.PointsOccupied.Any(p => p.XCoordinate == attackingPosition.XCoordinate && p.YCoordinate == attackingPosition.YCoordinate)); //assert Assert.Equal(attackResult, result); if (isSunk && !shouldGameOver) //After the last ship sunk, game will be reset with no ships on board. so shipUnderAttack would not be available { Assert.Equal(ShipHealth.Sunk, shipUnderAttack.Health); } else if (attackResult == AttackResult.Hit) { Assert.Equal(ShipHealth.Damaged, shipUnderAttack.Health); } Assert.Equal(shouldGameOver, isGameOver); //if(shouldGameOver) //Assert.Equal(0, StateTrackingManager.ShipsOnBoard.Count); }
public IHttpActionResult Attack(ShipPointLocationModel pointUnderAttack) { if (ModelState.IsValid) { var isGameOver = false; var attackResult = _stateTrackingManager.AttackOnBoard(pointUnderAttack, out isGameOver); return(Ok(new { IsGameOver = isGameOver, AttackStatus = attackResult.ToString(), Message = isGameOver ? "Board is reset for a new game as this game is over!" : attackResult.GetDescription() })); } return(BadRequest(ModelState)); }