/// <summary> /// Add a new rover to this plateau /// </summary> /// <param name="positionX"></param> /// <param name="positionY"></param> /// <param name="direction"></param> /// <returns></returns> public Rover AddRover(int positionX, int positionY, char direction) { // Rover can only be added inside the coordinates if (positionX < 0 || positionX > MaxX || positionY < 0 || positionY > MaxY) { throw new ArgumentException(string.Format("Invalid Rover location {0} {1}", positionX, positionY)); } // A rover might already be standing at the given coordinates, this must be an error if (Rovers.Any(r => r.PositionX == positionX && r.PositionY == positionY)) { throw new ArgumentException("A rover is already standing at this position!"); } // Valid directions are N,E,W,S if (!Enum.TryParse <DirectionE>(direction.ToString(), out DirectionE directionE)) { throw new ArgumentException(string.Format("Invalid direction {0}", direction)); } var rover = new Rover(this); rover.SetPosition(positionX, positionY, directionE); Rovers.Add(rover); ActiveRover = rover; return(rover); }
public void AddRover(ICoordinates coordinates, string direction) { var initialPosition = new Position(Plateau, coordinates); CurrentRover = new MarsRover(initialPosition, direction); Rovers.Add(CurrentRover); }
public void Run() => Rovers.ForEach(p => { Console.WriteLine(p.Commands); Console.WriteLine(p.ToString()); p.Run(); Console.WriteLine(p.ToString()); });
public void DeployRover(int x, int y, Direction direction) { CheckIfLocationToDeployIsValid(x, y); var rover = new Rover(x, y, direction, LandingSurface); Rovers.Add(rover); ActiveRover = rover; }
public void AddRover(IRover rover) { if (rover.PositionX > Width || rover.PositionY > Height) { throw new PlateauSizeException(); } Rovers.Add(rover); }
public void AddRover(IRover rover) { if (rover.LocationX > SizeX || rover.LocationY > SizeY) { throw new PlateauSizeOverException(); } Rovers.Add(rover); }
public Rover DeployRover(Position roverPosition) { var rover = new Rover { Position = roverPosition }; Rovers.Add(rover); return(rover); }
/// <summary> /// Sets Rover position on the Plateau /// </summary> /// <param name="point"></param> /// <param name="direction"></param> public void DeployRover(Point point, Direction direction) { // Check rover position CheckIfPositionToDeployIsValid(point); // Create new Rover, Add it to list and set it as active var rover = new Rover(point, direction, Surface); Rovers.Add(rover); ActiveRover = rover; }
public void AddRover(int x, int y, Direction direction, string commands) { var point = Points.FirstOrDefault(p => p.X == x && p.Y == y); if (point is null) { Console.WriteLine("Invalid coordinate!"); return; } Rovers.Add(new Rover(point, direction, commands, MoveManager)); }
public bool IsValidPoint(Point point) { var isValidX = point.XPosition >= 0 && point.XPosition <= Size.Width; var isValidY = point.YPosition >= 0 && point.YPosition <= Size.Height; if (Rovers.Count(t => t.Value.Key == point.XPosition && t.Value.Value == point.YPosition) > 1) { return(false); //throw new Exception("Aracın hareket etmek istediği noktada başka bir uzay aracı bulunmaktadır.Bu sebepten hareket etmemelidir."); } return(isValidX && isValidY); }
public void DeployRover(int xCoordinate, int yCoordinate, Direction deployedDirection) { if (xCoordinate >= 0 && yCoordinate >= 0 && yCoordinate < Surface.Size.Height && xCoordinate < Surface.Size.Width) { var rover = new Rover(xCoordinate, yCoordinate, deployedDirection, Surface); Rovers.Add(rover); ActiveRover = rover; Logger.WriteLog(this.GetType().Name, $"Rover is deployed successfully. XCoordinate : {xCoordinate} YCoordinate : {yCoordinate} Direction : {rover.Direction:G}"); } else { Logger.WriteLog(this.GetType().Name, $"Rover is deployed to out of surface. XCoordinate : {xCoordinate} YCoordinate : {yCoordinate} Direction : {deployedDirection:G}"); } }
static void Main() { Plateau plateau = new Plateau(); plateau.SetPlateauSize(5, 5); Rovers rovers = new Rovers(); rovers.CreateNewRover(1, 2, Common.N, "LMLMLMLMM", plateau); rovers.CreateNewRover(3, 3, Common.E, "MMRMMRMRRM", plateau); foreach (Rover rover in rovers.GetRoverList()) { rover.PrintPosition(); } Console.ReadLine(); }
static void Main(string[] args) { //DI IServiceCollection services = new ServiceCollection(); services.AddSingleton <IRoverBussiness, RoverBussiness>(); services.AddSingleton <IPlateauBussiness, PlateauBussiness>(); services.AddSingleton <IExplore, Move>(); IPlateauBussiness plateauBussiness = services.BuildServiceProvider().GetService <IPlateauBussiness>(); IRoverBussiness roverBussiness = services.BuildServiceProvider().GetService <IRoverBussiness>(); Console.WriteLine("Initializing started..."); Plateau plateau = null; bool isCorrectSize = false; while (!isCorrectSize) // First input init. Correct Format. Some Validation. { Console.WriteLine("Okey captan give some coordinaties"); string sizeInput = Console.ReadLine(); plateau = plateauBussiness.sizeParse(sizeInput); if (plateau != null) { isCorrectSize = true; } } Console.WriteLine("Kirk, rover first location");//First Line Rover Currenct Location string firstPosition = Console.ReadLine(); Console.WriteLine("Rover direction"); //Second Line Rover Direction string direction = Console.ReadLine(); Rovers currenctRover = roverBussiness.CurrentRover(firstPosition); //Binding Object... if (currenctRover != null) { roverBussiness.GetNewLocation(direction); } Console.WriteLine("Kirk Expected Output right here: {0} {1} {2}", currenctRover.RoverLocation.X, currenctRover.RoverLocation.Y, currenctRover.RoverLocation.Direction.ToString()); }
public void DeployRover(Rover rover) { Rovers.Add(rover); if (rover.XLocation > this.SizeX) { throw new System.InvalidOperationException("Cannot Deploy Rover to outside of plateu!"); } if (rover.YLocation > this.SizeY) { throw new System.InvalidOperationException("Cannot Deploy Rover to outside of plateu!"); } if (this.Map[rover.XLocation, rover.YLocation] == 0) { this.Map[rover.XLocation, rover.YLocation] = 1; } else { throw new System.InvalidOperationException("Cannot Deploy Rover on Another Rover!"); } }
public void AddRoverWithInformation(int XPos, int YPos, string direction) { try { Direction DirectionOfRover = (Direction)Enum.Parse(typeof(Direction), direction); if (XPos > XMax || YPos > YMax) { throw new ArgumentOutOfRangeException(); } Rovers.Add(new Rover(XPos, YPos, DirectionOfRover, RoverCount)); RoverCount += 1; } catch (ArgumentOutOfRangeException) { throw new ArgumentOutOfRangeException("Position of rover is not inside the plateau!"); } catch (ArgumentException) { throw new ArgumentException("Given direction is not valid direction. It should N, W, E or S!"); } }
public Rovers CurrentRover(string location) { if (string.IsNullOrEmpty(location)) { Console.WriteLine("Spock give some coordinates..."); return(null); } var currectLocation = location.Split(' '); if (currectLocation.Length != 3) { Console.WriteLine("Spock... U're smart man. Right location pls."); return(null); } var x = int.Parse(currectLocation[0]); var y = int.Parse(currectLocation[1]); string direction = currectLocation[2].ToUpper(); Direction directionEnum; if (Enum.TryParse(direction, out directionEnum)) { roverLocation = new RoverLocation(x, y, directionEnum); } else { Console.WriteLine("Spock... U're smart man. Right direction pls."); return(null); } Rovers rover = new Rovers(roverLocation); return(rover); }
public void Reset() { Size = Size.Empty; Rovers.Clear(); }
public void AddRover(RoverClient rover) { Rovers.Add(rover); }
public void RemoveRovers(IRover rover) { Rovers.Remove(rover); }
public void PrintRovers() { Array.ForEach(Rovers.ToArray(), Console.WriteLine); }
public void AddRovers(IRover rover) { Rovers.Add(rover); }