// İki Rotate Fonksinyonu kullanılmak istenilmez ise //public void Rotate(string dir) //{ // if (dir == "R") // { // var tmp = (int)(Direction + 90) % 360; // Direction = (Directions)tmp; // } // else if (dir == "L") // { // var tmp = (int)(Direction + 270) % 360; // Direction = (Directions)tmp; // } // else // { // Console.WriteLine("Invalid Direction"); // } // PrinterHelper.Print(Direction); //} public void RotateRight() { switch (Direction) { case Directions.N: Direction = Directions.E; PrinterHelper.Print(Direction); break; case Directions.E: Direction = Directions.S; PrinterHelper.Print(Direction); break; case Directions.S: Direction = Directions.W; PrinterHelper.Print(Direction); break; case Directions.W: Direction = Directions.N; PrinterHelper.Print(Direction); break; default: break; } }
private void WriteMoveMessage(List <string> moves, Turtle turtle, ProjectSetting projectSetting) { PrinterHelper.Print(turtle); if (Enum.TryParse <Directions>(projectSetting.Direction, out var dir)) { turtle.Direction = dir; for (int i = 0; i < moves.Count; i++) { var array = moves[i].Split(' '); var count = array.Length; for (int j = 0; j < array.Length; j++) { MoveStrategyService.MakeMove(turtle, array[j]); var observe = _observer.Observe(turtle.Position); moveCount++; if (observe || moveCount == count) { turtle.Position = new Point(1, 0); turtle.Direction = Directions.N; j = array.Length; if (!observe && moveCount == count) { _observer.IsDanger(); } } } } } }
public void Move() { switch (Direction) { case Directions.N: PrinterHelper.Print(_turtle.Position, new Point { X = _turtle.Position.X, Y = _turtle.Position.Y + 1 }); _turtle.Position = new Point { X = _turtle.Position.X, Y = _turtle.Position.Y + 1 }; break; case Directions.S: PrinterHelper.Print(_turtle.Position, new Point { X = _turtle.Position.X, Y = _turtle.Position.Y - 1 }); _turtle.Position = new Point { X = _turtle.Position.X, Y = _turtle.Position.Y - 1 }; break; case Directions.E: PrinterHelper.Print(_turtle.Position, new Point { X = _turtle.Position.X + 1, Y = _turtle.Position.Y }); _turtle.Position = new Point { X = _turtle.Position.X + 1, Y = _turtle.Position.Y }; break; case Directions.W: PrinterHelper.Print(_turtle.Position, new Point { X = _turtle.Position.X - 1, Y = _turtle.Position.Y }); _turtle.Position = new Point { X = _turtle.Position.X - 1, Y = _turtle.Position.Y }; break; } }