public void Process_PainterDrawMapIsCalledWithCorrectMapImage() { var parameters = new DungeonParameters(); var dungeon = new FakeDungeon(5, 4); var mapBuilder = Substitute.For<IMapBuilder>(); mapBuilder.Build(parameters).Returns(dungeon); var populator = Substitute.For<IDungeonPopulator>(); var character = new Character { Location = new Point(1, 1) }; populator.WhenForAnyArgs(it => it.Fill(Arg.Any<IGameDungeon>())) .Do(d => { d.Arg<IGameDungeon>().Character = character; }); var painter = Substitute.For<IMapPainter>(); var processor = new Processor( mapBuilder, populator, painter); processor.Initialize(parameters); processor.Process(GameAction.None); painter.Received(1).DrawMap(Arg.Is<MapImage>(d => d.Width == dungeon.Width && d.Height == dungeon.Height && d[1, 1].Type == XType.Character)); }
protected override void ExecuteCommand(IMap map, DungeonParameters parameters) { var sparseFactor = parameters.CellSparseFactor; var expectedNumberOfRemovedCells = (int)Math.Ceiling(map.Size * (sparseFactor / 100m)) - 1; var removedCellsCount = 0; var nonWalls = map.Where(c => !c.IsWall).ToList(); if (!nonWalls.Any()) { throw new InvalidOperationException("All cells are walls."); } while (removedCellsCount < expectedNumberOfRemovedCells) { foreach (var cell in nonWalls.Where(c => c.IsDeadEnd).ToList()) { if (!cell.IsDeadEnd) continue; var emptySide = cell.Sides .Single(s => s.Value != Side.Wall) .Key; map.CreateWall(cell, emptySide); cell.IsCorridor = false; nonWalls.Remove(cell); removedCellsCount++; } } }
public void Execute_ShouldThrow_IfMapNull() { Map map = null; DungeonParameters parameters = new DungeonParameters(); var command = new FakeMapBuilderCommand(); Assert.That(() => command.Execute(map, parameters), Throws.ArgumentNullException); }
public void Execute(IMap map, DungeonParameters parameters) { Throw.IfNull(map, nameof(map)); Throw.IfNull(parameters, nameof(parameters)); Throw.IfNull(parameters.RoomParameters, nameof(parameters.RoomParameters)); ValidateParameters(parameters); ExecuteCommand(map, parameters); }
public void Initialize(DungeonParameters parameters) { var dungeonMap = builder.Build(parameters); var dungeon = Convert(dungeonMap); populator.Fill(dungeon); Dungeon = dungeon; Log.Debug("Dungeon initialized."); }
protected override void ExecuteCommand( IMap map, DungeonParameters parameters) { var rooms = CreateRooms(parameters.RoomParameters); foreach (var room in rooms) { PlaceRoom(map, room); } }
public void Execute_ShouldCallValidateParameters() { var map = new Map(3, 4); DungeonParameters parameters = new DungeonParameters(); var command = new FakeMapBuilderCommand(); command.Execute(map, parameters); Assert.That(command.ValidateParametersCalls, Is.EqualTo(1)); }
public void Execute_SetsAllCells_ToVisited() { var map = new Map(2, 3); var parameters = new DungeonParameters(); var command = new CorridorBuilderCommand(new DirectionPicker(50)); command.Execute(map, parameters); Assert.That(map, Has.All.With.Property(nameof(MapCell.IsVisited)).True); }
protected override void ExecuteCommand(IMap map, DungeonParameters parameters) { var _sparseFactor = parameters.DeadEndSparseFactor; foreach (var cell in map) { if (cell.IsDeadEnd && _sparseFactor > StaticRandom.Next(0, 100)) { BuildCorridor(map, cell); } } }
public void Execute_ShouldThrow_IfMapContainsVisitedCell(int x, int y) { var map = new Map(2, 3); var parameters = new DungeonParameters(); var command = new CorridorBuilderCommand(new DirectionPicker(50)); map.Visit(map[x, y]); Assert.That(() => command.Execute(map, parameters), Throws.InvalidOperationException); }
public void Execute_ShouldThrow_IfTwistFactorIsInvalid(int factor) { var map = new Map(2, 3); var parameters = new DungeonParameters { TwistFactor = factor }; var command = new CorridorBuilderCommand(new DirectionPicker(50)); Assert.That(() => command.Execute(map, parameters), Throws.InstanceOf<ArgumentOutOfRangeException>()); }
public void Execute_ShouldThrow_IfRoomParametersNull() { var map = new Map(3, 4); DungeonParameters parameters = new DungeonParameters { RoomParameters = null }; var command = new FakeMapBuilderCommand(); Assert.That(() => command.Execute(map, parameters), Throws.ArgumentNullException); }
public void Initialize_BuilderIsCalled() { var parameters = new DungeonParameters(); var mapBuilder = Substitute.For<IMapBuilder>(); var processor = new Processor( mapBuilder, Substitute.For<IDungeonPopulator>(), Substitute.For<IMapPainter>()); processor.Initialize(parameters); mapBuilder.Received(1).Build(parameters); }
public IDungeon Build(DungeonParameters parameters) { Throw.IfNull(parameters, nameof(parameters)); Throw.IfLess(1, parameters.Width, nameof(parameters.Width)); Throw.IfLess(1, parameters.Height, nameof(parameters.Height)); var map = new Map(parameters.Width, parameters.Height); foreach (var command in commands) { command.Execute(map, parameters); } return converter.ConvertToDungeon(map); }
public void Initialize_PopulatorIsCalled() { var parameters = new DungeonParameters(); var dungeon = new FakeDungeon(); var mapBuilder = Substitute.For<IMapBuilder>(); mapBuilder.Build(parameters).Returns(dungeon); var populator = Substitute.For<IDungeonPopulator>(); var processor = new Processor( mapBuilder, populator, Substitute.For<IMapPainter>()); processor.Initialize(parameters); populator.Received(1).Fill( Arg.Is<IGameDungeon>(d => d.Size == dungeon.Size)); }
public void Constructor_ValidateParameters_Throws_IfMaxHeightLessMin( int min, int max) { var map = new Map(5, 5); var parameters = new DungeonParameters { RoomParameters = { MinHeight = min, MaxHeight = max } }; Assert.That(() => _command.Execute(map, parameters), Throws.InstanceOf<ArgumentOutOfRangeException>() .With.Property(nameof(ArgumentOutOfRangeException.ParamName)) .EqualTo(nameof(RoomParameters.MaxHeight))); }
public void Constructor_ValidateParameters_Succeeds_IfParametersOK() { var map = new Map(5, 5); var parameters = new DungeonParameters { CellSparseFactor = 50, DeadEndSparseFactor = 60, TwistFactor = 45, Height = 11, Width = 15, RoomParameters = { Count = 2, MaxHeight = 5, MaxWidth = 5, MinHeight = 5, MinWidth = 4 } }; Assert.That(() => _command.Execute(map, parameters), Throws.Nothing); }
protected override void ValidateParameters(DungeonParameters parameters) { var roomParameters = parameters.RoomParameters; Throw.IfNull(roomParameters, nameof(roomParameters)); Throw.IfLess(0, roomParameters.Count, nameof(roomParameters.Count)); Throw.IfLess(0, roomParameters.MinWidth, nameof(roomParameters.MinWidth)); Throw.IfLess(0, roomParameters.MinHeight, nameof(roomParameters.MinHeight)); Throw.IfLess(roomParameters.MinWidth, roomParameters.MaxWidth, nameof(roomParameters.MaxWidth)); Throw.IfLess(roomParameters.MinHeight, roomParameters.MaxHeight, nameof(roomParameters.MaxHeight)); Throw.IfGreater(parameters.Width, roomParameters.MaxWidth, nameof(roomParameters.MaxWidth)); Throw.IfGreater(parameters.Height, roomParameters.MaxHeight, nameof(roomParameters.MaxHeight)); }
protected override void ExecuteCommand(IMap map, DungeonParameters parameters) { BuildCorridors(map); }
protected abstract void ExecuteCommand(IMap map, DungeonParameters parameters);
public void Constructor_ValidateParameters_Throws_IfMaxWidthGreaterThanWidth( int maxW, int w) { var map = new Map(5, 5); var parameters = new DungeonParameters { Width = w, RoomParameters = { MaxWidth = maxW } }; Assert.That(() => _command.Execute(map, parameters), Throws.InstanceOf<ArgumentOutOfRangeException>() .With.Property(nameof(ArgumentOutOfRangeException.ParamName)) .EqualTo(nameof(RoomParameters.MaxWidth))); }
public void SetUp() { _map = new Map(15, 20); _parameters = new DungeonParameters { CellSparseFactor = 50, DeadEndSparseFactor = 60, TwistFactor = 45, Height = 20, Width = 15, RoomParameters = { Count = 2, MaxHeight = 5, MaxWidth = 5, MinHeight = 5, MinWidth = 4 } }; _command = new PlaceRoomsCommand(); var corridorBuilderCommand = new CorridorBuilderCommand( new DirectionPicker(_parameters.TwistFactor)); corridorBuilderCommand.Execute(_map, _parameters); }
public void Constructor_ValidateParameters_Throws_IfRoomCountNegative(int count) { var map = new Map(5, 5); var parameters = new DungeonParameters { RoomParameters = { Count = count } }; Assert.That(() => _command.Execute(map, parameters), Throws.InstanceOf<ArgumentOutOfRangeException>() .With.Property(nameof(ArgumentOutOfRangeException.ParamName)) .EqualTo(nameof(RoomParameters.Count))); }
protected abstract void ValidateParameters(DungeonParameters parameters);
public void Constructor_RoomParameters_AreNotNull() { var parameters = new DungeonParameters(); Assert.That(parameters.RoomParameters, Is.Not.Null); }
public void Process_PainterDrawMessageIsCalled() { var parameters = new DungeonParameters(); var dungeon = new FakeDungeon(5, 4); var mapBuilder = Substitute.For<IMapBuilder>(); mapBuilder.Build(parameters).Returns(dungeon); var populator = Substitute.For<IDungeonPopulator>(); var character = new Character { Location = new Point(1, 1) }; populator.WhenForAnyArgs(it => it.Fill(Arg.Any<IGameDungeon>())) .Do(d => { d.Arg<IGameDungeon>().Character = character; }); var painter = Substitute.For<IMapPainter>(); var processor = new Processor( mapBuilder, populator, painter); processor.Initialize(parameters); processor.Process(GameAction.None); ////TODO test precise message painter.Received(1).DrawMessage(Arg.Any<GameMessage>()); }
protected override void ValidateParameters(DungeonParameters parameters) { Throw.IfNotInRange(0, 100, parameters.DeadEndSparseFactor, nameof(parameters.DeadEndSparseFactor)); }
public void SetUp() { _params = new DungeonParameters { Width = 10, Height = 10, RoomParameters = new RoomParameters() }; _builder = new MapBuilder(new List<IMapBuilderCommand>(), Substitute.For<IMapConverter>()); }
public void SetUp() { _map = new Map(12, 16); _parameters = new DungeonParameters { TwistFactor = 50, DeadEndSparseFactor = 50 }; _command = new SparsifyDeadEndsCommand(new DirectionPicker(0)); }
public void SetUp() { _map = new Map(8, 6); _parameters = new DungeonParameters { TwistFactor = 50, CellSparseFactor = 50 }; _command = new SparsifyCellsCommand(); }