Пример #1
0
        public bool AddShip(shipPlacement placement)
        {
            switch (placement.placement)
            {
            case PlaceMode.HCarrier:
                if (placement.x / 32 > 10 - 5 || placement.x < 0)
                {
                    return(false);
                }
                if (placement.y / 32 > 10 || placement.y < 0)
                {
                    return(false);
                }
                ships.Add(new AircraftCarrier(placement.x, placement.y, true, BoardPlacement.Carrier));
                return(true);

            case PlaceMode.HBattleship:
                if (placement.x / 32 > 10 - 4 || placement.x < 0)
                {
                    return(false);
                }
                if (placement.y / 32 > 10 || placement.y < 0)
                {
                    return(false);
                }
                ships.Add(new Battleship(placement.x, placement.y, true, BoardPlacement.Battleship));
                return(true);

            case PlaceMode.HSubmarine:
                if (placement.x / 32 > 10 - 3 || placement.x < 0)
                {
                    return(false);
                }
                if (placement.y / 32 > 10 || placement.y < 0)
                {
                    return(false);
                }
                ships.Add(new Submarine(placement.x, placement.y, true, BoardPlacement.Submarine));
                return(true);

            case PlaceMode.HDestroyer:
                if (placement.x / 32 > 10 - 3 || placement.x < 0)
                {
                    return(false);
                }
                if (placement.y / 32 > 10 || placement.y < 0)
                {
                    return(false);
                }
                ships.Add(new Destroyer(placement.x, placement.y, true, BoardPlacement.Destroyer));
                return(true);

            case PlaceMode.HBoat:
                if (placement.x / 32 > 10 - 2 || placement.x < 0)
                {
                    return(false);
                }
                if (placement.y / 32 > 10 || placement.y < 0)
                {
                    return(false);
                }
                ships.Add(new PatrolBoat(placement.x, placement.y, true, BoardPlacement.Boat));
                return(true);

            case PlaceMode.VCarrier:
                if (placement.x / 32 > 10 || placement.x < 0)
                {
                    return(false);
                }
                if (placement.y / 32 > 10 - 5 || placement.y < 0)
                {
                    return(false);
                }
                ships.Add(new AircraftCarrier(placement.x, placement.y, false, BoardPlacement.Carrier));
                return(true);

            case PlaceMode.VBattleship:
                if (placement.x / 32 > 10 || placement.x < 0)
                {
                    return(false);
                }
                if (placement.y / 32 > 10 - 4 || placement.y < 0)
                {
                    return(false);
                }
                ships.Add(new Battleship(placement.x, placement.y, false, BoardPlacement.Battleship));
                return(true);

            case PlaceMode.VSubmarine:
                if (placement.x / 32 > 10 || placement.x < 0)
                {
                    return(false);
                }
                if (placement.y / 32 > 10 - 3 || placement.y < 0)
                {
                    return(false);
                }
                ships.Add(new Submarine(placement.x, placement.y, false, BoardPlacement.Submarine));
                return(true);

            case PlaceMode.VDestroyer:
                if (placement.x / 32 > 10 || placement.x < 0)
                {
                    return(false);
                }
                if (placement.y / 32 > 10 - 3 || placement.y < 0)
                {
                    return(false);
                }
                ships.Add(new Destroyer(placement.x, placement.y, false, BoardPlacement.Destroyer));
                return(true);

            case PlaceMode.VBoat:
                if (placement.x / 32 > 10 || placement.x < 0)
                {
                    return(false);
                }
                if (placement.y / 32 > 10 - 2 || placement.y < 0)
                {
                    return(false);
                }
                ships.Add(new PatrolBoat(placement.x, placement.y, false, BoardPlacement.Boat));
                return(true);
            }
            return(false);
        }
Пример #2
0
 public bool PlaceShip(int uid, shipPlacement placement)
 {
     return(gameState.GetPlayerByUid(uid).AddShip(placement));
 }