Ejemplo n.º 1
0
        public void AttackHelper(Character character)
        {
            attackFlag = 1;
            attackingCharacter = character;

            Vector2 charPos = attackingCharacter.getPosition();

            for (int i = 0; i < map.getHeight(); i++)
            {
                for (int j = 0; j < map.getWidth(); j++)
                {

                    if (((Math.Abs((int)charPos.Y / 60 - j)) + (Math.Abs((int)charPos.X / 60 - i))) <= attackingCharacter.AttackRange)
                    {
                        map.GetSquare(i, j).IsAttackable = true;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void MoveToEnemy(Character character)
        {
            Character closestEnemy =  charList[0];
            int minDistance = (int)Math.Sqrt(((int)character.getPosition().Y / 60 - (int)closestEnemy.getPosition().Y / 60) * ((int)character.getPosition().Y / 60 - (int)closestEnemy.getPosition().Y / 60) - ((int)character.getPosition().X / 60 - (int)closestEnemy.getPosition().X / 60) * ((int)character.getPosition().X / 60 - (int)closestEnemy.getPosition().X) / 60);

            for (int i = 0; i < map.getHeight(); i++)
            {
                for (int j = 0; j < map.getWidth(); j++)
                {
                    if (map.GetSquare(i, j).getCurrentChar() != null && map.GetSquare(i, j).getCurrentChar().PlayerIndex == 1)
                    {
                        Character temp = map.GetSquare(i, j).getCurrentChar();
                        int distance = (int)Math.Sqrt(((int)character.getPosition().Y / 60 - (int)temp.getPosition().Y / 60) * ((int)character.getPosition().Y / 60 - (int)temp.getPosition().Y / 60) - ((int)character.getPosition().X / 60 - (int)temp.getPosition().X / 60) * ((int)character.getPosition().X / 60 - (int)temp.getPosition().X / 60));

                        if (distance < minDistance)
                        {
                            closestEnemy = temp;
                            minDistance = distance;
                        }
                    }
                }
            }

            if (character.HasMoved == false)
            {
                cursor.MoveHelper(character);
                int distance = 9000;
                Vector2 toMove = new Vector2();

                for (int i = 0; i < map.getHeight(); i++)
                {
                    for (int j = 0; j < map.getWidth(); j++)
                    {
                        if (map.GetSquare(i, j).IsMovable == true)
                        {
                            int distanceToEnemy = (int)Math.Sqrt(Math.Pow((int)j - ((int)closestEnemy.getPosition().Y / 60), 2) + Math.Pow((int)i - ((int)closestEnemy.getPosition().X / 60), 2));

                            if (distanceToEnemy < distance)
                            {
                                if(distanceToEnemy >= 1)
                                {
                                    distance = distanceToEnemy;
                                    toMove.X = i;
                                    toMove.Y = j;
                                }
                            }
                        }
                    }
                }
                character.Move((int)toMove.X, (int)toMove.Y);
                character.HasMoved = true;

                cursor.ClearBoard();
            }
        }
Ejemplo n.º 3
0
        private void MoveToCamp(Character character)
        {
            Vector2 campPosition;
            Vector2 minCampPosition = new Vector2(); ;
            int minCampDistance = 9000;
            Character nearbyCamp;

            foreach (Character camp in charList)
            {
                if (camp.CharType == "camp")
                {
                    campPosition = camp.getPosition();
                    campPosition.X = (int)campPosition.X / 60;
                    campPosition.Y = (int)campPosition.Y / 60;

                    if ((int)Math.Sqrt((campPosition.X * campPosition.X) + (campPosition.Y * campPosition.Y)) < minCampDistance)
                    {
                        minCampPosition = campPosition;
                        nearbyCamp = camp;
                    }
                }
            }

            cursor.MoveHelper(character);

            int minDistance = 9000;
            Vector2 toMove = new Vector2();
            for (int i = 0; i < map.getHeight(); i++)
            {
                for (int j = 0; j < map.getWidth(); j++)
                {
                    if (map.GetSquare(i, j).IsMovable == true)
                    {
                        int distanceToCamp = (int)Math.Sqrt(Math.Abs((i - minCampPosition.Y) * (i - minCampPosition.Y)) - Math.Abs((j - minCampPosition.X) * (j - minCampPosition.X)));

                        if (distanceToCamp < minDistance)
                        {
                            minDistance = distanceToCamp;
                            toMove.X = j;
                            toMove.Y = i;
                        }
                    }
                }
            }

            if (character.HasMoved == false)
            {
                character.Move((int)toMove.Y, (int)toMove.X);
                character.HasMoved = true;

                //map.GetSquare((int)character.getPosition().Y / 60, (int)character.getPosition().X / 60).TileDeselect();
                cursor.ClearBoard();

                if ((int)(character.getPosition().X / 60) + 1 < 10 && map.GetSquare((int)(character.getPosition().Y / 60), (int)(character.getPosition().X / 60) + 1).getCurrentChar() != null)
                {
                    if (map.GetSquare((int)(character.getPosition().Y / 60), (int)(character.getPosition().X / 60) + 1).getCurrentChar().CharType == "camp")
                    {
                        BuyMercenary(character);
                    }
                }
                if ((int)(character.getPosition().Y / 60) - 1 >= 0 && map.GetSquare((int)(character.getPosition().Y / 60) - 1, (int)(character.getPosition().X / 60)).getCurrentChar() != null)
                {
                    if (map.GetSquare((int)(character.getPosition().Y / 60) - 1, (int)(character.getPosition().X / 60)).getCurrentChar().CharType == "camp")
                    {
                        BuyMercenary(character);
                    }
                }
                if ((int)(character.getPosition().X / 60) - 1 >= 0 && map.GetSquare((int)(character.getPosition().Y / 60), (int)(character.getPosition().X / 60) - 1).getCurrentChar() != null)
                {
                    if (map.GetSquare((int)(character.getPosition().Y / 60), (int)(character.getPosition().X / 60) - 1).getCurrentChar().CharType == "camp")
                    {
                        BuyMercenary(character);
                    }
                }
                if ((character.getPosition().Y / 60) + 1 < 10 && map.GetSquare((int)(character.getPosition().Y / 60) + 1, (int)(character.getPosition().X / 60)).getCurrentChar() != null)
                {
                    if (map.GetSquare((int)(character.getPosition().Y / 60) + 1, (int)(character.getPosition().X / 60)).getCurrentChar().CharType == "camp")
                    {
                        BuyMercenary(character);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void MoveHelper(Character character)
        {
            moveFlag = 1;
            movingCharacter = character;

            Vector2 charPos = movingCharacter.getPosition();

            for (int i = 0; i < map.getHeight(); i++)
            {
                for (int j = 0; j < map.getWidth(); j++)
                {
                    if (((Math.Abs((int)charPos.Y / 60 - j)) + (Math.Abs((int)charPos.X / 60 - i))) <= movingCharacter.MoveDistance
                        && map.GetSquare(j,i).getCurrentChar() == null)
                    {
                        map.GetSquare(i, j).IsMovable = true;
                    }
                }
            }
        }