Exemple #1
0
        public void UnitGeneration()
        {
            int randomXposition;
            int randomYposition;

            //generating melee units
            for (int i = 0; i < melee_unit_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);

                MeleeUnit M = new MeleeUnit(randomXposition, randomYposition, 50, 10, 1, 1, "o/*", false, "Warrior");
                meleeUnits.Add(M);
                units.Add(M);
            }
            //generating ranged units
            for (int i = 0; i < ranged_unit_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);
                RangedUnit R = new RangedUnit(randomXposition, randomYposition, 50, 10, 5, 1, "o|}", false, "Archer");
                rangedUnits.Add(R);
                units.Add(R);
            }

            foreach (Building b in buildings)
            {
                if (b is FactoryBuilding)
                {
                    FactoryBuilding f = (FactoryBuilding)b;
                    if (f.production_speed % gameengine.RoundsCompleted == 0)
                    {
                        units.Add(f.UnitSpawner());
                    }
                }
                if (b is ResourceBuilding)
                {
                    ResourceBuilding rs = (ResourceBuilding)b;
                    rs.ResourceGeneration();
                }
            }
        }
Exemple #2
0
        //Display
        public void Display(GroupBox place)
        {
            place.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.image;
                    if (mu.faction == 0)
                    {
                        b.ForeColor = Color.Red;
                    }
                    else
                    {
                        b.ForeColor = Color.Green;
                    }
                }
                else
                {
                    RangedUnit ru = (RangedUnit)u;
                    b.Size     = new Size(20, 20);
                    b.Location = new Point(ru.xpos * 20, ru.ypos * 20);
                    b.Text     = ru.image;
                    if (ru.faction == 0)
                    {
                        b.ForeColor = Color.Red;
                    }
                    else
                    {
                        b.ForeColor = Color.Green;
                    }
                }
                b.Click += InfoClick;
                place.Controls.Add(b);
            }

            //building Display
            {
                foreach (Buildings b in build)
                {
                    Button c = new Button();
                    if (b is ResourceBuilding)
                    {
                        ResourceBuilding Bu = (ResourceBuilding)b;
                        c.Size     = new Size(30, 30);
                        c.Location = new Point(Bu.xxpos * 20, Bu.yypos * 20);
                        c.Text     = Bu.iimage;
                        if (Bu.ffaction == 0)
                        {
                            c.ForeColor = Color.Red;
                        }
                        else
                        {
                            c.ForeColor = Color.Green;
                        }
                    }
                    else
                    {
                        FactoryBuilding Fu = (FactoryBuilding)b;
                        c.Size     = new Size(30, 30);
                        c.Location = new Point(Fu.xxpos * 20, Fu.yypos * 20);
                        c.Text     = Fu.iimage;
                        if (Fu.ffaction == 0)
                        {
                            c.ForeColor = Color.Red;
                        }
                        else
                        {
                            c.ForeColor = Color.Green;
                        }
                    }
                    c.Click += InfoClick;
                    place.Controls.Add(c);
                }
            }
        }
Exemple #3
0
        public void BuildingGeneration()
        {
            int randomXposition;
            int randomYposition;

            //generating team 1 resource buildings
            for (int i = 0; i < T1_resource_building_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);

                ResourceBuilding RB1 = new ResourceBuilding(randomXposition, randomYposition, 100, 1, "[*]", 1);
                resource_buildings.Add(RB1);
                T1_resource_buildings.Add(RB1);
                buildings.Add(RB1);
            }
            //gennerating team 2 resource buildings
            for (int i = 0; i < T2_resource_building_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);

                ResourceBuilding RB2 = new ResourceBuilding(randomXposition, randomYposition, 100, 2, "[+]", 1);
                resource_buildings.Add(RB2);
                T2_resource_buildings.Add(RB2);
                buildings.Add(RB2);
            }
            //generating team 3 resource buildings
            for (int i = 0; i < T2_resource_building_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);

                ResourceBuilding RB3 = new ResourceBuilding(randomXposition, randomYposition, 100, 3, "[+]", 1);
                resource_buildings.Add(RB3);
                T3_resource_buildings.Add(RB3);
                buildings.Add(RB3);
            }
            //generating team 1 factory buildings
            for (int i = 0; i < T1_factory_building_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);

                FactoryBuilding FB = new FactoryBuilding(randomXposition, randomYposition, 100, 1, "[+]", 3);
                factory_buildings.Add(FB);
                buildings.Add(FB);
            }
            //generating team 2 factory buldngs
            for (int i = 0; i < T2_factory_building_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);

                FactoryBuilding FB = new FactoryBuilding(randomXposition, randomYposition, 100, 2, "[+]", 3);
                factory_buildings.Add(FB);
                buildings.Add(FB);
            }
            //generating team 3 factory buldngs
            for (int i = 0; i < T3_factory_building_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);

                FactoryBuilding FB = new FactoryBuilding(randomXposition, randomYposition, 100, 3, "[+]", 5);
                factory_buildings.Add(FB);
                buildings.Add(FB);
            }
        }
Exemple #4
0
        //gameLogic
        public void GameLogic()
        {
            for (int i = 0; i < m.Build.Count; i++)
            {
                if (m.Build[i] is FactoryBuilding)
                {
                    FactoryBuilding bu = (FactoryBuilding)m.Build[i];
                    (Unit type, int prodspeed) = bu.Spawn();
                    PrdSp = prodspeed;
                    if (prodspeed == countertick3)
                    {
                        m.Units.Add(type);
                    }
                }
                if (m.Build[i] is ResourceBuilding)
                {
                    ResourceBuilding bu = (ResourceBuilding)m.Build[i];
                    bu.ResourcesGenerated();
                }
            }
            //every x rounds
            if (PrdSp == countertick3)
            {
                countertick3 = 0;
            }
            countertick3++;

            for (int i = 0; i < m.Units.Count; i++)
            {
                //checking if unit is melee
                if (m.Units[i] is MeleeUnit)
                {
                    MeleeUnit mu = (MeleeUnit)m.Units[i];
                    (Unit closest, int distance) = mu.ClosestUnit(m.Units);
                    //checking health

                    //setting speed local value
                    speed1 = mu.speed;


                    if (mu.health <= mu.maxHealth * 0.25 && mu.speed == countertick1)
                    {
                        mu.Move(r.Next(0, 4));
                    }
                    else
                    {
                        //Check in range
                        if (mu.IsInRange(closest) == true)
                        {
                            mu.isAttacking = true;
                            mu.Combat(closest);
                        }
                        //moving in direction
                        else
                        {
                            if (closest is MeleeUnit && mu.speed == countertick1)
                            {
                                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 && mu.speed == countertick1)
                            {
                                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);
                                }
                            }
                        }
                    }
                }

                // checking if unit is rangedunit
                else if (m.Units[i] is RangedUnit)
                {
                    RangedUnit Ru = (RangedUnit)m.Units[i];
                    (Unit closest, int distance) = Ru.ClosestUnit(m.Units);
                    //checking health

                    //setting speed local value
                    speed2 = Ru.speed;

                    if (Ru.health <= Ru.maxHealth * 0.25 && Ru.speed == countertick2)
                    {
                        Ru.Move(r.Next(0, 4));
                    }
                    else
                    {
                        //Check in range
                        if (Ru.IsInRange(closest) == true)
                        {
                            Ru.isAttacking = true;
                            Ru.Combat(closest);
                        }
                        //moving in direction
                        else
                        {
                            if (closest is MeleeUnit && Ru.speed == countertick2)
                            {
                                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 && Ru.speed == countertick2)
                            {
                                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);
                                }
                            }
                        }
                    }
                }
            }
            if (speed1 == countertick1)
            {
                countertick1 = 0;
            }
            if (speed2 == countertick2)
            {
                countertick2 = 0;
            }
            m.Display(maap);
            round++;
            countertick1++;
            countertick2++;
        }
Exemple #5
0
        public void BuildingGeneration()
        {
            int randomXposition;
            int randomYposition;

            //generating team 1 resource buildings
            for (int i = 0; i < T1_resource_building_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);

                ResourceBuilding RB = new ResourceBuilding(randomXposition, randomYposition, 100, 1, "[*]");
                resource_buildings.Add(RB);
                buildings.Add(RB);
            }
            //gennerating team 2 resource buildings
            for (int i = 0; i < T2_resource_building_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);

                ResourceBuilding RB = new ResourceBuilding(randomXposition, randomYposition, 100, 2, "[+]");
                resource_buildings.Add(RB);
                buildings.Add(RB);
            }
            //generating team 1 factory buildings
            for (int i = 0; i < T1_factory_building_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);

                FactoryBuilding FB = new FactoryBuilding(randomXposition, randomYposition, 100, 1, "[+]");
                factory_buildings.Add(FB);
                buildings.Add(FB);
            }
            //generating team 2 factory buldngs
            for (int i = 0; i < T2_factory_building_amount; i++)
            {
                randomXposition = r.Next(1, 19);
                randomYposition = r.Next(1, 19);
                //bool positionfound = false;
                //while (positionfound == false)
                //{
                //    foreach (FactoryBuilding fb in factory_buildings)
                //    {
                //        if (randomXposition == fb.XPos && randomYposition == fb.YPos)
                //        {
                //            randomXposition = r.Next(1, 19);
                //            randomYposition = r.Next(1, 19);
                //            positionfound = false;
                //        }
                //        else if (positionfound != false)
                //        {
                //            positionfound = true;
                //        }
                //    }
                //}
                FactoryBuilding FB = new FactoryBuilding(randomXposition, randomYposition, 100, 2, "[+]");
                factory_buildings.Add(FB);
                buildings.Add(FB);
            }
        }