Example #1
0
        //gameLogic
        public void GameLogic()
        {
            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];

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

                    (Unit closest, int distance) = mu.ClosestUnit(m.Units);
                    //checking health
                    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;
                                //checking if unit is dead

                                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;
                                //checking if unit is dead

                                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];

                    speed2 = Ru.speed;

                    (Unit closest, int distance) = Ru.ClosestUnit(m.Units);
                    //checking health
                    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);
                                }
                            }
                        }
                    }
                }
            }
            //checking speeds
            if (speed1 == countertick1)
            {
                countertick1 = 0;
            }
            if (speed2 == countertick2)
            {
                countertick2 = 0;
            }

            m.Display(maap);
            round++;
            countertick1++;
            countertick2++;
        }
Example #2
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++;
        }