Ejemplo n.º 1
0
        private Game(SetupBoard playerOneSetup, SetupBoard playerTwoSetup)
        {
            if (!playerOneSetup.IsValid)
            {
                throw new ArgumentException("Player One setup board is not valid.", nameof(playerOneSetup));
            }

            if (!playerTwoSetup.IsValid)
            {
                throw new ArgumentException("Player Two setup board is not valid.", nameof(playerTwoSetup));
            }

            m_PlayerOneSetup = playerOneSetup;
            m_PlayerTwoSetup = playerTwoSetup;

            Turn = Players.PlayerOne;
        }
Ejemplo n.º 2
0
        private static FireResult GetResult(GridSquare target, SetupBoard targetBoard, ShotState[,] shotRecorder)
        {
            var isHit = targetBoard.ShipsByOccupationPoints.ContainsKey(target.Point);

            shotRecorder[target.Point.X, target.Point.Y] = isHit ? ShotState.Hit : ShotState.Miss;

            if (!isHit)
            {
                return(new FireResult(target));
            }

            var hitShip = targetBoard.ShipsByOccupationPoints[target.Point];
            var isSunk  = hitShip.Hit(target.Point);

            var haveWon = isSunk ? targetBoard.AllSunk : false;

            return(new FireResult(target, isSunk, isSunk ? hitShip : null, haveWon));
        }
Ejemplo n.º 3
0
 internal Game(SetupBoard setupBoard, SetupBoard opponentsSetupBoard, IComputerStrategy computerStrategy) : this(setupBoard, opponentsSetupBoard)
 {
     m_ComputerStrategy = computerStrategy;
 }
Ejemplo n.º 4
0
 public Game(SetupBoard setupBoard) : this(setupBoard, new SetupBoard().GenerateRandom())
 {
     m_ComputerStrategy = new ShipSeekingEfficientStrategy();
 }