Exemplo n.º 1
0
        public void GameEngine() //game engine method instead of a separate class
        {
            int hero    = 0;
            int villian = 0;

            foreach (ResourceBuilding u in m.diamondMines) // incrementing the hero or villian based on which faction type they belong to
            {
                if (u.Faction == Faction.Hero)
                {
                    hero++;
                }
                else
                {
                    villian++;
                }
            }

            foreach (FactoryBuilding u in m.barracks) // incrementing the hero or villian based on which faction type they belong to
            {
                if (u.Faction == Faction.Hero)
                {
                    hero++;
                }
                else
                {
                    villian++;
                }
            }

            foreach (Units u in m.units) // incrementing the hero or villian based on which faction type they belong to
            {
                if (u.factionType == Faction.Hero)
                {
                    hero++;
                }
                else
                {
                    villian++;
                }
            }


            if (hero > 0 && villian > 0) // telling the game when there is only 1 type of unit left then that team is the victor
            {
                foreach (ResourceBuilding Rb in m.diamondMines)
                {
                    Rb.GenerateResources();
                }

                foreach (FactoryBuilding Fb in m.barracks)
                {
                    if (Round % Fb.ProductionSPeed == 0)
                    {
                        m.SpawnUnits(Fb.SpawnPointX, Fb.SpawnPointY, Fb.Faction, Fb.UnitType);
                    }
                }

                foreach (Units u in m.units)
                {
                    u.AttRange(m.units, m.buildings);
                }

                m.Populate();
                m.PlaceBuildings();
                Round++;
                PlaceButtons();
            }
            else
            {
                m.Populate();
                m.PlaceBuildings();
                PlaceButtons();
                Ticker.Enabled = false;

                if (hero > villian)
                {
                    MessageBox.Show("Hero Wins on Round: " + Round);
                }
                else
                {
                    MessageBox.Show("Villain Wins on Round: " + Round);
                }
            }

            for (int i = 0; i < m.rangedUnit.Count; i++) // for loop to remove Ranged units once health has reached 0
            {
                if (m.rangedUnit[i].Death())
                {
                    m.map[m.rangedUnit[i].posX, m.rangedUnit[i].posX] = "";
                    m.rangedUnit.RemoveAt(i);
                }
            }

            for (int i = 0; i < m.melleUnit.Count; i++) // for loop to remove Melee units once health has reached 0
            {
                if (m.melleUnit[i].Death())
                {
                    m.map[m.melleUnit[i].posX, m.melleUnit[i].posX] = "";
                    m.melleUnit.RemoveAt(i);
                }
            }

            for (int i = 0; i < m.units.Count; i++) // for loop to remove units once health has reached 0
            {
                if (m.units[i].Death())
                {
                    m.map[m.units[i].posX, m.units[i].posX] = "";
                    m.units.RemoveAt(i);
                }
            }

            for (int i = 0; i < m.diamondMines.Count; i++) // for loop to remove The diamond mine buildings once health has reached 0
            {
                if (m.diamondMines[i].Destruction())
                {
                    m.map[m.diamondMines[i].PosX, m.diamondMines[i].PosX] = "";
                    m.diamondMines.RemoveAt(i);
                }
            }

            for (int i = 0; i < m.barracks.Count; i++) // for loop to remove The Barrack buildings once health has reached 0
            {
                if (m.barracks[i].Destruction())
                {
                    m.map[m.barracks[i].PosX, m.barracks[i].PosX] = "";
                    m.barracks.RemoveAt(i);
                }
            }

            for (int i = 0; i < m.buildings.Count; i++) // for loop to remove The buildings once health has reached 0
            {
                if (m.buildings[i].Destruction())
                {
                    if (m.buildings[i] is FactoryBuilding)
                    {
                        FactoryBuilding FB = (FactoryBuilding)m.buildings[i];
                        m.map[FB.PosX, FB.PosY] = "";
                    }
                    else if (m.buildings[i] is ResourceBuilding)
                    {
                        ResourceBuilding RB = (ResourceBuilding)m.buildings[i];
                        m.map[RB.PosX, RB.PosY] = "";
                    }

                    m.buildings.RemoveAt(i);
                }
            }
        }
Exemplo n.º 2
0
    //overwatch Texts
    //public Text txtOverwatchResourcesLeft;
    //public Text txtOvertwatchResourcesGathered;
    //public Text txtOverwatchUnitsLeft;
    //Talon texts
    //public Text txtTalonResourcesLeft;
    //public Text txtTalonResourcesGathered;
    // public Text txtTalonUnitsLeft;



    public void GameEng()
    {
        txtRound.text = "Round: " + Round;
        int hero    = 0;
        int villian = 0;

        foreach (ResourceBuildings u in m.BitCoinMine)
        {
            if (u.Faction == Faction.Overwatch)
            {
                hero++;
            }
            else
            {
                villian++;
            }
        }

        foreach (FactoryBuildings u in m.Barracks)
        {
            if (u.Faction == Faction.Overwatch)
            {
                hero++;
            }
            else
            {
                villian++;
            }
        }

        foreach (Unit u in m.units)
        {
            if (u.factionType == Faction.Overwatch)
            {
                villian++;
            }
            else
            {
                villian++;
            }
        }


        if (hero > 0 && villian > 0)
        {
            foreach (ResourceBuildings Rb in m.BitCoinMine)
            {
                Rb.GenerateResources();
            }

            foreach (FactoryBuildings Fb in m.Barracks)
            {
                if (Round % Fb.ProductionSpeed == 0)
                {
                    m.SpawnUnits(Fb.SpawnPointX, Fb.SpawnPointY, Fb.Faction, Fb.SpawnUnits());
                }
            }

            foreach (Unit u in m.units)
            {
                u.CheckAttackRange(m.units, m.buildings);
            }

            m.Populate();
            m.PlaceBuildings();
            Round++;
            // Placebuttons();
        }
        else
        {
            m.Populate();
            m.PlaceBuildings();
            //Placebuttons();


            if (hero > villian)
            {
                // MessageBox.Show("Hero Wins on Round: " + Round);
            }
            else
            {
                //MessageBox.Show("Villian Wins on Round: " + Round);
            }
        }

        for (int i = 0; i < m.rangedUnits.Count; i++)
        {
            if (m.rangedUnits[i].Death())
            {
                m.map[m.rangedUnits[i].posX, m.rangedUnits[i].posX] = "";
                m.rangedUnits.RemoveAt(i);
            }
        }

        for (int i = 0; i < m.meleeUnits.Count; i++)
        {
            if (m.meleeUnits[i].Death())
            {
                m.map[m.meleeUnits[i].posX, m.meleeUnits[i].posX] = "";
                m.meleeUnits.RemoveAt(i);
            }
        }

        for (int i = 0; i < m.units.Count; i++)
        {
            if (m.units[i].Death())
            {
                m.map[m.units[i].posX, m.units[i].posX] = "";
                m.units.RemoveAt(i);
            }
        }
        for (int i = 0; i < m.Barracks.Count; ++i)
        {
            if (m.Barracks[i].Destruction())
            {
                m.map[m.Barracks[i].PosX, m.Barracks[i].PosY] = "";
                m.Barracks.RemoveAt(i);
            }
        }

        for (int i = 0; i < m.BitCoinMine.Count; ++i)
        {
            if (m.BitCoinMine[i].Destruction())
            {
                m.map[m.BitCoinMine[i].PosX, m.BitCoinMine[i].PosY] = "";
                m.BitCoinMine.RemoveAt(i);
            }
        }



        for (int i = 0; i < m.buildings.Count; ++i)
        {
            if (m.buildings[i].Destruction())
            {
                if (m.buildings[i] is FactoryBuildings)
                {
                    FactoryBuildings FB = (FactoryBuildings)m.buildings[i];
                    m.map[FB.PosX, FB.PosY] = "";
                }
                else if (m.buildings[i] is ResourceBuildings)
                {
                    ResourceBuildings RB = (ResourceBuildings)m.buildings[i];
                    m.map[RB.PosX, RB.PosY] = "";
                }
                m.buildings.RemoveAt(i);
            }
        }
    }