示例#1
0
        //public void GenerateBuilding() //Makes Buildings
        //{
        //    for (int i = 0; i < numBuildings; i++)
        //    {
        //        if (rd.Next(0, 2) == 0)
        //        {
        //            ResourceBuilding a = new ResourceBuilding(rd.Next(0, 20),
        //                                                      rd.Next(0, 20),
        //                                                      500,
        //                                                      (i % 2 == 0 ? 1 : 0),
        //                                                      "[RS]");
        //            buildings.Add(a);
        //        }
        //        else
        //        {
        //            FactoryBuilding f = new FactoryBuilding(rd.Next(0, 20),
        //                                                      rd.Next(0, 20),
        //                                                      500,
        //                                                      (i % 2 == 0 ? 1 : 0),
        //                                                      "[FS]");
        //            buildings.Add(f);
        //        }
        //    }

        //}

        public void Display(GroupBox groupBox)
        {
            //GenerateBuilding();
            groupBox.Controls.Clear();
            foreach (Unit u in units)
            {
                Button b = new Button();
                if (u is MeleeUnit)
                {
                    MeleeUnit mu = (MeleeUnit)u;
                    b.Size     = new Size(20, 20);
                    b.Location = new Point(mu.XPos * 20, mu.YPos * 20);
                    b.Text     = mu.Symbol;
                    if (mu.Faction == 0)
                    {
                        b.ForeColor = Color.Red;
                    }
                    else
                    {
                        b.ForeColor = Color.Green;
                    }
                    b.Click += Unit_Click;
                    groupBox.Controls.Add(b);
                }
                else
                {
                    RangedUnit ru = (RangedUnit)u;
                    b.Size     = new Size(20, 20);
                    b.Location = new Point(ru.XPos * 20, ru.YPos * 20);
                    b.Text     = ru.Symbol;
                    if (ru.Faction == 0)
                    {
                        b.ForeColor = Color.Red;
                    }
                    else
                    {
                        b.ForeColor = Color.Green;
                    }
                    b.Click += Unit_Click;
                    groupBox.Controls.Add(b);
                }
            }
            foreach (Building d in buildings)
            {
                Button bb = new Button();
                if (d is ResourceBuilding)
                {
                    ResourceBuilding Ab = (ResourceBuilding)d;
                    bb.Size     = new Size(40, 40);
                    bb.Location = new Point(Ab.buildingX * 20, Ab.buildingY * 20);
                    bb.Text     = Ab.buildingSymbol;
                    if (Ab.buildingFaction == 0)
                    {
                        bb.ForeColor = Color.Red;
                    }
                    else
                    {
                        bb.ForeColor = Color.Green;
                    }
                    bb.Click += Building_Click;
                    groupBox.Controls.Add(bb);
                }
                else
                {
                    FactoryBuilding FB = (FactoryBuilding)d;
                    bb.Size     = new Size(40, 40);
                    bb.Location = new Point(FB.buildingX * 20, FB.buildingY * 20);
                    bb.Text     = FB.buildingSymbol;
                    if (FB.buildingFaction == 0)
                    {
                        bb.ForeColor = Color.Red;
                    }
                    else
                    {
                        bb.ForeColor = Color.Green;
                    }
                    bb.Click += Building_Click;
                    groupBox.Controls.Add(bb);
                }
            }
        }
示例#2
0
        public void Update()
        {
            foreach (Building bs in map.Buildings)
            {
                if (bs is FactoryBuilding)
                {
                    FactoryBuilding fb = (FactoryBuilding)bs;
                    if (fb.ProductionSpeed % Round == 0)
                    {
                        map.Units.Add(fb.UnitSpawn());
                    }
                }
            }

            for (int i = 0; i < map.Units.Count; i++)
            {
                if (map.Units[i] is MeleeUnit)
                {
                    MeleeUnit mu = (MeleeUnit)map.Units[i];
                    // mu.Health = 10;//HandiCap
                    if (mu.Health <= mu.MaxHealth * 0.25)//Moves away if unit is damaged
                    {
                        mu.Move(r.Next(0, 4));
                    }
                    else
                    {
                        int  shortest = 100;
                        Unit closestM = mu;
                        foreach (Unit u in map.Units)
                        {
                            if (u is MeleeUnit)
                            {
                                MeleeUnit otherMu  = (MeleeUnit)u;
                                int       distance = Math.Abs(mu.XPos - otherMu.XPos)
                                                     + Math.Abs(mu.YPos - otherMu.YPos);
                                if (distance < shortest)
                                {
                                    shortest = distance;
                                    closestM = otherMu;
                                }
                            }
                        }
                        //Check in Range
                        int distanceTo = 0;
                        if (distanceTo <= mu.AttackRange)
                        {
                            mu.IsAttacking = true;
                            mu.Combat(closestM);
                        }
                        else//Move to closestM enemy unit!
                        {
                            if (closestM is MeleeUnit)
                            {
                                MeleeUnit closestMMu = (MeleeUnit)closestM;
                                if (mu.XPos > closestMMu.XPos)
                                {
                                    mu.Move(0);//North
                                }
                                else if (mu.XPos < closestMMu.XPos)
                                {
                                    mu.Move(2);//South
                                }
                                else if (mu.YPos > closestMMu.XPos)
                                {
                                    mu.Move(3);//West
                                }
                                else if (mu.YPos < closestMMu.XPos)
                                {
                                    mu.Move(1);//East
                                }
                            }
                            else if (closestM is RangedUnit)
                            {
                                RangedUnit closestMMu = (RangedUnit)closestM;
                                if (mu.XPos > closestMMu.XPos)
                                {
                                    mu.Move(0);//North
                                }
                                else if (mu.XPos < closestMMu.XPos)
                                {
                                    mu.Move(2);//South
                                }
                                else if (mu.YPos > closestMMu.XPos)
                                {
                                    mu.Move(3);//West
                                }
                                else if (mu.YPos < closestMMu.XPos)
                                {
                                    mu.Move(1);//East
                                }
                            }
                        }
                    }
                }
                if (map.Units[i] is RangedUnit)
                {
                    RangedUnit ru = (RangedUnit)map.Units[i];
                    if (ru.Health <= ru.MaxHealth * 0.25)//Moves away if unit is damaged
                    {
                        ru.Move(r.Next(0, 4));
                    }
                    else
                    {
                        int  shortest = 100;
                        Unit closestR = ru;
                        foreach (Unit u in map.Units)
                        {
                            if (u is RangedUnit)
                            {
                                RangedUnit otherRu  = (RangedUnit)u;
                                int        distance = Math.Abs(ru.XPos - otherRu.XPos)
                                                      + Math.Abs(ru.YPos - otherRu.YPos);
                                if (distance < shortest)
                                {
                                    shortest = distance;
                                    closestR = otherRu;
                                }
                            }
                        }
                        int distanceTo = 0;
                        if (distanceTo <= ru.AttackRange)
                        {
                            ru.IsAttacking = true;
                            ru.Combat(closestR);
                        }
                        else
                        {
                            if (closestR is MeleeUnit)
                            {
                                MeleeUnit closestMMu = (MeleeUnit)closestR;
                                if (ru.XPos > closestMMu.XPos)
                                {
                                    ru.Move(0);//North
                                }
                                else if (ru.XPos < closestMMu.XPos)
                                {
                                    ru.Move(2);//South
                                }
                                else if (ru.YPos > closestMMu.XPos)
                                {
                                    ru.Move(3);//West
                                }
                                else if (ru.YPos < closestMMu.XPos)
                                {
                                    ru.Move(1);//East
                                }
                            }
                            else if (closestR is RangedUnit)
                            {
                                RangedUnit closestMMu = (RangedUnit)closestR;
                                if (ru.XPos > closestMMu.XPos)
                                {
                                    ru.Move(0);//North
                                }
                                else if (ru.XPos < closestMMu.XPos)
                                {
                                    ru.Move(2);//South
                                }
                                else if (ru.YPos > closestMMu.XPos)
                                {
                                    ru.Move(3);//West
                                }
                                else if (ru.YPos < closestMMu.XPos)
                                {
                                    ru.Move(1);//East
                                }
                            }
                        }
                    }
                }
                if (map.Units[i] is WizardUnit)
                {
                    WizardUnit wu = (WizardUnit)map.Units[i];
                    if (wu.Health <= wu.MaxHealth * 0.25)//Moves away if unit is damaged
                    {
                        wu.Move(r.Next(0, 4));
                    }
                    else
                    {
                        int  shortest = 100;
                        Unit closestR = wu;
                        foreach (Unit u in map.Units)
                        {
                            if (u is WizardUnit)
                            {
                                WizardUnit otherWu  = (WizardUnit)u;
                                int        distance = Math.Abs(wu.XPos - otherWu.XPos)
                                                      + Math.Abs(wu.YPos - otherWu.YPos);
                                if (distance < shortest)
                                {
                                    shortest = distance;
                                    closestR = otherWu;
                                }
                            }
                        }
                        int distanceTo = 0;
                        if (distanceTo <= wu.AttackRange)
                        {
                            wu.IsAttacking = true;
                            wu.Combat(closestR);
                        }
                        else
                        {
                            if (closestR is MeleeUnit)
                            {
                                MeleeUnit closestMMu = (MeleeUnit)closestR;
                                if (wu.XPos > closestMMu.XPos)
                                {
                                    wu.Move(0);//North
                                }
                                else if (wu.XPos < closestMMu.XPos)
                                {
                                    wu.Move(2);//South
                                }
                                else if (wu.YPos > closestMMu.XPos)
                                {
                                    wu.Move(3);//West
                                }
                                else if (wu.YPos < closestMMu.XPos)
                                {
                                    wu.Move(1);//East
                                }
                            }
                            else if (closestR is RangedUnit)
                            {
                                RangedUnit closestMMu = (RangedUnit)closestR;
                                if (wu.XPos > closestMMu.XPos)
                                {
                                    wu.Move(0);//North
                                }
                                else if (wu.XPos < closestMMu.XPos)
                                {
                                    wu.Move(2);//South
                                }
                                else if (wu.YPos > closestMMu.XPos)
                                {
                                    wu.Move(3);//West
                                }
                                else if (wu.YPos < closestMMu.XPos)
                                {
                                    wu.Move(1);//East
                                }
                            }
                        }
                    }
                }
                //Added Neutral Wizard Faction[Task 3]
                if (map.Units[i] is RougeWizardUnit)
                {
                    RougeWizardUnit rwu = (RougeWizardUnit)map.Units[i];
                    rwu.Health = 30;
                    if (rwu.Health <= rwu.MaxHealth * 0.25)//Moves away if unit is damaged
                    {
                        rwu.Move(r.Next(0, 4));
                    }
                    else
                    {
                        int  shortest = 100;
                        Unit closestR = rwu;
                        foreach (Unit u in map.Units)
                        {
                            if (u is WizardUnit)
                            {
                                WizardUnit otherWu  = (WizardUnit)u;
                                int        distance = Math.Abs(rwu.XPos - otherWu.XPos)
                                                      + Math.Abs(rwu.YPos - otherWu.YPos);
                                if (distance < shortest)
                                {
                                    shortest = distance;
                                    closestR = otherWu;
                                }
                            }
                        }
                        int distanceTo = 0;
                        if (distanceTo <= rwu.AttackRange)
                        {
                            rwu.IsAttacking = true;
                            rwu.Combat(closestR);
                        }
                        else
                        {
                            if (closestR is MeleeUnit)
                            {
                                MeleeUnit closestMMu = (MeleeUnit)closestR;
                                if (rwu.XPos > closestMMu.XPos)
                                {
                                    rwu.Move(0);//North
                                }
                                else if (rwu.XPos < closestMMu.XPos)
                                {
                                    rwu.Move(2);//South
                                }
                                else if (rwu.YPos > closestMMu.XPos)
                                {
                                    rwu.Move(3);//West
                                }
                                else if (rwu.YPos < closestMMu.XPos)
                                {
                                    rwu.Move(1);//East
                                }
                            }
                            else if (closestR is RangedUnit)
                            {
                                RangedUnit closestMMu = (RangedUnit)closestR;
                                if (rwu.XPos > closestMMu.XPos)
                                {
                                    rwu.Move(0);//North
                                }
                                else if (rwu.XPos < closestMMu.XPos)
                                {
                                    rwu.Move(2);//South
                                }
                                else if (rwu.YPos > closestMMu.XPos)
                                {
                                    rwu.Move(3);//West
                                }
                                else if (rwu.YPos < closestMMu.XPos)
                                {
                                    rwu.Move(1);//East
                                }
                            }
                        }
                    }
                }
            }

            //

            map.Display(grpMap);
            round++;
        }
示例#3
0
        public void Generate()
        {
            for (int i = 0; i < numUnits; i++)//Generate Melee Unit.
            {
                if (rd.Next(0, 4) == 0)
                {
                    MeleeUnit m = new MeleeUnit(rd.Next(0, 20),
                                                rd.Next(0, 20),
                                                100,
                                                1,
                                                20,
                                                (i % 2 == 0 ? 1 : 0),
                                                "M",
                                                "Knight");
                    units.Add(m);
                }
                else if (rd.Next(0, 4) == 1) // Generate Ranged Unit
                {
                    RangedUnit r = new RangedUnit(rd.Next(0, 20),
                                                  rd.Next(0, 20),
                                                  100,
                                                  1,
                                                  20,
                                                  5,
                                                  (i % 2 == 0 ? 1 : 0),
                                                  "R",
                                                  "Musketeer");// [Update]: For task 3 I changed the units from wizards to musketeers as wizards are now their own unit type.
                    units.Add(r);
                }
                else if (rd.Next(0, 4) == 2)
                {
                    WizardUnit w = new WizardUnit(rd.Next(0, 20),
                                                  rd.Next(0, 20),
                                                  100,
                                                  1,
                                                  20,
                                                  5,
                                                  (i % 2 == 0 ? 1 : 0),
                                                  "W",
                                                  "Wizard");//Task 3: Added the wizard.
                    units.Add(w);
                }
                else //[Task 3] Generates Neutral Wizzards in their own faction.
                {
                    RougeWizardUnit wr = new RougeWizardUnit(rd.Next(0, 20),
                                                             rd.Next(0, 20),
                                                             100,
                                                             1,
                                                             20,
                                                             5,
                                                             (i % 2 == 0 ? 1 : 0),
                                                             "W",
                                                             "Neutral_Wizard");//Task 3: Added the Neutral wizard. aka Rouge wizard as they are in their own faction.
                    units.Add(wr);
                }
            }

            for (int j = 0; j < numBuildings; j++)
            {
                if (rd.Next(0, 2) == 0)
                {
                    ResourceBuilding a = new ResourceBuilding(rd.Next(0, 20),
                                                              rd.Next(0, 20),
                                                              500,
                                                              (j % 2 == 0 ? 1 : 0),
                                                              "[RS]");
                    buildings.Add(a);
                }
                else
                {
                    FactoryBuilding f = new FactoryBuilding(rd.Next(0, 20),
                                                            rd.Next(0, 20),
                                                            500,
                                                            (j % 2 == 0 ? 1 : 0),
                                                            "[FS]");
                    buildings.Add(f);
                }
            }
        }