public bool TryCreateEntity(int column, int row, bool isPartOfDrag, [NotNullWhen(returnValue: true)] out Track?entity) { if (_terrainMap.Get(column, row).IsWater) { entity = null; return(false); } entity = new Track(); return(true); }
public IEnumerable <Track> GetPossibleReplacements(int column, int row, Track track) { if (!_terrainMap.Get(column, row).IsWater) { yield break; } yield return(new Bridge() { Direction = TrackDirection.Horizontal }); var neighbours = track.GetAllNeighbors(); if (neighbours.Up is not null || neighbours.Down is not null) { yield return(new Bridge() { Direction = TrackDirection.Vertical }); } if (neighbours.Up is not null && neighbours.Left is not null) { yield return(new Bridge() { Direction = TrackDirection.LeftUp }); } if (neighbours.Up is not null && neighbours.Right is not null) { yield return(new Bridge() { Direction = TrackDirection.RightUp }); } if (neighbours.Down is not null && neighbours.Left is not null) { yield return(new Bridge() { Direction = TrackDirection.LeftDown }); } if (neighbours.Down is not null && neighbours.Right is not null) { yield return(new Bridge() { Direction = TrackDirection.RightDown }); } }
public void Render(ICanvas canvas, int width, int height, IPixelMapper pixelMapper) { var tunnelRoofColour = BuildModeAwareColour(Colors.LightGray); var firstMountain = new Terrain() { Height = Terrain.FirstMountainHeight }; var tunnelBaseColour = BuildModeAwareColour(TerrainMapRenderer.GetTerrainColour(firstMountain)); var entranceColourArray = new[] { tunnelBaseColour, tunnelRoofColour, tunnelBaseColour }; Dictionary <(int column, int row), Tunnel> entrances = new(); foreach (Track track in _trackLayout) { var terrain = _terrainMap.Get(track.Column, track.Row); if (!terrain.IsMountain) { continue; } (int x, int y, _) = pixelMapper.CoordsToViewPortPixels(track.Column, track.Row); // Paint over the tracks with the colour of the terrain. Would be awesome to remove this in future somehow var terrainColour = BuildModeAwareColour(TerrainMapRenderer.GetTerrainColour(terrain)); canvas.DrawRect(x, y, pixelMapper.CellSize, pixelMapper.CellSize, new PaintBrush { Style = PaintStyle.Fill, Color = terrainColour, }); TrackNeighbors trackNeighbours = track.GetConnectedNeighbors(); BuildEntrances(trackNeighbours.Up, Tunnel.Bottom, entrances); BuildEntrances(trackNeighbours.Right, Tunnel.Left, entrances); BuildEntrances(trackNeighbours.Down, Tunnel.Top, entrances); BuildEntrances(trackNeighbours.Left, Tunnel.Right, entrances); var currentCellTunnels = (IsEntrance(trackNeighbours.Up) ? Tunnel.Top : Tunnel.NoTunnels) | (IsEntrance(trackNeighbours.Right) ? Tunnel.Right : Tunnel.NoTunnels) | (IsEntrance(trackNeighbours.Down) ? Tunnel.Bottom : Tunnel.NoTunnels) | (IsEntrance(trackNeighbours.Left) ? Tunnel.Left : Tunnel.NoTunnels); DrawTunnel(canvas, pixelMapper, tunnelRoofColour, tunnelBaseColour, x, y, currentCellTunnels); } foreach (var(col, row, tunnels) in entrances) { DrawEntrance(canvas, pixelMapper, entranceColourArray, col, row, tunnels); } }
public IEnumerable <Track> GetPossibleReplacements(int column, int row, Track track) { if (_terrainMap.Get(column, row).IsWater) { yield break; } var neighbours = track.GetAllNeighbors(); if (neighbours.Count == 4) { yield return(new CrossTrack()); } }
public bool TryCreateEntity(int column, int row, [NotNullWhen(returnValue: true)] out Track?entity) { if (!_terrainMap.Get(column, row).IsWater&& _layout.TryGet(column, row, out Track? track) && ( track is Signal || track.Direction is TrackDirection.Horizontal or TrackDirection.Vertical && track.Happy) ) { entity = new Signal(); return(true); } entity = null; return(false); }
public IEnumerable <Track> GetPossibleReplacements(int column, int row, Track track) { if (!_terrainMap.Get(column, row).IsWater) { var neighbours = track.GetAllNeighbors(); if (neighbours.Left is not null || neighbours.Right is not null) { yield return(new Signal() { Direction = TrackDirection.Horizontal, SignalState = SignalState.Go }); yield return(new Signal() { Direction = TrackDirection.Horizontal, SignalState = SignalState.TemporaryStop }); yield return(new Signal() { Direction = TrackDirection.Horizontal, SignalState = SignalState.Stop }); } if (neighbours.Up is not null || neighbours.Down is not null) { yield return(new Signal() { Direction = TrackDirection.Vertical, SignalState = SignalState.Go }); yield return(new Signal() { Direction = TrackDirection.Vertical, SignalState = SignalState.TemporaryStop }); yield return(new Signal() { Direction = TrackDirection.Vertical, SignalState = SignalState.Stop }); } } }
public bool IsValid(int column, int row) => _entityCollection.IsAvailable(column, row) && _terrainMap.Get(column, row).IsLand;
public IEnumerable <Track> GetPossibleReplacements(int column, int row, Track track) { if (_terrainMap.Get(column, row).IsWater) { yield break; } var neighbours = track.GetAllNeighbors(); if (neighbours.Count < 3) { yield break; } if (AreAllPresent(neighbours.Up, neighbours.Left, neighbours.Right)) { yield return(new Track() { Direction = TrackDirection.LeftUp_RightUp }); yield return(new Track() { Direction = TrackDirection.LeftUp_RightUp, AlternateState = true }); } if (AreAllPresent(neighbours.Up, neighbours.Left, neighbours.Down)) { yield return(new Track() { Direction = TrackDirection.LeftDown_LeftUp }); yield return(new Track() { Direction = TrackDirection.LeftDown_LeftUp, AlternateState = true }); } if (AreAllPresent(neighbours.Up, neighbours.Right, neighbours.Down)) { yield return(new Track() { Direction = TrackDirection.RightUp_RightDown }); yield return(new Track() { Direction = TrackDirection.RightUp_RightDown, AlternateState = true }); } if (AreAllPresent(neighbours.Down, neighbours.Left, neighbours.Right)) { yield return(new Track() { Direction = TrackDirection.RightDown_LeftDown }); yield return(new Track() { Direction = TrackDirection.RightDown_LeftDown, AlternateState = true }); } }