示例#1
0
        //Movement takes in the enemy unit the current unit needs to move to and finds the shortest way of getting to that unit without moviong diagonally
        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);
        }