public void GivenNpcAndEmptyFieldUnderNpc_WhenMoveNpcDown_ThenMovesNpcDownInTheMap() { //Arrange _testMap[2, 1] = new MapElementContainer(2, 1, new EmptyField()); // Act _npcToDownMover.MoveNpcDown(_testNpc); // Assert Check.That(_testMap[1, 1].MapElement).IsInstanceOf <EmptyField>(); Check.That(_testMap[2, 1].MapElement).IsInstanceOf <NonPlayableCharacter>(); }
public void GivenNpcAndFlameUnderNpc_WhenMoveNpcDown_ThenNpcCantMoveDownAndSwitchesDirection() { //Arrange _testMap[2, 1] = new MapElementContainer(2, 1, new EmptyField(), new Flame(2, 0, new PlayerDto())); // Act _npcToDownMover.MoveNpcDown(_testNpc); // Assert Check.That(_testMap[1, 1].MapElement).IsInstanceOf <NonPlayableCharacter>(); Check.That(_testMap[2, 1].BlowingElement).IsInstanceOf <Flame>(); Check.That(_testNpc.IsAlive).IsEqualTo(false); }
public void GivenNpcAndWallUnderNpc_WhenMoveNpcDown_ThenNpcCantMoveDownAndSwitchesDirection() { //Arrange _testMap[2, 1] = new MapElementContainer(2, 1, new BreakableWall()); // Act _npcToDownMover.MoveNpcDown(_testNpc); // Assert Check.That(_testMap[1, 1].MapElement).IsInstanceOf <NonPlayableCharacter>(); Check.That(_testMap[2, 1].MapElement).IsInstanceOf <BreakableWall>(); Check.That(_testNpc.MoveDirection).IsEqualTo(MoveDirection.Up); }
public void GivenActualPlayerAndNoEmptyFieldLefter_WhenMoveLeft_ThenPlayerCantMoveLeft() { // Arrange _testMap[1, 0] = new MapElementContainer(1, 0, new BreakableWall()); // Act _gameLogic.MoveLeft(_testPlayer); // Assert Check.That(_testMap[1, 1].MapElement).IsInstanceOf <PlayerDto>(); Check.That(_testMap[1, 1].X).IsEqualTo(1); Check.That(_testMap[1, 1].Y).IsEqualTo(1); }
public void GivenNpcAndWallToLeftOfNpc_WhenMoveNpcLeft_ThenNpcCantMoveDownAndSwitchesDirection() { //Arrange _testMap[1, 0] = new MapElementContainer(1, 0, new BreakableWall()); // Act _npcToLeftMover.MoveNpcLeft(_testNpc); // Assert Check.That(_testMap[1, 1].MapElement).IsInstanceOf <NonPlayableCharacter>(); Check.That(_testMap[1, 0].MapElement).IsInstanceOf <BreakableWall>(); Check.That(_testNpc.MoveDirection).IsEqualTo(MoveDirection.Right); }
public void GivenActualPlayer_WhenMoveRight_ThenModifiesTheGivenMapStatus() { // Arrange _testMap[1, 2] = new MapElementContainer(1, 2, new EmptyField()); // Act _gameLogic.MoveRight(_testPlayer); // Assert Check.That(_testMap[1, 2].MapElement).IsInstanceOf <PlayerDto>(); Check.That(_testMap[1, 2].X).IsEqualTo(1); Check.That(_testMap[1, 2].Y).IsEqualTo(2); Check.That(_testMap[1, 1].MapElement).IsInstanceOf <EmptyField>(); Check.That(_testMap[1, 1].X).IsEqualTo(1); Check.That(_testMap[1, 1].Y).IsEqualTo(1); }
public static MapElementContainer[,] GenerateMap(IMapElement mapElement = null) { var testMap = new MapElementContainer[3, 3]; testMap[0, 0] = new MapElementContainer(0, 0, new NonBreakableWall()); testMap[0, 1] = new MapElementContainer(0, 1, new BreakableWall()); testMap[0, 2] = new MapElementContainer(0, 2, new NonBreakableWall()); testMap[1, 0] = new MapElementContainer(1, 0, new BreakableWall()); testMap[1, 1] = new MapElementContainer(1, 1, mapElement ?? new EmptyField()); testMap[1, 2] = new MapElementContainer(1, 2, new BreakableWall()); testMap[2, 0] = new MapElementContainer(2, 0, new NonBreakableWall()); testMap[2, 1] = new MapElementContainer(2, 1, new BreakableWall()); testMap[2, 2] = new MapElementContainer(2, 2, new NonBreakableWall()); return(testMap); }
public void Setup() { _testPlayer = new PlayerDto() { Name = "Jani", EntityType = EntityType.PlayerOne }; _testMap = new MapElementContainer[3, 3]; _testMap[0, 0] = new MapElementContainer(0, 0, new NonBreakableWall()); _testMap[0, 1] = new MapElementContainer(0, 1, new BreakableWall()); _testMap[0, 2] = new MapElementContainer(0, 2, new NonBreakableWall()); _testMap[1, 0] = new MapElementContainer(1, 0, _testPlayer); _testMap[1, 1] = new MapElementContainer(1, 1, new EmptyField()); _testMap[1, 2] = new MapElementContainer(1, 2, new BreakableWall()); _testMap[2, 0] = new MapElementContainer(2, 0, new NonBreakableWall()); _testMap[2, 1] = new MapElementContainer(2, 1, new BreakableWall()); _testMap[2, 2] = new MapElementContainer(2, 2, new NonBreakableWall()); // _gameSaver = new GameSaver(new ElementToTypeConverter()); }
public MapElementContainer[,] BuildMapFromXml(XDocument mapXml) { var map = new MapElementContainer[_xmlElementFinder.GetWidth(mapXml) + 1, _xmlElementFinder.GetHigh(mapXml) + 1]; for (var widthIndex = 0; widthIndex < map.GetLength(0); widthIndex++) { for (var heightIndex = 0; heightIndex < map.GetLength(1); heightIndex++) { var widthIndexToAsync = widthIndex; var heightIndexToAsync = heightIndex; Task.WaitAll(Task.Run(async() => { var foundedEntityType = await _xmlElementFinder.GetEntityTypesByCoordinatesAsync(mapXml, widthIndexToAsync, heightIndexToAsync); var entityTypeInstance = _mapElementFactory.CreateMapElement(foundedEntityType); map[widthIndexToAsync, heightIndexToAsync] = new MapElementContainer(widthIndexToAsync, heightIndexToAsync, entityTypeInstance); })); } } return(map); }
private ISet <MapElementContainer> ProcessLabels(RenderContext renderContext) { // if we are drawing the labels per tile, we need to establish which tile-overlapping // elements need to be drawn. ISet <MapElementContainer> labelsToDraw = new HashSet <MapElementContainer>(); lock (tileDependencies) { // first we need to get the labels from the adjacent tiles if they have already been drawn // as those overlapping items must also be drawn on the current tile. They must be drawn regardless // of priority clashes as a part of them has alread been drawn. ISet <Tile> neighbours = renderContext.rendererJob.tile.Neighbours; ISet <MapElementContainer> undrawableElements = new HashSet <MapElementContainer>(); tileDependencies.AddTileInProgress(renderContext.rendererJob.tile); for (var i = neighbours.Count - 1; i >= 0; i--) { Tile neighbour = neighbours.ElementAt(i); if (tileDependencies.IsTileInProgress(neighbour) || tileCache.ContainsKey(renderContext.rendererJob.OtherTile(neighbour))) { // if a tile has already been drawn, the elements drawn that overlap onto the // current tile should be in the tile dependencies, we add them to the labels that // need to be drawn onto this tile. For the multi-threaded renderer we also need to take // those tiles into account that are not yet in the TileCache: this is taken care of by the // set of tilesInProgress inside the TileDependencies. labelsToDraw.UnionWith(tileDependencies.GetOverlappingElements(neighbour, renderContext.rendererJob.tile)); // but we need to remove the labels for this tile that overlap onto a tile that has been drawn foreach (MapElementContainer current in renderContext.labels) { if (current.Intersects(neighbour.BoundaryAbsolute)) { undrawableElements.Add(current); } } // since we already have the data from that tile, we do not need to get the data for // it, so remove it from the neighbours list. neighbours.Remove(neighbour); } else { tileDependencies.RemoveTileData(neighbour); } } // now we remove the elements that overlap onto a drawn tile from the list of labels // for this tile foreach (var element in undrawableElements) { renderContext.labels.Remove(element); } // at this point we have two lists: one is the list of labels that must be drawn because // they already overlap from other tiles. The second one is currentLabels that contains // the elements on this tile that do not overlap onto a drawn tile. Now we sort this list and // remove those elements that clash in this list already. ICollection <MapElementContainer> currentElementsOrdered = LayerUtil.CollisionFreeOrdered(renderContext.labels); // now we go through this list, ordered by priority, to see which can be drawn without clashing. IEnumerator <MapElementContainer> currentMapElementsIterator = currentElementsOrdered.GetEnumerator(); while (currentMapElementsIterator.MoveNext()) { MapElementContainer current = currentMapElementsIterator.Current; foreach (MapElementContainer label in labelsToDraw) { if (label.ClashesWith(current)) { break; } } } labelsToDraw.UnionWith(currentElementsOrdered); // update dependencies, add to the dependencies list all the elements that overlap to the // neighbouring tiles, first clearing out the cache for this relation. foreach (Tile tile in neighbours) { tileDependencies.RemoveTileData(renderContext.rendererJob.tile, tile); foreach (MapElementContainer element in labelsToDraw) { if (element.Intersects(tile.BoundaryAbsolute)) { tileDependencies.AddOverlappingElement(renderContext.rendererJob.tile, tile, element); } } } } return(labelsToDraw); }
public MapElementContainer[,] GetMapFromMapElements(IEnumerable <MapElementDto> mapElements, IEnumerable <PlayerDto> players) { var map = new MapElementContainer[GetWidthFromMapElements(mapElements) + 1, GetHeightFromMapElements(mapElements) + 1]; return(null); }