/// <summary>
        /// Gets the output for REPORT command
        /// </summary>
        /// <param name="turtle">turtle class instance</param>
        /// <param name="isSuccess">boolean representing a successful execution</param>
        /// <returns>command output</returns>
        private string GetReport(ITurtle turtle, out bool isSuccess)
        {
            if (turtle != null && turtle.Report() != null)
            {
                TurtleState currentState = turtle.Report();
                isSuccess = true;
                return(string.Format("{0}, {1}, {2}", currentState.X, currentState.Y, currentState.FacingDirection.ToString().ToUpper()));
            }

            isSuccess = false;
            return("Please place the turtle on the board before trying to get its current state.");
        }
Beispiel #2
0
        /// <summary>
        /// PLACE Command
        /// </summary>
        /// <param name="turtleState">arguments X Y and F encapsulated inside TurtleState Object</param>
        /// <returns>execution status</returns>
        public bool Place(TurtleState turtleState)
        {
            var action = TurtleInstruction.Place;

            // Check if the placement is valid
            if (this.IsTurtleInsideTable(turtleState.X.Value, turtleState.Y.Value))
            {
                this.turtleState = turtleState;
                return(true);
            }

            // invalid command
            this.SetErrorMessage(action, false);
            return(false);
        }