示例#1
0
        public int MoveTowardPosition(Position other, int movePoints)
        {
            while (movePoints > 0 && (DistanceFromPosition(other) != 1))
            {
                if (X > other.X)
                {
                    X--;
                } else if (X < other.X)
                {
                    X++;
                }

                if (Y > other.Y)
                {
                    Y--;
                } else if (Y < other.Y)
                {
                    Y++;
                }

                movePoints--;
            }

            return movePoints;
        }
示例#2
0
        public int DistanceFromPosition(Position other)
        {
            var diffX = Math.Abs(X - other.X);
            var diffY = Math.Abs(Y - other.Y);

            return Math.Max(diffX, diffY);
        }