public Ship(string model, ShipSize size)
 {
     Model = model;
     Size = size;
     Hardpoints = new List<Hardpoint>();
     Compartments = new List<Compartment>();
 }
Ejemplo n.º 2
0
        public Enum GetRandomShipType(ShipSize shipSize)
        {
            switch (shipSize)
            {
            case ShipSize.AirCarrier:
                var values = Enum.GetValues(typeof(AirCarrierType));
                return((AirCarrierType)values.GetValue(RandomHelper.Random.Next(values.Length)));

            case ShipSize.Battleship:
                values = Enum.GetValues(typeof(BattleshipType));
                return((BattleshipType)values.GetValue(RandomHelper.Random.Next(values.Length)));

            case ShipSize.Cruiser:
                values = Enum.GetValues(typeof(CruiserType));
                return((CruiserType)values.GetValue(RandomHelper.Random.Next(values.Length)));

            case ShipSize.Destroyer:
                return(DestroyerType.Straight);

            case ShipSize.Submarine:
                return(SubmarineType.Square);

            default:
                throw new InvalidEnumArgumentException();
            }
        }
Ejemplo n.º 3
0
    public override void SetShipScaleBySize(ShipSize shipSize)
    {
        float tempSize = (float)shipSize / 50.0f;

        tempSize = tempSize > 0.5f ? 0.5f : tempSize;
        this.transform.localScale = Vector3.one * tempSize;
    }
Ejemplo n.º 4
0
 public Slot(Vector2 offset, Vector2 inwards, ShipSize size)
 {
     this.Offset           = offset;
     this.InwardsDirection = inwards;
     this.Size             = size;
     this.CurrentShip      = null;
 }
Ejemplo n.º 5
0
        private Ship AllocateShip(ShipSize shipSize, IEnumerable <Ship> battleships)
        {
            var eqComparer            = new BattleCoordinateEqualityComparer();
            var battleshipCoordinates = battleships.SelectMany(x => x.Coordinates).ToList();

            var availableCoords = this.coordinates
                                  .Except(battleshipCoordinates, eqComparer)
                                  .ToList();

            var availablePositions = availableCoords.SelectMany(c => new[]
            {
                ShipPosition.Vertical(c, shipSize),
                ShipPosition.Horizontal(c, shipSize)
            });

            var validPositions = availablePositions.Where(x => x.IsValid).ToList();

            if (!validPositions.Any())
            {
                return(null);
            }

            var nonOverlappingPositions = validPositions
                                          .Where(x => !x.Coordinates.Intersect(battleshipCoordinates, eqComparer).Any())
                                          .ToList();

            var r = this.random.Next(nonOverlappingPositions.Count);

            var selectedPosition = nonOverlappingPositions[r];

            return(new Ship(selectedPosition));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the first available slot the can fit the ship of that size.
        /// Priotitizes placing it in the smallest possible slot, although small ships can dock in
        /// slots intended for larger ships.
        /// </summary>
        /// <param name="size">The size of the ship to fit in.</param>
        /// <returns>The index of the slot, or -1 if none were available.</returns>
        public int GetOpenSlot(ShipSize size)
        {
            int      bestFit     = -1;
            ShipSize bestFitSize = ShipSize.Large;

            for (int i = 0; i < Slots.Length; i++)
            {
                var spot = Slots[i];

                if (spot.CurrentShip != null)
                {
                    continue;
                }

                if (spot.Size.IsLargerOrEqual(size))
                {
                    if (spot.Size.IsSmallerOrEqual(bestFitSize))
                    {
                        bestFit     = i;
                        bestFitSize = spot.Size;
                    }
                }
            }

            return(bestFit);
        }
Ejemplo n.º 7
0
    public void UpdateShipSize(ShipSize shipSize)
    {
        currentShipSize = shipSize;

        switch (currentShipSize)
        {
        case ShipSize.small:
            smallContainer.SetActive(true);
            MediContainer.SetActive(false);
            BigContainer.SetActive(false);
            inerSpots = inerSmallSpots;
            farSpots  = farSmallSpots;
            splitIn   = 9;
            break;

        case ShipSize.medium:
            smallContainer.SetActive(false);
            MediContainer.SetActive(true);
            BigContainer.SetActive(false);
            inerSpots = inerMedSpots;
            farSpots  = farMedSpots;
            splitIn   = 9;
            break;

        case ShipSize.big:
            smallContainer.SetActive(false);
            MediContainer.SetActive(false);
            BigContainer.SetActive(true);
            inerSpots = inerBigSpots;
            farSpots  = farBigSpots;
            splitIn   = 14;
            break;
        }
    }
Ejemplo n.º 8
0
 // Update is called once per frame
 void Update()
 {
     if (previousShipSize != currentShipSize)
     {
         previousShipSize = currentShipSize;
         UpdateShipSize(currentShipSize);
     }
 }
Ejemplo n.º 9
0
 public Ship(long EDID, string Model, ShipSize Size)
 {
     this.EDID    = EDID;
     this.Model   = Model;
     this.Size    = Size;
     Hardpoints   = new List <Hardpoint>();
     Compartments = new List <Compartment>();
 }
Ejemplo n.º 10
0
 public Ship(long EDID, string Model, ShipSize Size)
 {
     this.EDID = EDID;
     this.Model = Model;
     this.Size = Size;
     Hardpoints = new List<Hardpoint>();
     Compartments = new List<Compartment>();
 }
Ejemplo n.º 11
0
        public void ShouldCreateInvalidHorizontalPosition(string value, ShipSize size)
        {
            var cb    = new TestCoordinateBoundary(10, 10);
            var coord = cb.CoordinateFromInput(value);

            var result = ShipPosition.Horizontal(coord, size);

            Assert.False(result.IsValid);
            Assert.Null(result.Coordinates);
        }
Ejemplo n.º 12
0
        public void ShouldCreateHorizontalCoordinates(string value, ShipSize size)
        {
            var cb    = new TestCoordinateBoundary(10, 10);
            var coord = cb.CoordinateFromInput(value);

            var result = ShipPosition.Horizontal(coord, size);

            Assert.True(result.IsValid);
            Assert.NotNull(result.Coordinates);
            Assert.True(result.Coordinates.Count() == (int)size);
        }
Ejemplo n.º 13
0
 public static Texture2D LoadShipImage(int ShipID,ShipSize size,bool isBroken = false)
 {
     switch (size)
     {
         case ShipSize.Small:
             return Load64Img(ShipID, isBroken);
         case ShipSize.Medium:
             return Load128Img(ShipID, isBroken);
         case ShipSize.Large:
             return Load1024Img(ShipID, isBroken);
         default:
             return null;
     }
 }
Ejemplo n.º 14
0
        public static Texture2D LoadShipImage(int ShipID, ShipSize size, bool isBroken = false)
        {
            switch (size)
            {
            case ShipSize.Small:
                return(Load64Img(ShipID, isBroken));

            case ShipSize.Medium:
                return(Load128Img(ShipID, isBroken));

            case ShipSize.Large:
                return(Load1024Img(ShipID, isBroken));

            default:
                return(null);
            }
        }
Ejemplo n.º 15
0
        // Define more prefabs here...

        internal static PrefabGrid GetBackup(ShipSize size)
        {
            switch (size)
            {
            case ShipSize.Large:
                return(RocketAirBackup);

            case ShipSize.Medium:
                return(MediumAirBackup);

            case ShipSize.Small:
                return(LightAirBackup);

            default:
                throw new ArgumentException(size + " air backup not found!");
            }
        }
Ejemplo n.º 16
0
        internal static PrefabGrid GetGroundTransport(ShipSize size)
        {
            switch (size)
            {
            case ShipSize.Large:
                return(LargeGroundTransport);

            case ShipSize.Medium:
                return(MediumGroundTransport);

            case ShipSize.Small:
                return(LightGroundTransport);

            default:
                throw new ArgumentException(size + " ground transport not found!");
            }
        }
Ejemplo n.º 17
0
        private static PrefabGrid GetGroundEscort(ShipSize size)
        {
            switch (size)
            {
            case ShipSize.Large:
                return(RocketGroundEscort);

            case ShipSize.Medium:
                return(MediumGroundEscort);

            case ShipSize.Small:
                return(LightGroundEscort);

            default:
                throw new ArgumentException(size + " ground escort not found!");
            }
        }
Ejemplo n.º 18
0
        public Upgrade(int id, UpgradeType upgradeType, int cost, string name, string description, List <string> faq, List <Faction> factions, ShipSize shipSize,
                       List <ShipType> shipThatCanUse, bool isWeapon, bool isUnique, bool isLimited, int numberOfUpgradeSlots, bool isDualCard, bool isTieOnly, bool isXWingOnly,
                       Dictionary <UpgradeType, int> upgradesAdded, Dictionary <UpgradeType, int> upgradesRemoved, int requiresPilotSkill, List <Action> requiresActions,
                       List <int> requiresUpgrades, List <Action> addsActions, int addsPilotSkill, int numberOwned, List <ExpansionType> inExpansion, string canonicalName)
        {
            this.isUpgrade            = true;
            this.imageFilePath        = @"Upgrade Cards\" + id.ToString();
            this.id                   = id;
            this.upgradeType          = upgradeType;
            this.cost                 = cost;
            this.name                 = name;
            this.description          = description;
            this.faq                  = faq;
            this.factions             = factions;
            this.shipSize             = shipSize;
            this.shipThatCanUse       = shipThatCanUse;
            this.isWeapon             = isWeapon;
            this.isUnique             = isUnique;
            this.isLimited            = isLimited;
            this.numberOfUpgradeSlots = numberOfUpgradeSlots;
            this.isDualCard           = isDualCard;
            this.isTieOnly            = isTieOnly;
            this.isXWingOnly          = isXWingOnly;
            this.upgradesAdded        = upgradesAdded;
            this.upgradesRemoved      = upgradesRemoved;
            this.requiresPilotSkill   = requiresPilotSkill;
            this.requiresActions      = requiresActions;
            this.requiresUpgrades     = requiresUpgrades;
            this.addsActions          = addsActions;
            this.addsPilotSkill       = addsPilotSkill;
            this._numberOwned         = numberOwned;
            this.canonicalName        = canonicalName;

            foreach (ExpansionType expansionType in inExpansion)
            {
                if (this.inExpansion.ContainsKey(expansionType) == false)
                {
                    this.inExpansion[expansionType] = 1;
                }
                else
                {
                    this.inExpansion[expansionType]++;
                }
            }
        }
Ejemplo n.º 19
0
 public Ship(int id, ShipType shipType, string name, ShipSize shipSize, bool isTIE, bool isXWing, int attack, int agility, int hull, int shields,
             List <Action> actions, Faction faction, Dictionary <int, List <int> > maneuvers, string uniqueManeuverId, string canonicalName)
 {
     this.id               = id;
     this.shipType         = shipType;
     this.name             = name;
     this.shipSize         = shipSize;
     this.isTIE            = isTIE;
     this.isXWing          = isXWing;
     this.attack           = attack;
     this.agility          = agility;
     this.hull             = hull;
     this.shields          = shields;
     this.actions          = actions;
     this.faction          = faction;
     this.maneuvers        = maneuvers;
     this.uniqueManeuverId = uniqueManeuverId;
     this.canonicalName    = canonicalName;
 }
Ejemplo n.º 20
0
    public static float SizeToFloat(ShipSize size)
    {
        switch (size)
        {
        case (ShipSize.XS):
            return(24);

        case (ShipSize.S):
            return(32);

        case (ShipSize.M):
            return(48);

        case (ShipSize.L):
            return(64);

        case (ShipSize.XL):
            return(96);
        }
        return(0);
    }
Ejemplo n.º 21
0
    // Use this for initialization
    void Start()
    {
        movementSelected = false;
        mSize            = ShipSize.Small;
        shipsInRange     = new Dictionary <int, List <Ship> >();
        shipsInRange.Add(1, new List <Ship>());
        shipsInRange.Add(2, new List <Ship>());
        shipsInRange.Add(3, new List <Ship>());

        // Temp block to initialize the test moves this ship will have
        mShipMoves = new List <Movement>()
        {
            //hard left
            new Movement(this, "Hard Left 1 Speed", -transform.right, new Vector3(0f, -90f, 0f), 1f, 90f, 1f),
            //hard right
            new Movement(this, "Hard Right 1 Speed", transform.right, new Vector3(0f, 90f, 0f), 1f, 90f, 1f),
            // soft left
            new Movement(this, "Soft Left 1 Speed", -transform.right, new Vector3(0f, -45f, 0f), .5f, 45f, 1f),
            // soft right
            new Movement(this, "Soft Right 1 Speed", transform.right, new Vector3(0f, 45f, 0f), .5f, 45f, 1f),
            // straight
            new Movement(this, "Straight 1 Speed", transform.forward, new Vector3(0f, 0f, 0f), 0f, 0f, 1f)
        };
    }
Ejemplo n.º 22
0
 public static bool IsLargerOrEqual(this ShipSize self, ShipSize other)
 {
     return((int)self >= (int)other);
 }
Ejemplo n.º 23
0
 public static bool IsSmallerOrEqual(this ShipSize self, ShipSize other)
 {
     return((int)self <= (int)other);
 }
Ejemplo n.º 24
0
 internal static PrefabGrid GetEscort(UnitType unitType, ShipSize shipSize)
 {
     return(unitType == UnitType.Air ? GetAirEscort(shipSize) : GetGroundEscort(shipSize));
 }
Ejemplo n.º 25
0
        //поместить корабль в позицию (x, y)
        public bool PlaceShip(int x, int y, ShipSize ss, ShipPos sp)
        {
            x--; y--;
            //проверка границ
            if ((x < 0 || y < 0) ||
                (x > 9 || y > 9) ||
                (x + (int)ss * (sp == ShipPos.Horizontal ? 1 : 0) > 9) ||
                (y + (int)ss * (sp == ShipPos.Vertical ? 1 : 0)) > 9)
            {
                return(false);
            }

            int x1 = x, y1 = y;

            for (int i = 0; i < (int)ss + 1; i++)
            {
                //есть ли корабли ближе чем одна клетка
                if (x1 - 1 >= 0 && field[x1 - 1, y1] == Ship)
                {
                    return(false);
                }
                if (x1 + 1 <= 9 && field[x1 + 1, y1] == Ship)
                {
                    return(false);
                }
                if (y1 - 1 >= 0 && field[x1, y1 - 1] == Ship)
                {
                    return(false);
                }
                if (y1 + 1 <= 9 && field[x1, y1 + 1] == Ship)
                {
                    return(false);
                }
                if ((x1 - 1 >= 0 && y1 - 1 >= 0) && field[x1 - 1, y1 - 1] == Ship)
                {
                    return(false);
                }
                if ((x1 - 1 >= 0 && y1 + 1 <= 9) && field[x1 - 1, y1 + 1] == Ship)
                {
                    return(false);
                }
                if ((x1 + 1 <= 9 && y1 - 1 >= 0) && field[x1 + 1, y1 - 1] == Ship)
                {
                    return(false);
                }
                if ((x1 + 1 <= 9 && y1 + 1 <= 9) && field[x1 + 1, y1 + 1] == Ship)
                {
                    return(false);
                }
                if (field[x1, y1] == Ship)
                {
                    return(false);
                }
                if (sp == ShipPos.Horizontal)
                {
                    x1++;
                }
                else
                {
                    y1++;
                }
            }

            //поместить корабль
            for (int i = 0; i < (int)ss + 1; i++)
            {
                field[x, y] = Ship;
                if (sp == ShipPos.Horizontal)
                {
                    x++;
                }
                else
                {
                    y++;
                }
            }

            return(true);
        }
 /// <summary>
 /// Generates ship at random position.
 /// </summary>
 public Ship GenerateShip(ShipSize ship, Random random)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Reads pair of coordinates from console and checks if input is a ship and has correct size.
        /// </summary>

        public Ship ReadShip(ShipSize size)
        {
            Ship ship = new Ship();
            bool IsCompiled = false;
            int  m, n;

            while (IsCompiled == false)
            {
                string a = Console.ReadLine();
                if (a.Length == 5)
                {
                    if (a[2] == ' ')
                    {
                        m = (int)a[1];
                        n = (int)a[4];
                        if (a[0] < 91 && a[0] > 64 && a[3] < 91 && a[3] > 64)
                        {
                            ship.Start.X = a[0] - 'A';
                            ship.End.X   = a[3] - 'A';
                        }
                        else if (a[0] > 96 && a[0] < 123 && a[3] > 96 && a[3] < 123)
                        {
                            ship.Start.X = a[0] - 'a';
                            ship.End.X   = a[3] - 'a';
                        }
                        else
                        {
                            Console.WriteLine("Nermucir noric u ushadir! ");
                            continue;
                        }

                        ship.Start.Y = m;
                        ship.End.Y   = n;


                        if (ship.End.X - ship.Start.X == 0)
                        {
                            if (Math.Abs(ship.End.Y - ship.Start.Y) + 1 == (int)size)
                            {
                                return(ship);
                            }
                            else
                            {
                                Console.WriteLine("Nermucir noric u ushadir! ");
                                continue;
                            }
                        }
                        else if (ship.End.Y - ship.Start.Y == 0)
                        {
                            if (Math.Abs(ship.End.X - ship.Start.X) + 1 == (int)size)
                            {
                                return(ship);
                            }
                            else
                            {
                                Console.WriteLine("Nermucir noric u ushadir! ");
                                continue;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Nermucir noric u ushadir! ");
                        continue;
                    }
                }
                else
                {
                    Console.WriteLine("Nermucir noric u ushadir! ");
                    continue;
                }
            }
            return(default(Ship));
        }
 /// <summary>
 /// Reads pair of coordinates from console and checks if input is a ship and has correct size.
 /// </summary>
 public Ship ReadShip(ShipSize size)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 29
0
 public virtual void SetShipScaleBySize(ShipSize shipSize)
 {
 }