예제 #1
0
파일: Position.cs 프로젝트: GooDer/descent
        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
파일: Position.cs 프로젝트: GooDer/descent
        public int DistanceFromPosition(Position other)
        {
            var diffX = Math.Abs(X - other.X);
            var diffY = Math.Abs(Y - other.Y);

            return Math.Max(diffX, diffY);
        }