Пример #1
0
        //public Unit CreateUnit(UnitProps unitProps, UnitStats unitStats)
        //{
        //    Unit unit = new Unit(unitProps, unitStats);

        //    return unit;
        //}

        public Unit CreateUnit(ArrayList objects)
        {
            UnitProps        unitProps  = new UnitProps();
            List <byte>      commonByte = new List <byte>();
            myRectangle      location   = new myRectangle();
            Texture2D        tex        = null;
            List <UnitState> usts       = new List <UnitState>();

            foreach (var obj in objects)
            {
                if (obj is List <UnitState> )
                {
                    usts = obj as List <UnitState>;
                    tex  = usts[0].stateTexture;
                }

                if (obj is List <Texture2D> )
                {
                    unitProps.DistributeTexture(obj as List <Texture2D>);
                }

                if (obj is myRectangle)
                {
                    location = obj as myRectangle;
                }

                if (obj is ForAsUnitStats)
                {
                    unitProps.ConvertUnitStats(obj as ForAsUnitStats);
                }

                if (obj is List <byte> )
                {
                    commonByte = obj as List <byte>;
                }
            }

            Unit unit = new Unit(unitProps, location.rect, tex);

            unit.DistributeCommons(commonByte);
            unit.DistributeStates(usts);

            return(unit);
        }
Пример #2
0
 public void SetPosition(myRectangle pos)
 {
     Location = pos.rect;
     unitProps.ReInicHealthBar(Location);
 }
Пример #3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            base.Initialize();

            store.r = new Random();

            List <UnitState> uStates = new List <UnitState>();

            uStates.Add(new NormalState(Content.Load <Texture2D>("Circle0")));
            uStates.Add(new AtackState(Content.Load <Texture2D>("Circle1")));
            uStates.Add(new DefenceState(Content.Load <Texture2D>("Circle2")));
            uStates.Add(new ShootState(Content.Load <Texture2D>("CircleShoot")));

            List <UnitState> uStates2 = new List <UnitState>();

            uStates2.Add(new NormalState(Content.Load <Texture2D>("Rect0")));
            uStates2.Add(new AtackState(Content.Load <Texture2D>("Rect1")));
            uStates2.Add(new DefenceState(Content.Load <Texture2D>("Rect2")));
            uStates2.Add(new ShootState(Content.Load <Texture2D>("RectShoot")));


            List <Texture2D> tex = new List <Texture2D>();

            tex.Add(Content.Load <Texture2D>("GreenHealth"));
            tex.Add(Content.Load <Texture2D>("Star"));
            tex.Add(Content.Load <Texture2D>("DamageEffectTexture"));

            myRectangle myRect = new myRectangle();


            ForAsUnitStats uStats = new ForAsUnitStats();

            uStats.unitStats.atack           = 20;
            uStats.unitStats.atackRange      = 20;
            uStats.unitStats.atackTime       = 50;
            uStats.unitStats.defenceTime     = 60;
            uStats.unitStats.health          = 300;
            uStats.unitStats.maxHealth       = 300;
            uStats.unitStats.level           = 0;
            uStats.unitStats.rangeUnit       = false;
            uStats.unitStats.rangeAtackPower = 0;
            uStats.unitStats.rangeAtackRange = 0;
            uStats.unitStats.rangeAtackTime  = 0;
            uStats.unitStats.speed           = 1;
            uStats.unitStats.shootAccuracy   = 15;

            List <byte> commonBytes = new List <byte>();

            commonBytes.Add(0);
            commonBytes.Add(0);
            commonBytes.Add(0);

            for (int i = 0; i < 8; i++)
            {
                //int x = 10;
                //int y = 10;
                //while (!(unitFactory.IsFreePlace(units, x, y)))
                //{
                //    x = store.r.Next(1200);
                //    y = store.r.Next(600);
                //}
                myRect.rect = new Rectangle(100, 40 + i * 80, 50, 50);

                store.objects.Add(uStates);
                store.objects.Add(tex);
                store.objects.Add(myRect);
                store.objects.Add(uStats);
                store.objects.Add(commonBytes);
                units.Add(unitFactory.CreateUnit(store.objects));

                store.objects.Clear();
            }

            uStats.unitStats.atack           = 20;
            uStats.unitStats.atackRange      = 20;
            uStats.unitStats.atackTime       = 50;
            uStats.unitStats.defenceTime     = 60;
            uStats.unitStats.health          = 50;
            uStats.unitStats.maxHealth       = 50;
            uStats.unitStats.level           = 0;
            uStats.unitStats.rangeUnit       = true;
            uStats.unitStats.rangeAtackPower = 1.1;
            uStats.unitStats.rangeAtackRange = 600;
            uStats.unitStats.rangeAtackTime  = 700;
            uStats.unitStats.shootAccuracy   = 15;

            for (int i = 0; i < 8; i++)
            {
                //int x = 10;
                //int y = 10;
                //while (!(unitFactory.IsFreePlace(units, x, y)))
                //{
                //    x = store.r.Next(1200);
                //    y = store.r.Next(600);
                //}
                myRect.rect = new Rectangle(30, 40 + i * 80, 50, 50);

                store.objects.Add(uStates);
                store.objects.Add(tex);
                store.objects.Add(myRect);
                store.objects.Add(uStats);
                store.objects.Add(commonBytes);
                units.Add(unitFactory.CreateUnit(store.objects));

                store.objects.Clear();
            }



            ForAsUnitStats uStats1 = new ForAsUnitStats();

            uStats1.unitStats.atack           = 29;
            uStats1.unitStats.atackRange      = 20;
            uStats1.unitStats.atackTime       = 70;
            uStats1.unitStats.defenceTime     = 40;
            uStats1.unitStats.health          = 300;
            uStats1.unitStats.maxHealth       = 300;
            uStats1.unitStats.level           = 0;
            uStats1.unitStats.rangeUnit       = false;
            uStats1.unitStats.rangeAtackPower = 0;
            uStats1.unitStats.rangeAtackRange = 0;
            uStats1.unitStats.rangeAtackTime  = 0;
            uStats1.unitStats.speed           = 1;
            uStats1.unitStats.shootAccuracy   = 15;

            commonBytes.Clear();

            commonBytes.Add(1);
            commonBytes.Add(0);
            commonBytes.Add(0);

            for (int i = 0; i < 8; i++)
            {
                //int x = 10;
                //int y = 10;
                //while (!(unitFactory.IsFreePlace(units, x, y)))
                //{
                //    x = store.r.Next(1200);
                //    y = store.r.Next(600);
                //}
                myRect.rect = new Rectangle(1000, 40 + i * 80, 50, 50);

                store.objects.Add(uStates2);
                store.objects.Add(tex);
                store.objects.Add(myRect);
                store.objects.Add(uStats1);
                store.objects.Add(commonBytes);
                units.Add(unitFactory.CreateUnit(store.objects));

                store.objects.Clear();
            }

            uStats1.unitStats.atack           = 30;
            uStats1.unitStats.atackRange      = 20;
            uStats1.unitStats.atackTime       = 70;
            uStats1.unitStats.defenceTime     = 40;
            uStats1.unitStats.health          = 50;
            uStats1.unitStats.maxHealth       = 50;
            uStats1.unitStats.level           = 0;
            uStats1.unitStats.rangeUnit       = true;
            uStats1.unitStats.rangeAtackPower = 1;
            uStats1.unitStats.rangeAtackRange = 600;
            uStats1.unitStats.rangeAtackTime  = 600;
            uStats1.unitStats.shootAccuracy   = 15;

            for (int i = 0; i < 8; i++)
            {
                //int x = 10;
                //int y = 10;
                //while (!(unitFactory.IsFreePlace(units, x, y)))
                //{
                //    x = store.r.Next(1200);
                //    y = store.r.Next(600);
                //}
                myRect.rect = new Rectangle(1100, 40 + i * 80, 50, 50);

                store.objects.Add(uStates2);
                store.objects.Add(tex);
                store.objects.Add(myRect);
                store.objects.Add(uStats1);
                store.objects.Add(commonBytes);
                units.Add(unitFactory.CreateUnit(store.objects));

                store.objects.Clear();
            }



            List <string> stats = new List <string>();

            stats.Add("atack = ");
            stats.Add("atackRange = ");
            stats.Add("atackTime = ");
            stats.Add("defenceTime = ");
            stats.Add("maxHealth = ");
            stats.Add("rangeAtackPower = ");
            stats.Add("rangeAtackRange = ");
            stats.Add("rangeAtackTime = ");

            store.createUnitForm.CreateElements(stats);


            foreach (var unit in units)
            {
                unit.ai = ai;
            }
        }