private void buttonDraw_Click(object sender, EventArgs e) { Turtle.Delay = 200; Turtle.Rotate(30); Turtle.Forward(200); Turtle.Rotate(120); Turtle.Forward(200); Turtle.Rotate(120); Turtle.Forward(200); Turtle.Rotate(-30); Turtle.PenUp(); Turtle.Backward(50); Turtle.PenDown(); Turtle.Backward(100); Turtle.PenUp(); Turtle.Forward(150); Turtle.PenDown(); Turtle.Rotate(30); }
private void buttonDraw_Click(object sender, EventArgs e) { // Assign a delay to visualize the drawing process Turtle.Delay = 200; // Draw a equilateral triangle Turtle.Rotate(30); Turtle.Forward(200); Turtle.Rotate(120); Turtle.Forward(200); Turtle.Rotate(120); Turtle.Forward(200); // Draw a line in the triangle Turtle.Rotate(-30); Turtle.PenUp(); Turtle.Backward(50); Turtle.PenDown(); Turtle.Backward(100); Turtle.PenUp(); Turtle.Forward(150); Turtle.PenDown(); Turtle.Rotate(30); }
public static void NextCommand() { Turtle.menu(player, room, programArgs); // show menu }
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 } }
private void buttonReset_Click(object sender, EventArgs e) { Turtle.Reset(); }