Ejemplo n.º 1
0
        public Building BuildingPosition() //Method to check the positions of the buildings
        {
            int      Xdis = 0, Ydis = 0;
            double   Distance = 1000;
            double   temp     = 1000;
            Building Target   = null;

            foreach (Building b in buildings)
            {
                if (b is FactoryBuilding)
                {
                    FactoryBuilding Fb = (FactoryBuilding)b;

                    if (FactionType != b.faction)
                    {
                        Xdis = Math.Abs(PosX - Fb.PosX) * (PosX - Fb.PosX);
                        Ydis = Math.Abs(PosY - Fb.PosY) * (PosY - Fb.PosY);

                        Distance = Math.Round(Math.Sqrt(Xdis + Ydis), 0);
                    }
                }
                else
                {
                    ResourceBuilding Rb = (ResourceBuilding)b;
                    if (FactionType != b.faction)
                    {
                        Xdis = Math.Abs(PosX - Rb.PosX) * (PosX - Rb.PosX);
                        Ydis = Math.Abs(PosY - Rb.PosY) * (PosY - Rb.PosY);

                        Distance = Math.Round(Math.Sqrt(Xdis + Ydis), 0);
                    }
                }

                if (Distance < temp)
                {
                    temp   = Distance;
                    Target = b;
                }
            }
            return(Target);
        }
Ejemplo n.º 2
0
        public void PlaceButtons() // Method to fill the Map with buttons to create the battlefield
        {
            GbBoxMap.Controls.Clear();

            Size btnSize = new Size(30, 30);

            for (int i = 0; i < mapWidth; i++)
            {
                for (int j = 0; j < mapHeight; j++)
                {
                    Button btn = new Button();

                    btn.Size     = btnSize;
                    btn.Location = new Point(i * 30, j * 30);

                    //buttons[i, j] = btn;
                    if (m.map[i, j] == "R")
                    {
                        btn.Text   = "->";
                        btn.Name   = m.uniMap[i, j].ToString();
                        btn.Click += MyButtonCLick;

                        btn.BackColor = m.uniMap[i, j].factionType == Faction.Hero ? Color.Chartreuse : Color.Crimson; // the color for the ranged and melee units
                    }
                    else if (m.map[i, j] == "M")
                    {
                        btn.Text   = "#";
                        btn.Name   = m.uniMap[i, j].ToString();
                        btn.Click += MyButtonCLick;

                        btn.BackColor = m.uniMap[i, j].factionType == Faction.Hero ? Color.Chartreuse : Color.Crimson; // the color for the ranged and melee units
                    }
                    else if (m.map[i, j] == "W")
                    {
                        btn.Text   = "≈";
                        btn.Name   = m.uniMap[i, j].ToString();
                        btn.Click += MyButtonCLick;

                        btn.BackColor = Color.BlueViolet;
                    }
                    else if (m.map[i, j] == "FB")
                    {
                        FactoryBuilding FB = (FactoryBuilding)m.buildingMap[i, j];
                        btn.Text      = FB.Symbol;
                        btn.BackColor = FB.Faction == Faction.Hero ? Color.Chartreuse : Color.Crimson;

                        btn.Name   = m.buildingMap[i, j].ToString();
                        btn.Click += MyButtonCLick;
                    }
                    else if (m.map[i, j] == "RB")
                    {
                        ResourceBuilding RB = (ResourceBuilding)m.buildingMap[i, j];
                        btn.Text      = RB.Symbol;
                        btn.BackColor = RB.Faction == Faction.Hero ? Color.Chartreuse : Color.Crimson;

                        btn.Name   = m.buildingMap[i, j].ToString();
                        btn.Click += MyButtonCLick;
                    }

                    buttons[i, j] = btn;
                }
            }

            for (int i = 0; i < mapWidth; i++)
            {
                for (int j = 0; j < mapHeight; j++)
                {
                    GbBoxMap.Controls.Add(buttons[i, j]);
                }
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
0
        public override void Move(int type) // all the move functions for the units once they have spawned and the the Buildings themselves
        {
            if (Health > MaxHealth * 0.25)
            {
                if (type == 0)
                {
                    if (ClosestUnit is MelleUnit)
                    {
                        MelleUnit closestUnitM = (MelleUnit)ClosestUnit;

                        if (closestUnitM.posX > posX && posX < 20)
                        {
                            posX++;
                        }
                        else if (closestUnitM.posX < posX && posX > 0)
                        {
                            posX--;
                        }

                        if (closestUnitM.posY > posY && posY < 20)
                        {
                            PosY++;
                        }
                        else if (closestUnitM.posY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                    else if (ClosestUnit is RangedUnit)
                    {
                        RangedUnit closestUnitR = (RangedUnit)ClosestUnit;

                        if (closestUnitR.PosX > posX && PosX < 20)
                        {
                            posX++;
                        }
                        else if (closestUnitR.PosX < posX && posX > 0)
                        {
                            posX--;
                        }

                        if (closestUnitR.PosY > posY && PosY < 20)
                        {
                            posY++;
                        }
                        else if (closestUnitR.PosY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                    else if (ClosestUnit is WizardUnit) // showing the new wizard who he can attack and when he can attack them
                    {
                        WizardUnit closestUnitW = (WizardUnit)ClosestUnit;

                        if (closestUnitW.PosX > posX && PosX < 20)
                        {
                            posX++;
                        }
                        else if (closestUnitW.PosX < posX && posX > 0)
                        {
                            posX--;
                        }

                        if (closestUnitW.PosY > posY && PosY < 20)
                        {
                            posY++;
                        }
                        else if (closestUnitW.PosY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                }
                else
                {
                    if (ClosestBuilding is FactoryBuilding)
                    {
                        FactoryBuilding closestBuildingFB = (FactoryBuilding)ClosestBuilding;

                        if (closestBuildingFB.PosX > posX && PosX < 20)
                        {
                            posX++;
                        }
                        else if (closestBuildingFB.PosX < posX && posX > 0)
                        {
                            posX--;
                        }

                        if (closestBuildingFB.PosY > posY && PosY < 20)
                        {
                            posY++;
                        }
                        else if (closestBuildingFB.PosY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                    else if (ClosestBuilding is ResourceBuilding)
                    {
                        ResourceBuilding closestBuildingRB = (ResourceBuilding)ClosestBuilding;

                        if (closestBuildingRB.PosX > posX && PosX < 19)
                        {
                            posX++;
                        }
                        else if (closestBuildingRB.PosX < posX && posX > 0)
                        {
                            posX--;
                        }

                        if (closestBuildingRB.PosY > posY && PosY < 19)
                        {
                            posY++;
                        }
                        else if (closestBuildingRB.PosY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                }
            }
            else
            {
                int direction = r.Next(0, 4);

                if (direction == 0 && PosX < 19)
                {
                    posX++;
                }
                else if (direction == 1 && posX > 0)
                {
                    posX--;
                }
                else if (direction == 2 && posY > 19)
                {
                    posY++;
                }
                else if (direction == 3 && posY > 0)
                {
                    posY--;
                }
            }
        }
Ejemplo n.º 5
0
        public override void AttRange(List <Units> uni, List <Building> builds) // checking the range of the building and the units they spawn
        {
            units     = uni;
            buildings = builds;

            ClosestUnit     = Position();
            ClosestBuilding = BuildingPosition();

            int enemyType;

            int xDis = 0, yDis = 0;

            int uDistance = 10000, bDistance = 10000;
            int distance;

            if (ClosestUnit is MelleUnit)
            {
                MelleUnit M = (MelleUnit)ClosestUnit;
                xDis = Math.Abs((PosX - M.PosX) * (PosX - M.PosX));
                yDis = Math.Abs((PosY - M.PosY) * (PosY - M.PosY));

                uDistance = (int)Math.Round(Math.Sqrt(xDis + yDis), 0);
            }
            else if (ClosestUnit is RangedUnit)
            {
                RangedUnit R = (RangedUnit)ClosestUnit;
                xDis = Math.Abs((PosX - R.PosX) * (PosX - R.PosX));
                yDis = Math.Abs((PosY - R.PosY) * (PosY - R.PosY));

                uDistance = (int)Math.Round(Math.Sqrt(xDis + yDis), 0);
            }

            if (ClosestBuilding is FactoryBuilding)
            {
                FactoryBuilding FB = (FactoryBuilding)ClosestBuilding;
                xDis = Math.Abs((PosX - FB.PosX) * (PosX - FB.PosX));
                yDis = Math.Abs((PosY - FB.PosY) * (PosY - FB.PosY));

                bDistance = (int)Math.Round(Math.Sqrt(xDis + yDis), 0);
            }
            else if (ClosestBuilding is ResourceBuilding)
            {
                ResourceBuilding RB = (ResourceBuilding)ClosestBuilding;
                xDis = Math.Abs((PosX - RB.PosX) * (PosX - RB.PosX));
                yDis = Math.Abs((PosY - RB.PosY) * (PosY - RB.PosY));

                bDistance = (int)Math.Round(Math.Sqrt(xDis + yDis), 0);
            }

            if (units[0] != null)
            {
                if (uDistance < bDistance)
                {
                    distance  = uDistance;
                    enemyType = 0;
                }
                else
                {
                    distance  = bDistance;
                    enemyType = 1;
                }
            }
            else
            {
                distance  = bDistance;
                enemyType = 1;
            }

            //Checks to see if they are below 25% health so they move rather than attacking
            if (Health > MaxHealth * 0.25)
            {
                if (distance <= atkRange)
                {
                    isAtk = true;
                    Combat(enemyType);
                }
                else
                {
                    isAtk = false;
                    Move(enemyType);
                }
            }
            else
            {
                Move(enemyType);
            }
        }
Ejemplo n.º 6
0
        public void GenerateBattleField()  // method to allow the random number of units, including the ranged and the melee units
        {
            for (int i = 0; i < BuildingNum; i++)
            {
                if (Rd.Next(0, 2) == 0)
                {
                    ResourceBuilding DiamondMine = new ResourceBuilding(0, 0, 100, Faction.Hero, "◘", 10); //setting the symbol amd stats for the diamond mine
                    diamondMines.Add(DiamondMine);
                }
                else
                {
                    int    UnitNum = Rd.Next(0, 2);
                    string UnitName;
                    if (UnitNum == 0)
                    {
                        UnitName = "Melee";
                    }
                    else
                    {
                        UnitName = "Ranged";
                    }

                    FactoryBuilding barrack = new FactoryBuilding(0, 0, 100, Faction.Hero, "┬", Rd.Next(3, 10), UnitName);  //setting the symbol amd stats for the Barrack
                    barracks.Add(barrack);
                }
            }
            for (int i = 0; i < BuildingNum; i++)
            {
                if (Rd.Next(0, 2) == 0)
                {
                    ResourceBuilding DiamondMine = new ResourceBuilding(0, 0, 100, Faction.Villain, "◘", 10);  //setting the symbol amd stats for the diamond mine
                    diamondMines.Add(DiamondMine);
                }
                else
                {
                    int    UnitNum = Rd.Next(0, 2);
                    string UnitName;
                    if (UnitNum == 0)
                    {
                        UnitName = "Melee";
                    }
                    else
                    {
                        UnitName = "Ranged";
                    }

                    FactoryBuilding barrack = new FactoryBuilding(0, 0, 100, Faction.Villain, "┬", Rd.Next(3, 10), UnitName);  //setting the symbol amd stats for the factory building
                    barracks.Add(barrack);
                }
            }

            foreach (ResourceBuilding u in diamondMines) // populating and randomizing the spawn of the resource buildings
            {
                for (int i = 0; i < diamondMines.Count; i++)
                {
                    int xPos = Rd.Next(0, 20);
                    int yPos = Rd.Next(0, 20);

                    while (xPos == diamondMines[i].PosX && yPos == diamondMines[i].PosY && xPos == barracks[i].PosX && yPos == barracks[i].PosY)
                    {
                        xPos = Rd.Next(0, 20);
                        yPos = Rd.Next(0, 20);
                    }

                    u.PosX = xPos;
                    u.PosY = yPos;
                    buildingMap[u.PosX, u.PosX] = (Building)u;
                }
                buildings.Add(u);
            }

            foreach (FactoryBuilding u in barracks) // populating and randomizing the spawn of the barracks
            {
                for (int i = 0; i < barracks.Count; i++)
                {
                    int xPos = Rd.Next(0, 20);
                    int yPos = Rd.Next(0, 20);

                    while (xPos == barracks[i].PosX && yPos == barracks[i].PosY && xPos == diamondMines[i].PosX && yPos == diamondMines[i].PosY)
                    {
                        xPos = Rd.Next(0, 20);
                        yPos = Rd.Next(0, 20);
                    }

                    u.PosX = xPos;
                    u.PosY = yPos;
                    buildingMap[u.PosY, u.PosX] = (Building)u;
                }
                buildings.Add(u);

                u.SpawnPointY = u.PosY;
                if (u.PosX < 19)
                {
                    u.SpawnPointX = u.PosX + 1;
                }
                else
                {
                    u.SpawnPointX = u.PosX - 1;
                }
            }
            Populate();
            PlaceBuildings();
        }
Ejemplo n.º 7
0
        public void GenerateBattleField()  // method to allow the random number of units, including the ranged and the melee units
        {
            for (int i = 0; i < BuildingNum; i++)
            {
                int    UnitNum = Rd.Next(0, 2);
                string UnitName;
                if (UnitNum == 0)
                {
                    UnitName = "Melee";
                }
                else
                {
                    UnitName = "Ranged";
                }

                ResourceBuilding DiamondMine = new ResourceBuilding(0, 0, 100, Faction.Hero, "◘", 10); // setting the values and symbols for the diamond mines
                diamondMines.Add(DiamondMine);

                FactoryBuilding barrack = new FactoryBuilding(0, 0, 100, Faction.Hero, "┬", Rd.Next(3, 10), UnitName); // setting the values and symbols for the barracks
                barracks.Add(barrack);
            }

            for (int i = 0; i < BuildingNum; i++)
            {
                int    UnitNum = Rd.Next(0, 2);
                string UnitName;
                if (UnitNum == 0)
                {
                    UnitName = "Melee";
                }
                else
                {
                    UnitName = "Ranged";
                }

                ResourceBuilding DiamondMine = new ResourceBuilding(0, 0, 100, Faction.Villain, "◘", 10);
                diamondMines.Add(DiamondMine);

                FactoryBuilding barrack =
                    new FactoryBuilding(0, 0, 100, Faction.Villain, "┬", Rd.Next(3, 10), UnitName);
                barracks.Add(barrack);
            }

            for (int i = 0; i < BuildingNum; i++)
            {
                WizardUnit wizard = new WizardUnit("Wizard", 0, 0, 15, 1, 3, 1, Faction.Neutral, "≈", false); //setting values for the new wizard unit
                wizardUnits.Add(wizard);
            }

            foreach (ResourceBuilding u in diamondMines)
            {
                for (int i = 0; i < diamondMines.Count; i++)
                {
                    int xPos = Rd.Next(0, mapHeight);
                    int yPos = Rd.Next(0, mapWidth);

                    while (xPos == diamondMines[i].PosX && yPos == diamondMines[i].PosY && xPos == barracks[i].PosX && yPos == barracks[i].PosY)
                    {
                        xPos = Rd.Next(0, mapHeight);
                        yPos = Rd.Next(0, mapWidth);
                    }

                    u.PosX = xPos;
                    u.PosY = yPos;
                    buildingMap[u.PosX, u.PosX] = (Building)u;
                }
                buildings.Add(u);
            }

            foreach (FactoryBuilding u in barracks)
            {
                for (int i = 0; i < barracks.Count; i++)
                {
                    int xPos = Rd.Next(0, mapHeight);
                    int yPos = Rd.Next(0, mapWidth);

                    while (xPos == barracks[i].PosX && yPos == barracks[i].PosY && xPos == diamondMines[i].PosX && yPos == diamondMines[i].PosY)
                    {
                        xPos = Rd.Next(0, mapHeight);
                        yPos = Rd.Next(0, mapWidth);
                    }

                    u.PosX = xPos;
                    u.PosY = yPos;
                    buildingMap[u.PosY, u.PosX] = (Building)u;
                }
                buildings.Add(u);

                u.SpawnPointY = u.PosY;
                if (u.PosX < 19)
                {
                    u.SpawnPointX = u.PosX + 1;
                }
                else
                {
                    u.SpawnPointX = u.PosX - 1;
                }
            }

            foreach (WizardUnit u in wizardUnits) // placing the wizard units randomly throughout the map
            {
                for (int i = 0; i < wizardUnits.Count; i++)
                {
                    int xPos = Rd.Next(0, mapHeight);
                    int yPos = Rd.Next(0, mapWidth);

                    while (xPos == diamondMines[i].PosX && yPos == diamondMines[i].PosY && xPos == barracks[i].PosX && yPos == barracks[i].PosY && xPos == wizardUnits[i].PosX && yPos == wizardUnits[i].PosY)
                    {
                        xPos = Rd.Next(0, mapHeight);
                        yPos = Rd.Next(0, mapWidth);
                    }

                    u.PosX = xPos;
                    u.PosY = yPos;
                    uniMap[u.PosX, u.PosX] = (Units)u;
                }
                units.Add(u);
            }

            Populate();
            PlaceBuildings();
        }