Esempio n. 1
0
        /// <summary>
        ///  Spawns a certain Number of Ships
        /// </summary>
        public void SpawnShips()
        {
            sSelectShipList    = new List <AShip>();
            sAllShipList       = new List <AShip>();
            mAttackingShipList = new List <IBattleObject>();
            mDefendingShipList = new List <IBattleObject>();
            mRepairingShipList = new List <AShip>();
            mEnteringShipList  = new List <BattleShip>();

            //instanziation
            FlagShip    testShip        = new FlagShip(new Vector2(20, 20));
            BattleShip  testBattleShip  = new BattleShip(new Vector2(300, 100));
            BattleShip  testBattleShip2 = new BattleShip(new Vector2(550, 900));
            FisherShip  testFisherShip  = new FisherShip(new Vector2(550, 700));
            TradingShip testTradingShip = new TradingShip(new Vector2(100, 1000));

            //initialization
            testBattleShip.Initialize();
            testBattleShip2.Initialize();
            testShip.Initialize();
            testFisherShip.Initialize();
            testTradingShip.Initialize();

            //Owned
            testBattleShip.Owned = true;

            //add to List
            sAllShipList.Add(testShip);
            sAllShipList.Add(testBattleShip);
            sAllShipList.Add(testBattleShip2);
            sAllShipList.Add(testFisherShip);
            sAllShipList.Add(testTradingShip);

            //testing behaviour
            //testBattleShip2.Defend(mPathFinder.CalculatePath(testBattleShip2.Position, new Vector2(100, 150), true));
            testTradingShip.Defend(mPathFinder.CalculatePath(testTradingShip.Position, new Vector2(100, 100), true));//4700, 1400
            mDefendingShipList.Add(testTradingShip);
            //mDefendingShipList.Add(testBattleShip2);


            //testing repairing
            testBattleShip.Hp = 80;

            //testing QuadTree:
            mShipsQuadTree = new QuadTree(0, new Rectangle(0, 0, 5760, 5760));//testmap size is 1000*1000
        }
Esempio n. 2
0
        /// <summary>
        ///  Creates all Ships according to the specified numbers.
        ///  BattleShips and TradingShips need to be added to the allShipsList in the AIShipManager
        /// </summary>
        //bShipCount + tShipCount muss >= 1 sein!!
        public Fleet(Vector2 position, int bShipsCount, int tShipsCount,
                     List <BattleShip> enterList, List <IBattleObject> attackingList, List <IBattleObject> defendingList, List <AShip> repairingList)
        {
            BattleShips  = new List <BattleShip>();
            TradingShips = new List <TradingShip>();
            MarkedShips  = new List <AShip>();

            mEnteringShipsList  = enterList;
            mAttackingShipsList = attackingList;
            mRepairingShipsList = repairingList;
            mDefendingShipsList = defendingList;
            //FlagShip
            if (bShipsCount >= 1)
            {
                var bShip = new BattleShip(position)
                {
                    Owned        = false,
                    mShipTexture = Game1.mContentManager.Load <Texture2D>("Ships/enemy_ship_texture")
                };
                bShip.Initialize();
                BattleShips.Add(bShip);
                bShipsCount--;
                FlagShip = bShip;
                FlagShip.MovementSpeed = 0.25f;
            }
            else if (tShipsCount >= 1)
            {
                var tShip = new TradingShip(position);
                tShip.Initialize();
                TradingShips.Add(tShip);
                tShipsCount--;
                FlagShip = tShip;
                FlagShip.MovementSpeed = 0.25f;
            }

            //simple spawn algorithm for testing
            for (var i = 0; i < bShipsCount + tShipsCount; i++)
            {
                //second row
                if (i >= (bShipsCount + tShipsCount) / 2)
                {
                    if (i <= bShipsCount)                                                                                                               //spawn battleShip
                    {
                        var bShip = new BattleShip(new Vector2((position.X - (((bShipsCount + tShipsCount) / 2) * 75) + (i * 50)), position.Y + 100f)); // spawn a row of ships on top of the FlagShip
                        BattleShips.Add(bShip);
                    }
                    else if (i <= bShipsCount + tShipsCount)//spawn tradingShip
                    {
                        var tShip = new TradingShip(new Vector2((position.X - (((bShipsCount + tShipsCount) / 2) * 75) + (i * 50)),
                                                                position.Y + 100f))
                        {
                            MovementSpeed = 0.25f
                        };
                        TradingShips.Add(tShip);
                    }
                }
                else//first row
                {
                    if (i <= bShipsCount)//spawn battleShip
                    {
                        var bShip = new BattleShip(new Vector2((position.X - (((bShipsCount + tShipsCount) / 4) * 50) + (i * 50)), position.Y - 100f));// spawn a row of ships on top of the FlagShip
                        bShip.Initialize();
                        BattleShips.Add(bShip);
                    }
                    else if (i <= bShipsCount + tShipsCount)//spawn tradingShip
                    {
                        var tShip = new TradingShip(new Vector2((position.X - (((bShipsCount + tShipsCount) / 4) * 50) + (i * 50)), position.Y - 100f));
                        tShip.Initialize();
                        tShip.MovementSpeed = 0.25f;
                        TradingShips.Add(tShip);
                    }
                }
            }
        }