public void Land(IPlateau plateau) { if (!plateau.CheckPoint(Position)) { throw new Exception("Position out of bounds"); } }
public void Move(IPlateau plateau) { foreach (var instruction in Instructions) { switch (instruction) { case Instruction.Right: Direction = Right(Direction); break; case Instruction.Left: Direction = Left(Direction); break; case Instruction.Forward: var next = Move(); try { plateau.Move(this, next); } finally { Position = next; } break; default: throw new Exception(); } } }
private static void SetPosition(ServiceProvider serviceProvider, IPlateau plateau) { var addAnotherRover = true; while (addAnotherRover) { Console.WriteLine("Rover position :"); var roverPositionInput = Console.ReadLine(); Console.WriteLine("Rover order :"); var roverCommandInput = Console.ReadLine(); var rover = serviceProvider.GetService <IRover>(); if (rover.IsRoverDirectionAvailable(roverPositionInput)) { rover.Plateau = plateau; rover.SetOrderDirection(roverCommandInput); plateau.Rovers.Add(rover); } Console.WriteLine("Add an another rover ? (Y)"); var addAnotherRoverInput = Console.ReadLine(); if (addAnotherRoverInput.ToUpper() == "Y") { continue; } addAnotherRover = false; } }
public PlateauGenerator(string PlateauSize) { Regex regex = new Regex(@"(?<width>^[1-65535]+) (?<height>[4-65535]+)$"); Match match = regex.Match(PlateauSize); if (match.Success) { ushort width; ushort height; if (!ushort.TryParse(match.Groups["width"].ToString(), out width)) { throw new PlateauSizeValidationException("Geçerli olmayan genişlik bilgisi"); } if (!ushort.TryParse(match.Groups["height"].ToString(), out height)) { throw new PlateauSizeValidationException("Geçerli olmayan yükseklik bilgisi"); } Plateau = new MarsPlateau(width, height); } else { throw new PlateauSizeValidationException("Tanımlanamayan ölçü girişi"); } }
public void MoveOn(IPlateau marsPlateau) { foreach (var command in _commands) { switch (command) { case Command.R: Direction = RightOf(Direction); break; case Command.L: Direction = LeftOf(Direction); break; case Command.M: var next = MoveTo(); try { marsPlateau.Move(this, next); } finally { Position = next; } break; default: throw new ArgumentOutOfRangeException(nameof(command), command, null); } } }
public void Land(IPlateau plateau, Position position) { #region Validations if (plateau is null) { throw new ValidationException("Plateau is not null"); } if (position is null) { throw new ValidationException("Plateau is not null"); } if (plateau.Width < position.X) { throw new ValidationException("Plateau X dimention is not lass than positon X"); } if (plateau.Heigth < position.Y) { throw new ValidationException("Plateau Y dimention is not lass than positon Y"); } if (position.X < 0) { throw new ValidationException("Position X is not less than 0"); } if (position.Y < 0) { throw new ValidationException("Position Y is not less than 0"); } #endregion Plateau = plateau; Plateau.AddRover(this); Position = position; IsLanded = true; }
private void AjouterAcces(IPlateau plateau, IReaded readed) { var from = FindByName(plateau, readed["from"]); var to = FindByName(plateau, readed["to"]); var acces = fabriqueAcces.CreerAcces(from, to, readed["nom"], readed["type"]); plateau.AjouterAcces(acces); }
public MoteurJeu() { Joueur1 = new Joueur1(); Joueur2 = new Joueur2(); plateau = new Plateau(); resolver = new Resolver(); }
public MoteurJeu(string joueur1, string joueur2) { Joueur1 = new Joueur1(joueur1); Joueur2 = new Joueur2(joueur2); plateau = new Plateau(); resolver = new Resolver(); }
public MoteurJeu(IJoueur joueur1, IJoueur joueur2, IPlateau plateau, IResolver resolver) { Joueur1 = joueur1; Joueur2 = joueur2; this.plateau = plateau; this.resolver = resolver; }
public NewRoverCommand(INasa nasa, IPlateau plateau, Location position, Cardinal cardinal) { _nasa = nasa; _plateau = plateau; this.position = position; this.cardinal = cardinal; }
public PlateauService() { var plateauCommand = Console.ReadLine().Split(" "); var plateau = new Plateau(int.Parse(plateauCommand[0]), 0, int.Parse(plateauCommand[1])); _plateau = plateau; }
public Rover(IPlateau plateau, Point point, string name, Direction direction) { Point = point; Name = name; Direction = direction; Plateau = plateau; }
public Rover(IPlateau plateau, IRouterFactory routerFactory, Position position, string parameters) : this(plateau, routerFactory, position) { foreach (char param in parameters) { switch (param) { case 'L': { SetDirection(Direction.Left); break; } case 'R': { SetDirection(Direction.Right); break; } case 'M': { Move(); break; } default: { throw new ArgumentException("Unexpected parameter", param.ToString()); } } } }
public Result Land(Coordinate coordinate, IPlateau plateau, Direction direction) { var result = new Result(); if (plateau == null) { result.IsSucceeded = false; result.Message = "Plato bilgisi boş geçilemez"; return(result); } if (IsLanded) { result.IsSucceeded = false; result.Message = "İniş daha önce zaten gerçekleştirildi."; return(result); } Plateau = plateau; IsLanded = true; Direction = direction; Coordinate = coordinate; LandedCoordinate = coordinate; LandedDirection = direction; result.IsSucceeded = true; return(result); }
public Rover(IPlateau Plateau, int CoordX, int CoordY, Directions Direction) { this.CoordX = CoordX; this.CoordY = CoordY; this.Direction = Direction; this.Plateau = Plateau; }
private void buttonBrowseFile_Click(object sender, EventArgs e) { try { var file = this.openInputFileDialog.ShowDialog(); // 1. Read file var readFile = FileManager.ReadFile(this.openInputFileDialog.FileName); // TODO: Implement further parsed file validation before parsing. if (readFile.Count < 3 || readFile.Count % 2 == 0) { throw new Exception("InvalidFile - File must have an odd number of lines greater than or equal to 3."); } // 2. Parse Plateu and Rovers var startingX = this.Width / 2; var startingY = this.Height / 2; var gScale = (int)this.graphicsScaleInput.Value; this.plateau = plateauParser.ParsePlateau(readFile, startingX, startingY, gScale, plateauColor); this.rovers = roverParser.ParseRovers(readFile, roverStartingMove, roverSize, startingX, startingY, gScale, roverColor, roverDirectionColor, roverDirectionFont); this.textBoxInputFile.Text = this.openInputFileDialog.FileName; //ResetCanvas(); } catch (Exception ex) { this.errorText.Text = invalidFile; } }
public Rover(int startX, int startY, Direction _direction, IPlateau _plateau) { this.plateauRoverPositionX = startX; this.plateauRoverPositionY = startY; this.Direction = _direction; this.plateau = _plateau; }
static void Main(string[] args) { string inputStr = GenerateInput(); Input input = InputManager.GetInput(inputStr); IKernel kernal = new StandardKernel(); kernal.Load(Assembly.GetExecutingAssembly()); IPlateau plateau = kernal.Get <IPlateau>(); plateau.SetPoint(new Point(input.X, input.Y)); foreach (var inputRover in input.InputRovers) { IRover rover = kernal.Get <Rover>(); rover.SetRover(plateau, new Point(inputRover.X, inputRover.Y), inputRover.CurrentDirection); rover.SetCommandParams(inputRover.Commands); RoverInvoker roverInvorker = new RoverInvoker(rover); roverInvorker.Execute(); //Output Console.WriteLine(rover.ToString()); } Console.ReadKey(); }
private void AjouterPersonnage(IPlateau plateau, IReaded readed) { var personnage = fabriquePersonnage.CreerPersonnage(readed["nom"], readed["type"]); var at = FindByName(plateau, readed["at"]); personnage.Position = at; }
public RoverCommandHandlerTest() { var services = IoCBuilder.ConfigureServices(); var serviceProvider = services.BuildServiceProvider(); plateau = serviceProvider.GetService <IPlateau>(); mediator = serviceProvider.GetService <IMediator>(); }
public void Setup() { var services = ServiceContainerBuilder.ConfigureServices(); var provider = services.BuildServiceProvider(); _plateau = provider.GetService <IPlateau>(); _rover = provider.GetService <IRover>(); }
public MarsRover(IPlateau marsPlateau, int x, int y, Direction dir, String instSet) { mars_Plateau = marsPlateau; InstructionSet = instSet; this.Dir = dir; CurrentLocation = new Cell(x, y); IsValid = true; }
protected override void SetUp() { _direction = Substitute.For <Direction>(); _plateau = Substitute.For <Plateau>(); _location = new Location(_plateau); _rover = new Rover(_location, _direction); base.SetUp(); }
public CommandInitializer(IPlateau _plateau, IRoverManager _roverManager, ICommandParser aCommandParser, ICommandInvoker aCommandInvoker) { plateau = _plateau; commandParser = aCommandParser; commandInvoker = aCommandInvoker; commandInvoker.SetPlateau(plateau); commandInvoker.SetRoverManager(_roverManager); }
public PlateauTest() { var services = IoCBuilder.ConfigureServices(); var serviceProvider = services.BuildServiceProvider(); plateau = serviceProvider.GetService <IPlateau>(); rover = serviceProvider.GetService <IRover>(); }
private void AjouterAcces(IPlateau plateau, IReaded readed) { var from = FindByName(plateau, readed["from"]); var to = FindByName(plateau, readed["to"]); var acces = fabriqueAcces.CreerAcces(from, to, readed["nom"], readed["type"]); plateau.AjouterAcces(acces); }
public void Constructor_Should_Successfully_Initialized() { //arrange _plateau = new Plateau(5, 5); //act //assert Assert.NotNull(_plateau); }
/// <summary> /// Creates rover object and run instructions /// </summary> /// <param name="rovers">Rovers</param> /// <param name="plateau">Plateau</param> /// <param name="stringReader">StringReader for input</param> /// <returns>Is rover created</returns> private static bool CreateRover(IList <Rover> rovers, IPlateau plateau, StringReader stringReader) { string roverPositionLine = stringReader.ReadLine(); if (roverPositionLine == null) { return(false); } string[] roverPositions = roverPositionLine.Split(' '); if (roverPositions.Length != 3) { throw new InvalidInputException("Rover position is not a valid input."); } int roverPositionX = int.Parse(roverPositions[0]); int roverPositionY = int.Parse(roverPositions[1]); CardinalDirection roverDirection = roverPositions[2].ToCardinalDirection(); Rover rover = new Rover(plateau, roverPositionX, roverPositionY, roverDirection); string roverCommandsLine = stringReader.ReadLine(); if (roverCommandsLine == null) { throw new InvalidInputException("Rover commands is not a valid input."); } foreach (Instruction command in roverCommandsLine) { switch (command) { case Instruction.Left: rover.Spin(SpinDirection.Left); break; case Instruction.Right: rover.Spin(SpinDirection.Right); break; case Instruction.Move: rover.Move(); break; default: throw new InvalidInputException("Rover commands is not a valid input."); } } if (!rover.IsInsidePlateau()) { throw new LandingException($"Rover cannot be landed to X={rover.Position.X}, Y={rover.Position.Y} coordinates."); } rovers.Add(rover); return(true); }
public void DriveRover(IPlateau plateau, IEnumerable <Movement> movements, IList <Point> otherRoverPoints) { _plateau = plateau; _otherRoverPoints = otherRoverPoints; foreach (var movement in movements) { _movementMethodDictionary[movement].Invoke(); } }
public void CreateRover(IPlateau plateau, Point point, Direction direction) { plateau.CheckPosition(point); Position = point; Direction = direction; _wing = _wingList.FirstOrDefault(x => x.Direction == direction); _isCreate = true; }
public override void Given() { this.StubbedRover = stub_a<IRover>(); this.StubbedPlateau = stub_a<IPlateau>(); this.StubbedInstruction = stub_a<IInstruction>(); this.StubbedPositionChecks = stub_a<List<IPositionCheck>>(); this.PlateauController = new PlateauController(this.StubbedPlateau); this.PlateauController.PositionChecks = this.StubbedPositionChecks; this.StubbedRover.Instruction = this.StubbedInstruction; }
internal static IEnumerable<string> GetOutputLines(IPlateau plateau, IEnumerable<IRover> rovers) { var output = new List<string>(); foreach (var rover in rovers) { output.Add(string.Format("{0} {1} {2}{3}", rover.Easting.ToString(CultureInfo.InvariantCulture), rover.Northing.ToString(CultureInfo.InvariantCulture), rover.Heading.ToString().Substring(0, 1), plateau.IsRoverWithinLimits(rover) ? string.Empty : AppConstants.BeyondLimits)); } return output; }
public MarsRover(IPosition roverPosition, IPlateau roverPlateau, RoverState currentState) { if (roverPlateau == null) { throw new ArgumentNullException("roverPlateau", "Rover Plateau is a required parameter and it cannot be null"); } if (currentState == null) { throw new ArgumentNullException("currentState", "Current State is a required parameter and it cannot be null"); } _roverPlateau = roverPlateau; if(!_roverPlateau.ValidCoordinate(Coordinate.CreateNew(roverPosition.Xaxis,roverPosition.Yaxis))) { throw new ArgumentOutOfRangeException("roverPosition", "Rover coordinates are out of the range"); } if (roverPosition.Direction == Enum_Direction.Direction_Error) { throw new ArgumentException("roverPosition", "Rover is set to error direction"); } _roverPosition = roverPosition; _currentState = currentState; }
private static IZone FindByName(IPlateau plateau, string name) => plateau.GetZone(name);
private static bool IsXInValid(IRover rover, IPlateau plateau) { return rover.X < 0 || rover.X > plateau.Width; }
public MarsRoverController(IPlateau plateau) { if (plateau == null) throw new ArgumentNullException("plateau", "Plateau is a required parameter and it cannot be null"); _plateau = plateau; }
public PlateauController(IPlateau plateau) { this._plateau = plateau; }
private static bool IsYInValid(IRover rover, IPlateau plateau) { return rover.Y < 0 || rover.Y > plateau.Height; }
private void AjouterPersonnage(IPlateau plateau, IReaded readed) { var personnage = fabriquePersonnage.CreerPersonnage(readed["nom"], readed["type"]); var at = FindByName(plateau, readed["at"]); personnage.Position = at; }
private void AjouterZone(IPlateau plateau, IReaded readed) { plateau.AjouterZone(fabriqueZone.CreerZone(readed.arguments)); }
public override void Given() { this.Plateau = stub_a<IPlateau>(); this.Plateau.Width = 5; this.Plateau.Height = 5; }