Exemplo n.º 1
0
        public void AddingShips(List <string> lstInput_, int iShipCount_, List <IPlayer> lstPlayers_)
        {
            int _iPlayerNumber = 0;

            if (Name == "Player-1")
            {
                _iPlayerNumber = 1;
            }
            else
            {
                _iPlayerNumber = 2;
            }

            for (int _iShipNumber = 0; _iShipNumber < iShipCount_; _iShipNumber++)
            {
                char      _chShipType = Convert.ToChar(lstInput_[2 + _iShipNumber].Split(new char[0], StringSplitOptions.RemoveEmptyEntries)[0]);
                IPosition _shipStartCordinatePosition = new Position();
                int       _shipHeight            = Convert.ToInt32(lstInput_[2 + _iShipNumber].Split(new char[0], StringSplitOptions.RemoveEmptyEntries)[1]);
                int       _shipWidth             = Convert.ToInt32(lstInput_[2 + _iShipNumber].Split(new char[0], StringSplitOptions.RemoveEmptyEntries)[2]);
                string    _shipStartingCordinate = lstInput_[2 + _iShipNumber].Split(new char[0], StringSplitOptions.RemoveEmptyEntries)[2 + _iPlayerNumber];
                _shipStartCordinatePosition.X = Convert.ToChar(_shipStartingCordinate.Substring(0, 1));
                _shipStartCordinatePosition.Y = Convert.ToInt32(_shipStartingCordinate.Substring(1, _shipStartingCordinate.Length - 1));
                ShipsType _shipType = _chShipType == 'Q' ? ShipsType.Q : ShipsType.P;
                IShip     _ship     = new Ship(_shipHeight, _shipWidth, _shipStartCordinatePosition, _shipType);

                if (lstPlayers_.Where(x => x.battleArea.CheckAvailablePostionForNewShip(_ship)).Count() > 1)
                {
                    battleArea.AddShip(_ship);
                }
                else
                {
                    Console.WriteLine("Ship Already added on same position");
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a ship with given size and on given position
 /// </summary>
 /// <param name="iHeight_"></param>
 /// <param name="iWidth_"></param>
 /// <param name="position_"></param>
 /// <param name="shipType_"></param>
 public Ship(int iHeight_, int iWidth_, IPosition position_, ShipsType shipType_)
 {
     lstCells = new List <ICell>();
     ShipType = shipType_;
     for (int _iHeight = 0; _iHeight < iHeight_; _iHeight++)
     {
         for (int _iWidth = 0; _iWidth < iWidth_; _iWidth++)
         {
             Cell _cell = new Cell();
             _cell.status     = StatusType.F;
             _cell.position.X = (char)((int)position_.X + _iWidth);
             _cell.position.Y = position_.Y + _iHeight;
             lstCells.Add(_cell);
         }
     }
 }