public Position() { this.x = 0; this.y = 0; this.Directon = Enums.Directions.N; }
public void Turn(Enums.Sides side) { switch (side) { case Enums.Sides.Left: { if (Direction.Equals(Enums.Directions.East)) { Direction = Enums.Directions.North; break; } Direction = (Enums.Directions)Enum.ToObject(typeof(Enums.Directions), ((byte)Direction) + 1); break; } case Enums.Sides.Right: { if (Direction.Equals(Enums.Directions.North)) { Direction = Enums.Directions.East; break; } Direction = Direction = (Enums.Directions)Enum.ToObject(typeof(Enums.Directions), ((byte)Direction) - 1); break; } } }
private void Spin90DegreesLeft() { Direction = Direction switch { Enums.Directions.N => Enums.Directions.W, Enums.Directions.S => Enums.Directions.E, Enums.Directions.E => Enums.Directions.N, Enums.Directions.W => Enums.Directions.S, _ => Direction }; }
/// <summary> /// Rotates turtle. /// </summary> /// <param name="left">Boolean used for rotating the turtle left or right.</param> public void RotateTurtle(bool left) { if (left) { turtleDirection = GetPreviousDirection(turtleDirection); } else { turtleDirection = GetNextDirection(turtleDirection); } SetTurtleDirectionArrow(); DrawGame(); }
/// <summary> /// Gets previous direction. /// </summary> /// <param name="direction">Current direction.</param> private Enums.Directions GetPreviousDirection(Enums.Directions direction) { switch (direction) { case Enums.Directions.North: return(Enums.Directions.West); case Enums.Directions.East: return(Enums.Directions.North); case Enums.Directions.South: return(Enums.Directions.East); case Enums.Directions.West: return(Enums.Directions.South); default: throw new IndexOutOfRangeException(); } }
public static void SetAxisTowards(Enums.Directions axis, Transform t, Vector2 direction) { switch (axis) { case Enums.Directions.Up: t.up = direction; break; case Enums.Directions.Down: t.up = -direction; break; case Enums.Directions.Right: t.right = direction; break; case Enums.Directions.Left: t.right = -direction; break; } }
private void SpinRight() //Assuming 90 degree { switch (this.Directon) { case Enums.Directions.N: this.Directon = Enums.Directions.E; break; case Enums.Directions.S: this.Directon = Enums.Directions.W; break; case Enums.Directions.E: this.Directon = Enums.Directions.S; break; case Enums.Directions.W: this.Directon = Enums.Directions.N; break; default: break; } }
public RoverPosition() { X = 0; Y = 0; Direction = Enums.Directions.N; }