示例#1
0
        public string[] Start()
        {
            List <string> results = new List <string>();

            for (int i = 0; i < routes.Length; i++)
            {
                //the turtle is created for every series of moves
                Turtle turtle = new Turtle(startPoint.X, startPoint.Y, startPoint.Direction, board);
                string result = string.Empty;
                for (int j = 0; j < routes[i].Length; j++)
                {
                    result = MoveOrTurn(turtle, routes[i][j]);
                    if (result != string.Empty && result != "Still in Danger")
                    {
                        break;
                    }
                }
                results.Add(result);
            }

            return(results.ToArray());
        }
示例#2
0
        private string MoveOrTurn(Turtle turtle, string command)
        {
            string result = string.Empty;

            if (command.Length > 1)
            {
                throw new Exception("Series of commands must be char");
            }

            switch (command)
            {
            case "M":
                result = turtle.Move();
                break;

            case "R":
            case "L":
                turtle.Turn(command[0]);
                break;
            }


            return(result);
        }