Esempio n. 1
0
        //Tests if closest enemy unit is within 1 blocks of the current unit
        public override bool IsInRange(Unit unitInRange)
        {
            bool   inRange   = false;;
            string typeCheck = unitInRange.GetType().ToString();

            string[] splitArray = typeCheck.Split('.');
            typeCheck = splitArray[splitArray.Length - 1];

            if (typeCheck == "MeleeUnit")
            {
                MeleeUnit mu = (MeleeUnit)unitInRange;
                if ((mu.YPos == this.YPos && Math.Abs(mu.XPos - this.XPos) == 1) || (mu.XPos == this.XPos && Math.Abs(mu.YPos - this.YPos) == 1))
                {
                    inRange = true;
                }
                else
                {
                    inRange = false;
                }
            }
            else
            {
                RangedUnit ru = (RangedUnit)unitInRange;
                if ((ru.YPos == this.YPos && Math.Abs(ru.XPos - this.XPos) == 1) || (ru.XPos == this.XPos && Math.Abs(ru.YPos - this.YPos) == 1))
                {
                    inRange = true;
                }
                else
                {
                    inRange = false;
                }
            }

            return(inRange);
        }
Esempio n. 2
0
        protected override bool IsInRange(Unit unitInRange)
        {
            bool   inRange   = false;;
            string typeCheck = unitInRange.GetType().ToString();

            string[] splitArray = typeCheck.Split('.');
            typeCheck = splitArray[splitArray.Length - 1];

            if (typeCheck == "MeleeUnit")
            {
                MeleeUnit mu = (MeleeUnit)unitInRange;
                if (Math.Abs(this.YPos - mu.YPos) == 2 || Math.Abs(this.XPos - mu.XPos) == 2)
                {
                    inRange = true;
                }
                else
                {
                    inRange = false;
                }
            }
            else
            {
                RangedUnit ru = (RangedUnit)unitInRange;
                if (Math.Abs(this.YPos - ru.YPos) == 2 || Math.Abs(this.XPos - ru.XPos) == 2)
                {
                    inRange = true;
                }
                else
                {
                    inRange = false;
                }
            }

            return(inRange);
        }
Esempio n. 3
0
        public override Unit ClosestUnit(Unit[] unitClosetCheck)
        {
            int  workingOut, xDis, yDis;
            int  closest   = 1000;
            Unit returnVal = this;

            foreach (Unit temp in unitClosetCheck)
            {
                string   typeCheck  = temp.GetType().ToString();
                string[] splitArray = typeCheck.Split('.');
                typeCheck = splitArray[splitArray.Length - 1];

                if (typeCheck == "MeleeUnit")
                {
                    MeleeUnit m = (MeleeUnit)temp;
                    if (m.XPos != this.XPos && m.YPos != this.YPos)
                    {
                        if (m.Faction != this.Faction)
                        {
                            xDis       = Math.Abs(this.XPos - m.XPos);
                            yDis       = Math.Abs(this.YPos - m.YPos);
                            workingOut = Convert.ToInt32(Math.Sqrt((xDis * xDis) + (yDis * yDis)));

                            if (workingOut < closest)
                            {
                                closest   = workingOut;
                                returnVal = m;
                            }
                        }
                    }
                }
                else
                {
                    RangedUnit r = (RangedUnit)temp;
                    if (r.XPos != this.XPos && r.YPos != this.YPos)
                    {
                        if (r.Faction != this.Faction)
                        {
                            xDis       = Math.Abs(this.XPos - r.XPos);
                            yDis       = Math.Abs(this.YPos - r.YPos);
                            workingOut = Convert.ToInt32(Math.Sqrt((xDis * xDis) + (yDis * yDis)));

                            if (workingOut < closest)
                            {
                                closest   = workingOut;
                                returnVal = r;
                            }
                        }
                    }
                }
            }

            return(returnVal);
        }
Esempio n. 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Values from both the buildings and units are saved into seperate textfiles
            FileStream fsU = new FileStream("SavedUnits/unitTextFile", FileMode.Create, FileAccess.Write);

            fsU.Close();
            FileStream fsB = new FileStream("SavedBuildings/buildingTextFile", FileMode.Create, FileAccess.Write);

            fsB.Close();

            foreach (Unit temp in ge.MapTracker.unitArray)
            {
                string   typeCheck  = temp.GetType().ToString();
                string[] splitArray = typeCheck.Split('.');
                typeCheck = splitArray[splitArray.Length - 1];

                if (typeCheck == "MeleeUnit")
                {
                    MeleeUnit obj = (MeleeUnit)temp;
                    obj.Save();
                }
                else
                {
                    RangedUnit obj = (RangedUnit)temp;
                    obj.Save();
                }
            }

            foreach (Building temp in ge.MapTracker.buildingArray)
            {
                string   typeCheck  = temp.GetType().ToString();
                string[] splitArray = typeCheck.Split('.');
                typeCheck = splitArray[splitArray.Length - 1];

                if (typeCheck == "ResourceBuilding")
                {
                    ResourceBuilding obj = (ResourceBuilding)temp;
                    obj.Save();
                }
                else
                {
                    FactoryBuilding obj = (FactoryBuilding)temp;
                    obj.Save();
                }
            }
        }
Esempio n. 5
0
        public override void Combat(Unit attackingUnit)
        {
            string typeCheck = attackingUnit.GetType().ToString();

            string[] splitArray = typeCheck.Split('.');
            typeCheck = splitArray[splitArray.Length - 1];

            if (typeCheck == "MeleeUnit")
            {
                MeleeUnit mu = (MeleeUnit)attackingUnit;
                mu.Health       -= this.Attk;
                this.isAttacking = false;
            }
            else
            {
                RangedUnit ru = (RangedUnit)attackingUnit;
                ru.Health       -= this.Attk;
                this.IsAttacking = false;
            }
        }
Esempio n. 6
0
        //Both units and buildings tostrings have been added to the rich text box to display stats
        private void Display()
        {
            battleInfo = "";
            foreach (Unit temp in ge.MapTracker.unitArray)
            {
                string   typeCheck  = temp.GetType().ToString();
                string[] splitArray = typeCheck.Split('.');
                typeCheck = splitArray[splitArray.Length - 1];

                if (typeCheck == "MeleeUnit")
                {
                    MeleeUnit obj = (MeleeUnit)temp;
                    battleInfo += obj.ToString();
                }
                else
                {
                    RangedUnit obj = (RangedUnit)temp;
                    battleInfo += obj.ToString();
                }
            }

            foreach (Building temp in ge.MapTracker.buildingArray)
            {
                string   typeCheck  = temp.GetType().ToString();
                string[] splitArray = typeCheck.Split('.');
                typeCheck = splitArray[splitArray.Length - 1];

                if (typeCheck == "ResourceBuilding")
                {
                    ResourceBuilding obj = (ResourceBuilding)temp;
                    battleInfo += obj.ToString();
                }
                else
                {
                    FactoryBuilding obj = (FactoryBuilding)temp;
                    battleInfo += obj.ToString();
                }
            }

            rtxProgress.Text = battleInfo;
        }
Esempio n. 7
0
        private void frmBattlefield_Load(object sender, EventArgs e)
        {
            GameEngine ge = new GameEngine();

            lblMap.Text = ge.MapTracker.drawMap();
            foreach (Unit temp in ge.MapTracker.mapArray)
            {
                string   typeCheck  = temp.GetType().ToString();
                string[] splitArray = typeCheck.Split('.');
                typeCheck = splitArray[splitArray.Length - 1];

                if (typeCheck == "MeleeUnit")
                {
                    MeleeUnit obj = (MeleeUnit)temp;
                    rtxProgress.AppendText(obj.ToString());
                }
                else
                {
                    RangedUnit obj = (RangedUnit)temp;
                    rtxProgress.AppendText(obj.ToString());
                }
            }
        }
Esempio n. 8
0
        public override string Move(Unit unitToEngage)
        {
            string returnVal = "";
            string typeCheck = unitToEngage.GetType().ToString();

            string[] splitArray = typeCheck.Split('.');
            typeCheck = splitArray[splitArray.Length - 1];

            if (typeCheck == "MeleeUnit")
            {
                MeleeUnit m = (MeleeUnit)unitToEngage;
                if ((Math.Abs(m.XPos - this.XPos) > Math.Abs(m.YPos - this.YPos)))
                {
                    if ((m.XPos - this.XPos) > 0)
                    {
                        if (mapTracker.mapVisuals[this.YPos, this.XPos + 1] == 'U' || mapTracker.mapVisuals[this.YPos, this.XPos + 1] == 'u' || mapTracker.mapVisuals[this.YPos, this.XPos + 1] == 'W' || mapTracker.mapVisuals[this.YPos, this.XPos + 1] == 'w')
                        {
                            this.YPos++;
                            this.XPos++;
                            returnVal = "Right";
                        }
                        else
                        {
                            this.XPos++;
                            returnVal = "Right";
                        }
                    }
                    else if ((m.XPos - this.XPos) < 0)
                    {
                        if (mapTracker.mapVisuals[this.YPos, this.XPos - 1] == 'U' || mapTracker.mapVisuals[this.YPos, this.XPos - 1] == 'u' || mapTracker.mapVisuals[this.YPos, this.XPos - 1] == 'W' || mapTracker.mapVisuals[this.YPos, this.XPos - 1] == 'w')
                        {
                            this.YPos++;
                            this.XPos--;
                            returnVal = "Left";
                        }
                        else
                        {
                            this.XPos--;
                            returnVal = "Left";
                        }
                    }
                }
                else
                {
                    if ((m.YPos - this.YPos) > 0)
                    {
                        if (mapTracker.mapVisuals[this.YPos + 1, this.XPos] == 'U' || mapTracker.mapVisuals[this.YPos + 1, this.XPos] == 'u' || mapTracker.mapVisuals[this.YPos + 1, this.XPos - 1] == 'W' || mapTracker.mapVisuals[this.YPos + 1, this.XPos] == 'w')
                        {
                            this.YPos++;
                            this.XPos++;
                            returnVal = "Up";
                        }
                        else
                        {
                            this.YPos++;
                            returnVal = "Up";
                        }
                    }
                    else if ((m.YPos - this.YPos) < 0)
                    {
                        if (mapTracker.mapVisuals[this.YPos - 1, this.XPos] == 'U' || mapTracker.mapVisuals[this.YPos - 1, this.XPos] == 'u' || mapTracker.mapVisuals[this.YPos - 1, this.XPos - 1] == 'W' || mapTracker.mapVisuals[this.YPos - 1, this.XPos] == 'w')
                        {
                            this.YPos--;
                            this.XPos++;
                            returnVal = "Down";
                        }
                        else
                        {
                            this.YPos--;
                            returnVal = "Down";
                        }
                    }
                }
            }
            else
            {
                RangedUnit r = (RangedUnit)unitToEngage;
                if ((Math.Abs(r.XPos - this.XPos) > Math.Abs(r.YPos - this.YPos)))
                {
                    if ((r.XPos - this.XPos) > 0)
                    {
                        if (mapTracker.mapVisuals[this.YPos, this.XPos + 1] == 'U' || mapTracker.mapVisuals[this.YPos, this.XPos + 1] == 'u' || mapTracker.mapVisuals[this.YPos, this.XPos + 1] == 'W' || mapTracker.mapVisuals[this.YPos, this.XPos + 1] == 'w')
                        {
                            this.YPos++;
                            this.XPos++;
                            returnVal = "Right";
                        }
                        else
                        {
                            this.XPos++;
                            returnVal = "Right";
                        }
                    }
                    else if ((r.XPos - this.XPos) < 0)
                    {
                        if (mapTracker.mapVisuals[this.YPos, this.XPos - 1] == 'U' || mapTracker.mapVisuals[this.YPos, this.XPos - 1] == 'u' || mapTracker.mapVisuals[this.YPos, this.XPos - 1] == 'W' || mapTracker.mapVisuals[this.YPos, this.XPos - 1] == 'w')
                        {
                            this.YPos++;
                            this.XPos--;
                            returnVal = "Left";
                        }
                        else
                        {
                            this.XPos--;
                            returnVal = "Left";
                        }
                    }
                }
                else
                {
                    if ((r.YPos - this.YPos) > 0)
                    {
                        if (mapTracker.mapVisuals[this.YPos + 1, this.XPos] == 'U' || mapTracker.mapVisuals[this.YPos + 1, this.XPos] == 'u' || mapTracker.mapVisuals[this.YPos + 1, this.XPos - 1] == 'W' || mapTracker.mapVisuals[this.YPos + 1, this.XPos] == 'w')
                        {
                            this.YPos++;
                            this.XPos++;
                            returnVal = "Up";
                        }
                        else
                        {
                            this.YPos++;
                            returnVal = "Up";
                        }
                    }
                    else if ((r.YPos - this.YPos) < 0)
                    {
                        if (mapTracker.mapVisuals[this.YPos - 1, this.XPos] == 'U' || mapTracker.mapVisuals[this.YPos - 1, this.XPos] == 'u' || mapTracker.mapVisuals[this.YPos - 1, this.XPos - 1] == 'W' || mapTracker.mapVisuals[this.YPos - 1, this.XPos] == 'w')
                        {
                            this.YPos--;
                            this.XPos++;
                            returnVal = "Down";
                        }
                        else
                        {
                            this.YPos--;
                            returnVal = "Down";
                        }
                    }
                }
            }

            return(returnVal);
        }