Ejemplo n.º 1
0
        // updates game information
        public void Update()
        {
            for (int i = 0; i < map.Units.Count; i++)
            {
                if (map.Units[i] is MeleeUnit)
                {
                    MeleeUnit mu = (MeleeUnit)map.Units[i];
                    if (mu.Health <= mu.MaxHealth * 0.25) // Running Away
                    {
                        mu.Move(r.Next(0, 4));
                    }
                    else
                    {
                        (Unit closest, int distanceTo)     = mu.Closest(map.Units);
                        (Building bclosest, int bdistance) = mu.Closest(map.Buildings);
                        //Check In Range
                        if (distanceTo <= mu.AttackRange)
                        {
                            mu.IsAttacking = true;
                            mu.Combat(closest);
                        }
                        else //Move Towards
                        {
                            if (closest is MeleeUnit)
                            {
                                MeleeUnit closestMu = (MeleeUnit)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 RangedUnit)
                            {
                                RangedUnit closestRu = (RangedUnit)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 RangedUnit)
                {
                    RangedUnit ru = (RangedUnit)map.Units[i];

                    (Unit closest, int distanceTo) = ru.Closest(map.Units);

                    //Check In Range
                    if (distanceTo <= ru.AttackRange)
                    {
                        ru.IsAttacking = true;
                        ru.Combat(closest);
                    }
                    else     //Move Towards
                    {
                        if (closest is MeleeUnit)
                        {
                            MeleeUnit closestMu = (MeleeUnit)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 RangedUnit)
                        {
                            RangedUnit closestRu = (RangedUnit)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);
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < map.Buildings.Count; i++)
            {
                Building bitch = map.Buildings[i];
                if (bitch is ResourceBuilding)
                {
                    ResourceBuilding bREE = (ResourceBuilding)bitch;

                    switch (bREE.Faction)
                    {
                    case 0:
                    {
                        FactionZeroR += bREE.MineResource();
                    }
                    break;

                    case 1:
                    {
                        FactionOneR += bREE.MineResource();
                    }
                    break;

                    default: break;
                    }
                }
                else if (bitch is FactoryBuilding)
                {
                    FactoryBuilding bFac = (FactoryBuilding)bitch;
                    int             a    = bFac.Faction;
                    switch (a)
                    {
                    case 0:
                    {
                        if (FactionZeroR >= 6)
                        {
                            map.Units.Add(bFac.UnitSpawn());
                        }
                    }
                    break;

                    case 1:
                    {
                        if (FactionOneR >= 6)
                        {
                            map.Units.Add(bFac.UnitSpawn());
                        }
                    }
                    break;

                    default: break;
                    }
                }
                else
                {
                    Console.WriteLine("NANI THE F**K YOU HERE FOR ");
                }
            }


            map.Display(grpMap);
            round++;
        }
Ejemplo n.º 2
0
        // displays units on map
        public void Display(GroupBox groupBox)
        {
            groupBox.Controls.Clear();
            foreach (Unit u in units)
            {
                Button b = new Button();

                if (u is WizardUnit)
                {
                    WizardUnit wu = (WizardUnit)u;
                    b.Size     = new Size(20, 20);
                    b.Location = new Point(wu.XPos * 20, wu.YPos * 20);
                    b.Text     = wu.Symbol;
                    if (wu.Faction == 3)
                    {
                        b.ForeColor = Color.Violet;
                    }
                }
                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;
                    }
                }
                else if (u is RangedUnit)
                {
                    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 b in building)
            {
                Button button = new Button();
                if (b is FactoryBuilding)
                {
                    FactoryBuilding bb = (FactoryBuilding)b;
                    button.Size     = new Size(20, 20);
                    button.Location = new Point(bb.XPos * 20, bb.YPos * 20);
                    button.Text     = bb.Symbol;
                    if (bb.Faction == 0)
                    {
                        button.ForeColor = Color.Red;
                    }
                    else
                    {
                        button.ForeColor = Color.Green;
                    }
                }
                else
                {
                    ResourceBuilding rb = (ResourceBuilding)b;
                    button.Size     = new Size(20, 20);
                    button.Location = new Point(rb.XPos * 20, rb.YPos * 20);
                    button.Text     = rb.Symbol;
                    if (rb.Faction == 0)
                    {
                        button.ForeColor = Color.Red;
                    }
                    else
                    {
                        button.ForeColor = Color.Green;
                    }
                }
                button.Click += Unit_Click;
                groupBox.Controls.Add(button);
            }
        }
Ejemplo n.º 3
0
        //Code given by Declan Porter
        public void DeclanFunctionalApproachToTheSaveFunction()
        {
            StreamWriter writer   = new StreamWriter("Local_Save.txt");
            string       Faction0 = "";
            string       Faction1 = "";

            writer.WriteLine("START OF SAVE");
            foreach (Unit u in map.Units)
            {
                if (u is MeleeUnit)
                {
                    MeleeUnit uu = (MeleeUnit)u;
                    if (uu.Faction == 0)
                    {
                        Faction0 += uu.ToString() + "\n";
                    }
                    else
                    {
                        Faction1 += uu.ToString() + "\n";
                    }
                }
                else if (u is RangedUnit)
                {
                    RangedUnit uu = (RangedUnit)u;
                    if (uu.Faction == 0)
                    {
                        Faction0 += uu.ToString() + "\n";
                    }
                    else
                    {
                        Faction1 += uu.ToString() + "\n";
                    }
                }
            }
            writer.WriteLine("UNITS -- FACTION 0");
            writer.WriteLine(Faction0);
            writer.WriteLine("UNITS -- FACTION 1");
            writer.WriteLine(Faction1);
            Faction0 = "";
            Faction1 = "";
            foreach (Building u in map.Buildings)
            {
                if (u is ResourceBuilding)
                {
                    ResourceBuilding uu = (ResourceBuilding)u;
                    if (uu.Faction == 0)
                    {
                        Faction0 += uu.ToString() + "\n";
                    }
                    else
                    {
                        Faction1 += uu.ToString() + "\n";
                    }
                }
                else if (u is FactoryBuilding)
                {
                    FactoryBuilding uu = (FactoryBuilding)u;
                    if (uu.Faction == 0)
                    {
                        Faction0 += uu.ToString() + "\n";
                    }
                    else
                    {
                        Faction1 += uu.ToString() + "\n";
                    }
                }
            }

            writer.WriteLine("BUILDINGS-- FACTION 0");
            writer.WriteLine(Faction0);
            writer.WriteLine("BUILDINGS-- FACTION 1");
            writer.WriteLine(Faction1);
            writer.WriteLine("END OF SAVE");
        }