Пример #1
0
        /// <summary>
        /// Observes a rover's location change and sets the appropriated squares that were affected by the operation
        /// </summary>
        void Rover_OnLocationChanged(object sender, RoverLocationEventArgs e)
        {
            Rover rover = sender as Rover;

            RoverBoardSquare oldSquare = GetSquareByLocation(e.OldLocation);
            RoverBoardSquare newSquare = GetSquareByLocation(e.NewLocation);

            oldSquare.IsSet = false;
            oldSquare.Rover = null;

            newSquare.IsSet = true;
            newSquare.Rover = rover;
        }
Пример #2
0
        /// <summary>
        /// Sets a Rover object on the board
        /// </summary>
        /// <param name="location">The required location for the Rover</param>
        /// <param name="direction">The initial direction of the Rover</param>
        /// <returns>The Rover object set on the board</returns>
        public Rover SetRoverOnBoard(Point location, RoverDirection direction = RoverDirection.North)
        {
            RoverBoardSquare square = GetSquareByLocation(location);

            square.IsSet = true;
            square.Rover = new Rover
            {
                Direction = direction,
                Location  = location
            };
            square.Rover.OnLocationChanged += new EventHandler <RoverLocationEventArgs>(Rover_OnLocationChanged);

            return(square.Rover);
        }