Esempio n. 1
0
        public static List<int> FlexibleNormalMovement(Game game, Entity startEntity, Entity targetEntity,
                                                     bool ignoreSword = false, bool ignorePits = false,
                                                     bool tryPlayerHit = true, bool inverse = false)
        {
            int nextX = 0;
            int nextY = 0;

            if (targetEntity.Y > startEntity.Y)
            {
                nextY = 1;

                if (inverse)
                    nextY = -1;
            }
            else if (targetEntity.Y < startEntity.Y)
            {
                nextY = -1;

                if (inverse)
                    nextY = 1;
            }

            if (targetEntity.X > startEntity.X)
            {
                nextX = 1;

                if (inverse)
                    nextX = -1;
            }
            else if (targetEntity.X < startEntity.X)
            {
                nextX = -1;

                if (inverse)
                    nextX = 1;
            }

            List<int> nextMove = new List<int> { nextX, nextY };

            if (tryPlayerHit && startEntity.X + nextMove[0] == targetEntity.X &&
                startEntity.Y + nextMove[1] == targetEntity.Y)
            {
                if (IsSafeKillPlayer(game, startEntity.X, startEntity.Y, nextMove[0], nextMove[1], ignoreSword,
                    ignorePits))
                {
                    game.Player.Destroy();
                }
            }

            if (IsSafe(game, startEntity.X, startEntity.Y, nextMove[0], nextMove[1], ignoreSword, ignorePits))
            {
                startEntity.Swap(startEntity.X + nextMove[0], startEntity.Y + nextMove[1], startEntity.Z);
            }
            else
            {
                if (((nextMove[0] == 1 || nextMove[0] == -1) && nextMove[1] == 0) ||
                    ((nextMove[1] == 1 || nextMove[1] == -1) && nextMove[0] == 0))
                {
                    if ((nextMove[0] == 1 || nextMove[0] == -1) && nextMove[1] == 0)
                    {
                        if (IsSafe(game, startEntity.X, startEntity.Y, nextMove[0], -1, ignoreSword, ignorePits))
                        {
                            startEntity.Swap(startEntity.X + nextMove[0], startEntity.Y + -1, startEntity.Z);
                            nextMove[1] = -1;
                        }
                        else if (IsSafe(game, startEntity.X, startEntity.Y, nextMove[0], 1, ignoreSword, ignorePits))
                        {
                            startEntity.Swap(startEntity.X + nextMove[0], startEntity.Y + 1, startEntity.Z);
                            nextMove[1] = 1;
                        }
                    }
                    if ((nextMove[1] == 1 || nextMove[1] == -1) && nextMove[0] == 0)
                    {
                        if (IsSafe(game, startEntity.X, startEntity.Y, -1, nextMove[1], ignoreSword, ignorePits))
                        {
                            startEntity.Swap(startEntity.X + -1, startEntity.Y + nextMove[1], startEntity.Z);
                            nextMove[0] = -1;
                        }
                        else if (IsSafe(game, startEntity.X, startEntity.Y, 1, nextMove[1], ignoreSword, ignorePits))
                        {
                            startEntity.Swap(startEntity.X + 1, startEntity.Y + nextMove[1], startEntity.Z);
                            nextMove[0] = 1;
                        }
                    }
                 }
                else
                {
                    int distanceX = Math.Abs(startEntity.X - targetEntity.X);
                    int distanceY = Math.Abs(startEntity.Y - targetEntity.Y);

                    int biggestDistance = distanceY;

                    if (distanceX > distanceY)
                        biggestDistance = distanceX;

                    if (biggestDistance == distanceX)
                    {
                        if (IsSafe(game, startEntity.X, startEntity.Y, nextMove[0], 0, ignoreSword, ignorePits))
                        {
                            startEntity.Swap(startEntity.X + nextMove[0], startEntity.Y, startEntity.Z);
                        }
                        else if (IsSafe(game, startEntity.X, startEntity.Y, 0, nextMove[1], ignoreSword, ignorePits))
                        {
                            startEntity.Swap(startEntity.X, startEntity.Y + nextMove[1], startEntity.Z);
                        }
                    }
                    else if (biggestDistance == distanceY)
                    {
                        if (IsSafe(game, startEntity.X, startEntity.Y, 0, nextMove[1], ignoreSword, ignorePits))
                        {
                            startEntity.Swap(startEntity.X, startEntity.Y + nextMove[1], startEntity.Z);
                        }
                        else if (IsSafe(game, startEntity.X, startEntity.Y, nextMove[0], 0, ignoreSword, ignorePits))
                        {
                            startEntity.Swap(startEntity.X + nextMove[0], startEntity.Y, startEntity.Z);
                        }
                    }
                }
            }

            return nextMove;
        }
Esempio n. 2
0
        public static List<int> DirectMovement(Game game, Entity startEntity, Entity targetEntity,
                                               bool ignoreSword = false, bool ignorePits = false,
                                               bool tryPlayerHit = true)
        {
            int nextX = 0;
            int nextY = 0;

            if (targetEntity.Y > startEntity.Y)
            {
                nextY = 1;
            }
            else if (targetEntity.Y < startEntity.Y)
            {
                nextY = -1;
            }

            if (targetEntity.X > startEntity.X)
            {
                nextX = 1;
            }
            else if (targetEntity.X < startEntity.X)
            {
                nextX = -1;
            }

            List<int> nextMove = new List<int> { nextX, nextY };

            if (tryPlayerHit && startEntity.X + nextMove[0] == targetEntity.X &&
                startEntity.Y + nextMove[1] == targetEntity.Y)
            {
                if (IsSafeKillPlayer(game, startEntity.X, startEntity.Y, nextMove[0], nextMove[1], ignoreSword,
                    ignorePits))
                {
                    game.Player.Destroy();
                }
            }

            if (IsSafe(game, startEntity.X, startEntity.Y, nextMove[0], nextMove[1], ignoreSword, ignorePits))
            {
                startEntity.Swap(startEntity.X + nextMove[0], startEntity.Y + nextMove[1], startEntity.Z);
            }

            return nextMove;
        }