Exemple #1
0
        public override (Unit, int) ClosestUnit(List <Unit> units)
        {
            int  shortest = 100;
            Unit closest  = this;

            //Closest Unit and Distance
            foreach (Unit u in units)
            {
                if (u is Melee_Unit)
                {
                    Melee_Unit otherMu  = (Melee_Unit)u;
                    int        distance = Math.Abs(this.Xpos - otherMu.Xpos)
                                          + Math.Abs(this.Ypos - otherMu.Ypos);
                    if (distance < shortest)
                    {
                        shortest = distance;
                        closest  = otherMu;
                    }
                }
                else if (u is Ranged_Unit)
                {
                    Ranged_Unit otherRu  = (Ranged_Unit)u;
                    int         distance = Math.Abs(this.Xpos - otherRu.Xpos)
                                           + Math.Abs(this.Ypos - otherRu.Ypos);
                    if (distance < shortest)
                    {
                        shortest = distance;
                        closest  = otherRu;
                    }
                }
            }
            return(closest, shortest);
        }
Exemple #2
0
        public void DisplayUnits(GroupBox groupBox)
        {
            //Num_Of_Rounds.Text = "Round : " + gE.round.ToString();

            //groupBox.Controls.Clear();

            foreach (Unit u in units)
            {
                Button newLabel = new Button();

                if (u is Melee_Unit)
                {
                    Melee_Unit mu = (Melee_Unit)u;
                    newLabel.Width    = 25;
                    newLabel.Height   = 25;
                    newLabel.Location = new Point(mu.Xpos * 20, mu.Ypos * 15);
                    newLabel.Text     = mu.Symbol;
                    if (mu.Team == "Blue")
                    {
                        newLabel.ForeColor = Color.Blue;
                    }
                    else
                    {
                        newLabel.ForeColor = Color.Red;
                    }
                }
                else if (u is Ranged_Unit)
                {
                    Ranged_Unit ru = (Ranged_Unit)u;
                    newLabel.Width    = 25;
                    newLabel.Height   = 25;
                    newLabel.Location = new Point(ru.Xpos * 20, ru.Ypos * 15);
                    newLabel.Text     = ru.Symbol;
                    if (ru.Team == "Blue")
                    {
                        newLabel.ForeColor = Color.Blue;
                    }
                    else
                    {
                        newLabel.ForeColor = Color.Red;
                    }
                }
                else if (u is Wizard_Unit)
                {
                    Wizard_Unit wU = (Wizard_Unit)u;
                    newLabel.Width     = 25;
                    newLabel.Height    = 25;
                    newLabel.Location  = new Point(wU.Xpos * 20, wU.Ypos * 15);
                    newLabel.Text      = wU.Symbol;
                    newLabel.ForeColor = Color.Purple;
                }

                groupBox.Controls.Add(newLabel);
            }



            foreach (Building bd in buildings)
            {
                Button newLabel = new Button();
                newLabel.Width    = 30;
                newLabel.Height   = 30;
                newLabel.Location = new Point(bd.xPosition * 20, bd.yPosition * 15);
                newLabel.Text     = bd.symbol;
                if (bd.team >= 3)
                {
                    newLabel.ForeColor = Color.Blue;
                }
                else
                {
                    newLabel.ForeColor = Color.Red;
                }

                groupBox.Controls.Add(newLabel);
            }

            //test = groupBox.Controls.Count;
        }
Exemple #3
0
        public void SpawnUnitAtFactory()
        {
            //for(int i = 0; i < 20; i++)
            //{
            //    Melee_Unit m = new Melee_Unit(r.Next(0, 20), r.Next(0, 20) + 5, 200, 1, 20, 1, "{:}", "Red");
            //    units.Add(m);
            //}

            //for (int i = 0; i < 20; i++)
            //{
            //    Ranged_Unit rU = new Ranged_Unit(r.Next(0, 20), r.Next(0, 20) + 5, 100, 1, 20, 5, "[!]", "Blue");
            //    units.Add(rU);
            //}


            //Spawns Wizards
            Wizard_Unit wU = new Wizard_Unit(r.Next(0, xMapSize), r.Next(0, yMapSize), 150, 1, 30, 1, "(<|>)", "Wizard");

            units.Add(wU);


            foreach (Building bd in buildings)
            {
                if (bd is FactoryBuilding)
                {
                    if (bd.symbol == "F" && bd.team < 3)
                    {
                        Ranged_Unit rU = new Ranged_Unit(bd.xPosition, bd.yPosition + 5, 100, 1, 20, 5, "[!]", "Red");
                        //rU.Xpos = bd.xPosition;
                        //rU.Ypos = bd.yPosition + 5;
                        //rU.Symbol = "[!]";
                        //rU.Health = 100;
                        //rU.Attack = 20;
                        //rU.AttackRange = 5;
                        //rU.IsAttacking = false;
                        //rU.IsDead = false;
                        //rU.Team = "Red";

                        units.Add(rU);

                        Melee_Unit mU = new Melee_Unit(bd.xPosition, bd.yPosition + 5, 200, 1, 20, 1, "{:}", "Red");
                        //mU.Xpos = bd.xPosition;
                        //mU.Ypos = bd.xPosition + 5;
                        //mU.Symbol = "{:}";
                        //mU.Health = 200;
                        //mU.Attack = 20;
                        //mU.AttackRange = 1;
                        //mU.IsAttacking = false;
                        //mU.IsDead = false;
                        //mU.Team = "Red";

                        units.Add(mU);
                    }
                    else if (bd.symbol == "F" && bd.team >= 7)
                    {
                        Ranged_Unit rU = new Ranged_Unit(bd.xPosition, bd.yPosition + 5, 100, 1, 20, 5, "[!]", "Blue");
                        //rU.Xpos = bd.xPosition;
                        //rU.Ypos = bd.yPosition + 5;
                        //rU.Symbol = "[!]";
                        //rU.Health = 100;
                        //rU.Team = "Blue";

                        units.Add(rU);

                        Melee_Unit mU = new Melee_Unit(bd.xPosition, bd.yPosition + 5, 200, 1, 20, 1, "{:}", "Blue");
                        //mU.Xpos = bd.xPosition;
                        //mU.Ypos = bd.xPosition + 5;
                        //mU.Symbol = "{:}";
                        //mU.Health = 200;
                        //mU.Team = "Blue";

                        units.Add(mU);
                    }
                }
            }
        }
Exemple #4
0
        public void UpdateMovement()
        {
            for (int i = 0; i < map.Units.Count; i++)
            {
                if (map.Units[i] is Melee_Unit)
                {
                    Melee_Unit mu = (Melee_Unit)map.Units[i];
                    if (mu.Health <= mu.MaxHealth * 0.25) // Running Away
                    {
                        mu.Move(r.Next(0, 4));
                    }
                    else
                    {
                        (Unit closest, int distanceTo) = mu.ClosestUnit(map.Units);

                        //Check In Range
                        if (distanceTo <= mu.AttackRange)
                        {
                            mu.IsAttacking = true;
                            mu.Combat(closest);
                        }
                        else //Move Towards
                        {
                            if (closest is Melee_Unit)
                            {
                                Melee_Unit closestMu = (Melee_Unit)closest;
                                if (mu.Xpos > closestMu.Xpos) //North
                                {
                                    mu.Move(0);
                                }
                                else if (mu.Xpos < closestMu.Xpos) //South
                                {
                                    mu.Move(2);
                                }
                                else if (mu.Ypos > closestMu.Ypos) //West
                                {
                                    mu.Move(3);
                                }
                                else if (mu.Ypos < closestMu.Ypos) //East
                                {
                                    mu.Move(1);
                                }
                            }
                            else if (closest is Ranged_Unit)
                            {
                                Ranged_Unit closestRu = (Ranged_Unit)closest;
                                if (mu.Xpos > closestRu.Xpos) //North
                                {
                                    mu.Move(0);
                                }
                                else if (mu.Xpos < closestRu.Xpos) //South
                                {
                                    mu.Move(2);
                                }
                                else if (mu.Ypos > closestRu.Ypos) //West
                                {
                                    mu.Move(3);
                                }
                                else if (mu.Ypos < closestRu.Ypos) //East
                                {
                                    mu.Move(1);
                                }
                            }
                        }
                    }
                }
                else if (map.Units[i] is Ranged_Unit)
                {
                    Ranged_Unit ru = (Ranged_Unit)map.Units[i];
                    if (ru.Health <= ru.MaxHealth * 0.25) // Running Away is commented out to make for a more interesting battle - and some insta-deaths
                    {
                        ru.Move(r.Next(0, 4));
                    }
                    else
                    {
                        (Unit closest, int distanceTo) = ru.ClosestUnit(map.Units);

                        //Check In Range
                        if (distanceTo <= ru.AttackRange)
                        {
                            ru.IsAttacking = true;
                            ru.Combat(closest);
                        }
                        else //Move Towards
                        {
                            if (closest is Melee_Unit)
                            {
                                Melee_Unit closestMu = (Melee_Unit)closest;
                                if (ru.Xpos > closestMu.Xpos) //North
                                {
                                    ru.Move(0);
                                }
                                else if (ru.Xpos < closestMu.Xpos) //South
                                {
                                    ru.Move(2);
                                }
                                else if (ru.Ypos > closestMu.Ypos) //West
                                {
                                    ru.Move(3);
                                }
                                else if (ru.Ypos < closestMu.Ypos) //East
                                {
                                    ru.Move(1);
                                }
                            }
                            else if (closest is Ranged_Unit)
                            {
                                Ranged_Unit closestRu = (Ranged_Unit)closest;
                                if (ru.Xpos > closestRu.Xpos) //North
                                {
                                    ru.Move(0);
                                }
                                else if (ru.Xpos < closestRu.Xpos) //South
                                {
                                    ru.Move(2);
                                }
                                else if (ru.Ypos > closestRu.Ypos) //West
                                {
                                    ru.Move(3);
                                }
                                else if (ru.Ypos < closestRu.Ypos) //East
                                {
                                    ru.Move(1);
                                }
                            }
                        }
                    }
                }
            }

            map.DisplayUnits(grpMap);
            //form.DisplayUnits();
        }