예제 #1
0
        public void Move()
        {
            Point newPosition = Position;

            switch (Heading)
            {
            case Direction.North: newPosition += new Size(0, 1); break;

            case Direction.East: newPosition += new Size(1, 0); break;

            case Direction.South: newPosition += new Size(0, -1); break;

            case Direction.West: newPosition += new Size(-1, 0); break;
            }

            // Can't move outside the fence
            if (Fence.Contains(newPosition))
            {
                Position = newPosition;
            }
        }