Пример #1
0
        public static void menu(Turtle player, int[,] room, string[] mainArgs)
        {
            Console.WriteLine("1 Pen UP");
            Console.WriteLine("2 Pen DOWN");
            Console.WriteLine("3 Turn RIGHT");
            Console.WriteLine("4 Turn LEFT");
            Console.WriteLine("5,10 Move FORWARD 10 spaces (replace 10 for a different number of spaces)");
            Console.WriteLine($"6 Display the 20-by-{player.RoomWidth} array");
            Console.WriteLine("9 End of Data (sentinel)");
            Console.WriteLine($"Turtle is facing {player.direction} from {player.x}, {player.y} and pen is {(player.Pen ? "Down" : "Up")}");

            string[] commandList = mainArgs;

            bool ShowScreen = false;    // don't draw by default
            bool Continue   = true;     // continue by default

            if (mainArgs == null)
            {
                Console.WriteLine("Choose a command (comma separated list of commands is accepted): ");
                commandList = Console.ReadLine().Split(new char[] { ',', ' ' },
                                                       StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                Continue = false;
            }


            for (int i = 0; i < commandList.Length; i++)
            {
                int command;
                if (int.TryParse(commandList[i], out command))
                {
                    switch (command)
                    {
                    case 1: player.PenUp(); break;

                    case 2: player.PenDown(); break;

                    case 3: player.TurnRight(room); break;

                    case 4: player.TurnLeft(room); break;

                    case 5: player.MoveForward(room, int.Parse(commandList[++i])); break;

                    case 6: ShowScreen = true; break;

                    case 9: Continue = false; break;

                    default: Console.WriteLine("Invalid command!"); break;
                    }
                }
            }
            Console.Clear();                               // clear screen
            if (ShowScreen)
            {
                Program.RefreshScreen();                   // show what you drew
            }
            if (Continue)
            {
                Program.NextCommand();                     // refresh menu
            }
        }