Пример #1
0
 public bool AddShip(ShipInstance ship)
 {
     if (TestShipDuplicate(ship.ship))
     {
         throw new FaultException("Duplicate Ship (cheater)");
     }
     else if (ship.pos.x >= 0 && ship.pos.x < boardSize &&
              (ship.rotation != Rotation.RIGHT || ship.pos.x + ship.ship.length < boardSize) && //EITHER ship is not pointing right, or if it is pointing right then is within grid
              ship.pos.y >= 0 && ship.pos.y < boardSize &&
              (ship.rotation != Rotation.DOWN || ship.pos.y + ship.ship.length < boardSize))
     {
         if (TestShipPosition(ship))
         {
             ships.Add(ship);
             return(true);
         }
         else
         {
             throw new FaultException("Overlapping with another ship");
         }
     }
     else
     {
         throw new FaultException("Going outside grid");
     }
 }
Пример #2
0
 public bool AddShip(ShipInstance ship)
 {
     if (TestShipDuplicate(ship.ship)) {
         throw new FaultException("Duplicate Ship (cheater)");
     }
     else if (ship.pos.x >= 0 && ship.pos.x < boardSize &&
         (ship.rotation != Rotation.RIGHT || ship.pos.x + ship.ship.length < boardSize) && //EITHER ship is not pointing right, or if it is pointing right then is within grid
         ship.pos.y >= 0 && ship.pos.y < boardSize &&
         (ship.rotation != Rotation.DOWN || ship.pos.y + ship.ship.length < boardSize))
     {
         if (TestShipPosition(ship))
         {
             ships.Add(ship);
             return true;
         }
         else
         {
             throw new FaultException("Overlapping with another ship");
         }
     }
     else
     {
         throw new FaultException("Going outside grid");
     }
 }
Пример #3
0
 public bool TestShipPosition(ShipInstance ship)
 {
     foreach (ShipInstance shipinst in ships)
     {
         if (shipinst.CheckOverlap(ship))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #4
0
        public bool CheckOverlap(ShipInstance other)
        {
            List<Position> path = GetPath();
            List<Position> otherpath = other.GetPath();

            foreach (Position pos in path)
            {
                if (otherpath.Contains(pos))
                {
                    return true;
                }
            }
            return false;
        }
Пример #5
0
        public bool CheckOverlap(ShipInstance other)
        {
            List <Position> path      = GetPath();
            List <Position> otherpath = other.GetPath();

            foreach (Position pos in path)
            {
                if (otherpath.Contains(pos))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #6
0
        public bool AddShip(int playerId, ShipInstance ship)
        {
            //clients only have access to the ship ID field
            // read this out and inject in the real ship instance.
            ship.ship = gb.ships[ship.shipId];
            bool result = gb.games[playerId].AddShip(ship);

            //automate ready
            if (gb.games[playerId].ships.Count >= gb.ships.Count) //if pships > gbships SHOULD never happem, but.. you never know
            {
                setReady(playerId);
            }
            return result;
        }
Пример #7
0
        public bool AddShip(int playerId, ShipInstance ship)
        {
            //clients only have access to the ship ID field
            // read this out and inject in the real ship instance.
            ship.ship = gb.ships[ship.shipId];
            bool result = gb.games[playerId].AddShip(ship);

            //automate ready
            if (gb.games[playerId].ships.Count >= gb.ships.Count) //if pships > gbships SHOULD never happem, but.. you never know
            {
                setReady(playerId);
            }
            return(result);
        }
Пример #8
0
        public ShotType FireAtShip(Position pos)
        {
            ShipInstance hit = HitsShip(pos);

            if (hit != null)
            {
                shots[pos.x + (pos.y * boardSize)] = ShotType.HIT;
            }
            else
            {
                shots[pos.x + (pos.y * boardSize)] = ShotType.MISS;
            }
            return(shots[pos.x + (pos.y * boardSize)]);
        }
Пример #9
0
 public bool TestShipPosition(ShipInstance ship)
 {
     foreach (ShipInstance shipinst in ships) {
         if (shipinst.CheckOverlap (ship))
             return false;
     }
     return true;
 }