Exemplo n.º 1
0
        private bool validateBattleShipNumber(IBattleArea battleArea, int battleShipCount)
        {
            int M = (battleArea.Width - '0');
            int N = (battleArea.Height - 'A' + 1);

            return(battleShipCount <= (M * N));
        }
Exemplo n.º 2
0
        public virtual void AddShip(IBattleArea battleArea, int height, int width, CoOrdinates initialCoordinates, ShipType type)
        {
            IShip ship = BattleShipGameFactory.Instance.GetShip();

            ship.Height = height;
            ship.Width  = width;

            battleArea.AddShip(ship, initialCoordinates);
        }
Exemplo n.º 3
0
        public virtual void SetBattleArea(char height, char width)
        {
            this._battleArea1 = BattleShipGameFactory.Instance.GetBattleArea();
            this.InitializeBattleArea(this._battleArea1, "Battle Area1", height, width);

            this._player1.BattleArea = this._battleArea1;

            this._battleArea2 = (this._battleArea1 as IClone <IBattleArea>).Clone();
            this.InitializeBattleArea(this._battleArea2, "Battle Area2", height, width);
            this._player2.BattleArea = this._battleArea2;
        }
Exemplo n.º 4
0
        public override BattleAreaValidatorErrorCode Validate(IBattleArea battleArea, IShip ship)
        {
            if (battleArea.Width < '1' || battleArea.Width > '9' || battleArea.Height < 'A' || battleArea.Height > 'Z')
            {
                return(BattleAreaValidatorErrorCode.InvalidDimension);
            }

            if (this._next != null)
            {
                return(this._next.Validate(battleArea, ship));
            }

            return(BattleAreaValidatorErrorCode.NoError);
        }
Exemplo n.º 5
0
        public override BattleAreaValidatorErrorCode Validate(IBattleArea battleArea, IShip ship)
        {
            bool checkLimits = this.CheckLimits(battleArea, ship.AcquiredCoordinates);

            if (!checkLimits)
            {
                return(BattleAreaValidatorErrorCode.ExceedLimit);
            }

            if (this._next != null)
            {
                return(this._next.Validate(battleArea, ship));
            }

            return(BattleAreaValidatorErrorCode.NoError);
        }
Exemplo n.º 6
0
        public override BattleAreaValidatorErrorCode Validate(IBattleArea battleArea, IShip ship)
        {
            List <CoOrdinates> coordinates = (battleArea as ICoordinate).GetAcquireCoordinates();

            int count = coordinates.Where(item => ship.AcquiredCoordinates.Find(item1 => item1.X == item.X && item1.Y == item.Y) != null).Count();

            if (count > 0)
            {
                return(BattleAreaValidatorErrorCode.AlreadyAcquired);
            }

            if (this._next != null)
            {
                return(this._next.Validate(battleArea, ship));
            }

            return(BattleAreaValidatorErrorCode.NoError);
        }
Exemplo n.º 7
0
        private bool CheckLimits(IBattleArea battleArea, List <CoOrdinates> coordinates)
        {
            //List<CoOrdinates> coordinates = (battleArea as ICoordinate).GetCoordinates();

            var result = coordinates.Where(item =>
            {
                if (item.X >= '1' && item.X <= battleArea.Width && item.Y >= 'A' && item.Y <= battleArea.Height)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            return(result.Count() == coordinates.Count);
        }
Exemplo n.º 8
0
 private bool ValidateShipData(IBattleArea battleArea, int height, int width, CoOrdinates coordinate)
 {
     return((height >= 1 && height <= (int)(battleArea.Height - 'A')) && (width >= 1 && width <= (int)(battleArea.Width - '0')) &&
            (coordinate.X >= '1' && coordinate.X <= battleArea.Width) && (coordinate.Y >= 'A' && coordinate.Y <= battleArea.Height));
 }
Exemplo n.º 9
0
 public abstract BattleAreaValidatorErrorCode Validate(IBattleArea battleArea, IShip ship);
Exemplo n.º 10
0
 private void InitializeBattleArea(IBattleArea battleArea, string name, char height, char width)
 {
     battleArea.Name   = name;
     battleArea.Height = height;
     battleArea.Width  = width;
 }