Пример #1
0
        protected bool NeedAddShip(eShip ship)
        {
            int shipSize = ship.Cells().Count;

            if (shipSize <= 0 || shipSize > 4)
            {
                return(false);
            }
            List <eShip> res = ships.FindAll(delegate(eShip item)
            {
                return(item.Cells().Count == shipSize);
            });

            switch (shipSize)
            {
            case 1: return(res.Count < 4);

            case 2: return(res.Count < 3);

            case 3: return(res.Count < 2);

            case 4: return(res.Count < 1);

            default:
                return(false);
            }
        }
Пример #2
0
 protected bool HasSpace(eShip ship)
 {
     foreach (eCell cell in ship.Cells())
     {
         if (!IsCellsAroundEmpty(cell))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #3
0
        protected bool AddShip_(eShip ship)
        {
            List <eCell> copyShipCells = new List <eCell>();

            foreach (eCell cell in ship.Cells())
            {
                eCell copyItem = cells.Find(delegate(eCell item)
                {
                    return(item.X == cell.X && item.Y == cell.Y);
                });
                if (copyItem == null)
                {
                    return(false);
                }
                copyShipCells.Add(copyItem);
            }
            ships.Add(new eShip(copyShipCells));
            return(true);
        }