private static Coords NewCoords(Coords coords, Direction.Facing facing) { Coords newCoords = new Coords(coords.GetRow(), coords.GetCol()); switch (facing) { case Direction.Facing.NORTH: newCoords.SetRow(newCoords.GetRow() + 1); break; case Direction.Facing.EAST: newCoords.SetCol(newCoords.GetCol() + 1); break; case Direction.Facing.SOUTH: newCoords.SetRow(newCoords.GetRow() - 1); break; case Direction.Facing.WEST: newCoords.SetCol(newCoords.GetCol() - 1); break; default: break; } return(newCoords); }
public void CanRotateLeft() { facing = Direction.Facing.EAST; var result = Direction.Left(facing); Assert.Equal(Direction.Facing.NORTH, result); }
public void CanRotateRight() { facing = Direction.Facing.EAST; var result = Direction.Right(facing); Assert.Equal(Direction.Facing.SOUTH, result); }
public void CanLoopRight() { facing = Direction.Facing.EAST; var result = facing; for (int i = 0; i < 9; i++) { result = Direction.Right(result); } Assert.Equal(Direction.Facing.SOUTH, result); }
public static Coords Move(Table table, Coords coords, Direction.Facing facing) { Coords newCoords = NewCoords(coords, facing); if (table.IsOnBoard(newCoords)) { return(newCoords); } else { return(coords); } }
public void Place(int row, int column, Direction.Facing facing) { Coords coords = new Coords(row, column); if (table.IsOnBoard(coords)) { this.coords = coords; this.facing = facing; } else { Console.WriteLine("Invalid Place Command - coordinates must be on the table"); } }
public void ExecuteCommand(string command) { string function = command.Split(' ')[0].ToUpper(); //Console.WriteLine(function); try { switch (function) { case "PLACE": string[] placementData = command.Split(' ')[1].ToUpper().Split(','); int row = Int32.Parse(placementData[0]); int col = Int32.Parse(placementData[1]); Direction.Facing facing = Direction.GetFacing(command.Split(' ')[1].ToUpper().Split(',')[2]); Place(row, col, facing); break; case "RIGHT": Right(); break; case "LEFT": Left(); break; case "MOVE": Move(); break; case "REPORT": Report(); break; default: break; } } catch { Console.WriteLine("INVALID COMMAND"); } }
public void Right() { facing = Direction.Right(facing); }
public void Left() { facing = Direction.Left(facing); }