示例#1
0
文件: map.cs 项目: Carl-hue/GADE1B
        //CLASS METHODS
        public void RandomBattlefield()
        {
            int randomX, randomY;


            ArrUnits = new Unit[sumUnits];
            Random rnd = new Random();

            for (int i = 0; i < 20; i++)
            {
                for (int k = 0; k < 20; k++)
                {
                    arrMap[i, k] = ',';
                }
            }

            for (int i = 0; i < sumUnits; i++)
            {
                randomX = rnd.Next(0, 20);
                randomY = rnd.Next(0, 20);

                int random;
                random = rnd.Next(1, 5);

                if (random == 1)
                {
                    MeleeUnits Unit = new MeleeUnits(randomX, randomY, 100, 1, 5, 1, "Team1", 'X', false);
                    arrMap[Unit.xPos, Unit.yPos] = Unit.symbol;
                    ArrUnits[i] = Unit;
                }
                else if (random == 2)
                {
                    MeleeUnits Unit = new MeleeUnits(randomX, randomY, 100, 1, 5, 1, "Team2", 'x', false);
                    arrMap[Unit.xPos, Unit.yPos] = Unit.symbol;
                    ArrUnits[i] = Unit;
                }
                else if (random == 3)
                {
                    RangedUnits Unit = new RangedUnits(randomX, randomY, 80, 1, 3, 1, "Team1", 'O', false);
                    arrMap[Unit.xPos, Unit.yPos] = Unit.symbol;
                    ArrUnits[i] = Unit;
                }
                else
                {
                    RangedUnits Unit = new RangedUnits(randomX, randomY, 80, 1, 3, 1, "Team2", 'o', false);
                    arrMap[Unit.xPos, Unit.yPos] = Unit.symbol;
                    ArrUnits[i] = Unit;
                }
            }
        }
示例#2
0
        public override void Combat(Unit Enemy)
        {
            string unitType = Enemy.GetType().ToString();

            string[] Type = unitType.Split('.');
            unitType = Type[Type.Length - 1];

            if (unitType == "MeleeUnits")
            {
                MeleeUnits un = (MeleeUnits)Enemy;

                un.HP = un.HP - this.attack;
            }
            else
            {
                RangedUnits un = (RangedUnits)Enemy;

                un.HP = un.HP - this.attack;
            }
        }
示例#3
0
文件: map.cs 项目: Carl-hue/GADE1B
        public void MapUpdate(Unit unitMove, int xOld, int yOld)
        {
            string unitType = unitMove.GetType().ToString();

            string[] Type = unitType.Split('.');
            unitType = Type[Type.Length - 1];

            if (unitType == "MeleeUnit")
            {
                MeleeUnits un = (MeleeUnits)unitMove;
                arrMap[xOld, yOld] = ',';

                arrMap[un.xPos, un.yPos] = un.symbol;
            }
            if (unitType == "RangedUnit")
            {
                RangedUnits un = (RangedUnits)unitMove;
                arrMap[xOld, yOld] = ',';

                arrMap[un.xPos, un.yPos] = un.symbol;
            }
        }
示例#4
0
        public override void AttackRange(Unit Enemy)
        {
            int totalDist;

            string unitType = Enemy.GetType().ToString();

            string[] Type = unitType.Split('.');
            unitType = Type[Type.Length - 1];



            if (unitType == "MeleeUnits")
            {
                MeleeUnits un = (MeleeUnits)Enemy;
                totalDist = Math.Abs(this.xPos - un.xPos) + Math.Abs(this.yPos - un.yPos);
                if (totalDist < this.attackRange)
                {
                    this.isAttacking = true;
                }
                else
                {
                    this.isAttacking = false;
                }
            }
            else
            {
                RangedUnits un = (RangedUnits)Enemy;
                totalDist = Math.Abs(this.xPos - un.xPos) + Math.Abs(this.yPos - un.yPos);
                if (totalDist < this.attackRange)
                {
                    this.isAttacking = true;
                }
                else
                {
                    this.isAttacking = false;
                }
            }
        }
示例#5
0
        public override Unit ClosestUnit(Unit[] Units) // finds the closest unit
        {
            int  xDist, yDist, totalDist, closestDist, checkValue;
            Unit closestUnit, thisUnit;

            closestDist = 19;
            closestUnit = Units[1];
            checkValue  = 69;
            thisUnit    = Units[1];

            for (int i = 0; i < Units.Length; i++)
            {
                string   unitType = Units[i].GetType().ToString();
                string[] Type     = unitType.Split('.');
                unitType = Type[Type.Length - 1];

                if (unitType == "MeleeUnits")
                {
                    MeleeUnits un = (MeleeUnits)Units[i];

                    if (this.xPos == un.xPos && this.yPos == un.yPos || un.Death() || this.team == un.team)
                    {
                        if (this.xPos == un.xPos && this.yPos == un.yPos)
                        {
                            thisUnit = un;
                        }
                    }
                    else
                    {
                        xDist     = Math.Abs(this.xPos - un.xPos);
                        yDist     = Math.Abs(this.yPos - un.yPos);
                        totalDist = xDist + yDist;

                        if (totalDist < closestDist)
                        {
                            closestDist = totalDist;
                            closestUnit = Units[i];
                            checkValue  = 42;
                        }
                    }
                }
                else
                {
                    RangedUnits un = (RangedUnits)Units[i];

                    if (this.xPos == un.xPos && this.yPos == un.yPos || un.Death() || this.team == un.team)
                    {
                        if (this.xPos == un.xPos && this.yPos == un.yPos)
                        {
                            thisUnit = un;
                        }
                    }
                    else
                    {
                        xDist     = Math.Abs(this.xPos - un.xPos);
                        yDist     = Math.Abs(this.yPos - un.yPos);
                        totalDist = xDist + yDist;

                        if (totalDist < closestDist)
                        {
                            closestDist = totalDist;
                            closestUnit = Units[i];
                            checkValue  = 42;
                        }
                    }
                }
                if (checkValue == 69)
                {
                    return(thisUnit);
                }
                else
                {
                    return(closestUnit);
                }
            }
            if (checkValue == 69)
            {
                return(thisUnit);
            }
            else
            {
                return(closestUnit);
            }
        }
示例#6
0
        public string Direction(Unit Main, Unit Enemy)
        {
            string ReturnVal;

            ReturnVal = " ";

            string MainType = Main.GetType().ToString();

            string[] mType = MainType.Split('.');
            MainType = mType[mType.Length - 1];

            string unitType = Enemy.GetType().ToString();

            string[] Type = unitType.Split('.');
            unitType = Type[Type.Length - 1];

            int    xTotal, yTotal;
            string xDirection, yDirection;

            xTotal     = 0;
            yTotal     = 0;
            xDirection = "";
            yDirection = "";

            if (MainType == "MeleeUnit")
            {
                MeleeUnits m = (MeleeUnits)Main;
                if (unitType == "MeleeUnit")
                {
                    MeleeUnits e = (MeleeUnits)Enemy;

                    xTotal = m.xPos - e.xPos;
                    yTotal = m.yPos - e.yPos;

                    if (xTotal > 0)
                    {
                        xDirection = "left";
                    }
                    else if (xTotal < 0)
                    {
                        xDirection = "right";
                    }

                    if (yTotal > 0)
                    {
                        yDirection = "down";
                    }
                    else if (yTotal < 0)
                    {
                        yDirection = "up";
                    }

                    xTotal = Math.Abs(m.xPos - e.xPos);
                    yTotal = Math.Abs(m.yPos - e.yPos);
                }
                else
                {
                    RangedUnits e = (RangedUnits)Enemy;
                    xTotal = m.xPos - e.xPos;
                    yTotal = m.yPos - e.yPos;

                    if (xTotal > 0)
                    {
                        xDirection = "left";
                    }
                    else if (xTotal < 0)
                    {
                        xDirection = "right";
                    }

                    if (yTotal > 0)
                    {
                        yDirection = "down";
                    }
                    else if (yTotal < 0)
                    {
                        yDirection = "up";
                    }

                    xTotal = Math.Abs(m.xPos - e.xPos);
                    yTotal = Math.Abs(m.yPos - e.yPos);
                }
            }
            else
            {
                RangedUnits m = (RangedUnits)Main;
                if (unitType == "MeleeUnit")
                {
                    MeleeUnits e = (MeleeUnits)Enemy;
                    xTotal = m.xPos - e.xPos;
                    yTotal = m.yPos - e.yPos;

                    if (xTotal > 0)
                    {
                        xDirection = "left";
                    }
                    else if (xTotal < 0)
                    {
                        xDirection = "right";
                    }

                    if (yTotal > 0)
                    {
                        yDirection = "down";
                    }
                    else if (yTotal < 0)
                    {
                        yDirection = "up";
                    }

                    xTotal = Math.Abs(m.xPos - e.xPos);
                    yTotal = Math.Abs(m.yPos - e.yPos);
                }
                else
                {
                    RangedUnits e = (RangedUnits)Enemy;
                    xTotal = m.xPos - e.xPos;
                    yTotal = m.yPos - e.yPos;

                    if (xTotal > 0)
                    {
                        xDirection = "left";
                    }
                    else if (xTotal < 0)
                    {
                        xDirection = "right";
                    }

                    if (yTotal > 0)
                    {
                        yDirection = "down";
                    }
                    else if (yTotal < 0)
                    {
                        yDirection = "up";
                    }

                    xTotal = Math.Abs(m.xPos - e.xPos);
                    yTotal = Math.Abs(m.yPos - e.yPos);
                }
            }

            if (xTotal <= yTotal || xTotal > 0)
            {
                ReturnVal = xDirection;
                return(xDirection);
            }
            else
            {
                ReturnVal = yDirection;
                return(yDirection);
            }
        }
示例#7
0
        public void GameLogic(Unit[] ArrUnits)
        {
            gameRounds++;
            Random rnd = new Random();
            bool   death;
            string direction;

            direction = " ";

            death = false;

            OutputString = "";
            for (int i = 0; i < ArrUnits.Length; i++)
            {
                string   unitType = ArrUnits[i].GetType().ToString();
                string[] Type     = unitType.Split('.');
                unitType = Type[Type.Length - 1];

                if (unitType == "MeleeUnit")
                {
                    MeleeUnits un = (MeleeUnits)ArrUnits[i];

                    death = un.Death();
                    if (death == true)
                    {
                    }
                    else
                    {
                        Unit closestunit;
                        closestunit = un.ClosestUnit(ArrUnits);
                        if (un == closestunit)
                        {
                        }
                        else
                        {
                            un.AttackRange(closestunit);
                            if (un.HP <= (un.maxHP * 0.25))
                            {
                                string randomDirection;
                                int    random;

                                random = rnd.Next(1, 5);

                                if (random == 1)
                                {
                                    randomDirection = "left";
                                }
                                else if (random == 2)
                                {
                                    randomDirection = "right";
                                }
                                else if (random == 3)
                                {
                                    randomDirection = "up";
                                }
                                else
                                {
                                    randomDirection = "down";
                                }

                                un.Move(randomDirection);
                            }
                            else
                            {
                                if (un.isAttacking == true)
                                {
                                    un.Combat(closestunit);
                                }
                                else
                                {
                                    int oldX, oldY;
                                    oldX      = un.xPos;
                                    oldY      = un.yPos;
                                    direction = Direction(un, closestunit);
                                    un.Move(direction);
                                    map.MapUpdate(un, oldX, oldY);
                                }
                            }
                        }
                    }
                    OutputString += "\n" + un.ToString();
                }
                else
                {
                    RangedUnits un = (RangedUnits)ArrUnits[i];

                    death = un.Death();
                    if (death == true)
                    {
                    }
                    else
                    {
                        Unit closestunit;
                        closestunit = un.ClosestUnit(ArrUnits);
                        if (un == closestunit)
                        {
                        }
                        else
                        {
                            un.AttackRange(closestunit);
                            if (un.HP <= (un.maxHP * 0.25))
                            {
                                string randomDirection;
                                int    random;

                                random = rnd.Next(1, 5);

                                if (random == 1)
                                {
                                    randomDirection = "left";
                                }
                                else if (random == 2)
                                {
                                    randomDirection = "right";
                                }
                                else if (random == 3)
                                {
                                    randomDirection = "up";
                                }
                                else
                                {
                                    randomDirection = "down";
                                }

                                un.Move(randomDirection);
                            }
                            else
                            {
                                if (un.isAttacking == true)
                                {
                                    un.Combat(closestunit);
                                }
                                else
                                {
                                    int oldX, oldY;
                                    oldX      = un.xPos;
                                    oldY      = un.yPos;
                                    direction = Direction(un, closestunit);
                                    un.Move(direction);
                                    map.MapUpdate(un, oldX, oldY);
                                }
                            }
                        }
                    }
                    OutputString += "\n" + un.ToString();
                }
                OutputString += "\n";
            }
        }