コード例 #1
0
ファイル: Plateau.cs プロジェクト: hashgit/MarsRover
        /// <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);
        }
コード例 #2
0
        public void AddRover(ICoordinates coordinates, string direction)
        {
            var initialPosition = new Position(Plateau, coordinates);

            CurrentRover = new MarsRover(initialPosition, direction);
            Rovers.Add(CurrentRover);
        }
コード例 #3
0
 public void Run() => Rovers.ForEach(p =>
 {
     Console.WriteLine(p.Commands);
     Console.WriteLine(p.ToString());
     p.Run();
     Console.WriteLine(p.ToString());
 });
コード例 #4
0
        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;
        }
コード例 #5
0
        public void AddRover(IRover rover)
        {
            if (rover.PositionX > Width || rover.PositionY > Height)
            {
                throw new PlateauSizeException();
            }

            Rovers.Add(rover);
        }
コード例 #6
0
        public void AddRover(IRover rover)
        {
            if (rover.LocationX > SizeX || rover.LocationY > SizeY)
            {
                throw new PlateauSizeOverException();
            }

            Rovers.Add(rover);
        }
コード例 #7
0
        public Rover DeployRover(Position roverPosition)
        {
            var rover = new Rover
            {
                Position = roverPosition
            };

            Rovers.Add(rover);
            return(rover);
        }
コード例 #8
0
ファイル: RoverManager.cs プロジェクト: fbozkurt1/mars-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;
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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);
        }
コード例 #11
0
 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}");
     }
 }
コード例 #12
0
        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();
        }
コード例 #13
0
        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());
        }
コード例 #14
0
ファイル: Plateu.cs プロジェクト: yigitsk/hbassignment
 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!");
     }
 }
コード例 #15
0
ファイル: Plateau.cs プロジェクト: xephtar/MarsRoverProject
 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!");
     }
 }
コード例 #16
0
        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);
        }
コード例 #17
0
ファイル: Plateau.cs プロジェクト: timnew/MarsRover
 public void Reset()
 {
     Size = Size.Empty;
     Rovers.Clear();
 }
コード例 #18
0
 public void AddRover(RoverClient rover)
 {
     Rovers.Add(rover);
 }
コード例 #19
0
ファイル: MarsSurface.cs プロジェクト: Davuter/Git
 public void RemoveRovers(IRover rover)
 {
     Rovers.Remove(rover);
 }
コード例 #20
0
ファイル: Plateau.cs プロジェクト: hashgit/MarsRover
 public void PrintRovers()
 {
     Array.ForEach(Rovers.ToArray(), Console.WriteLine);
 }
コード例 #21
0
ファイル: MarsSurface.cs プロジェクト: Davuter/Git
 public void AddRovers(IRover rover)
 {
     Rovers.Add(rover);
 }