コード例 #1
0
ファイル: MapService.cs プロジェクト: ansem571/MyPetProjects
        public void UpdateMap(ITileBase tile, int floor)
        {
            if (!_dungeonMap.TryGetValue(floor, out var mapFloor)) // floor does not exist in dungeon map
            {
                return;
            }
            if (!mapFloor.Map.TryGetValue(tile.GetTileLocation(), out var oldTile)) // tile does not exist in floor map
            {
                return;
            }
            if (oldTile.GetType() == tile.GetType())
            {
                switch (tile)
                {
                case BasicTile b:
                {
                    b.SetVisited(true);
                    var nearbyTiles = b.GetNearbyTiles().ToList();
                    foreach (DungeonBaseTile nearbyTile in nearbyTiles)
                    {
                        nearbyTile.SetVisible(true);
                    }
                    b.SetupNearbyTiles(nearbyTiles);
                    tile = b;
                }
                break;

                case StairTile stair:
                {
                    stair.SetVisited(true);
                    var nearbyTiles = stair.GetNearbyTiles().ToList();
                    foreach (DungeonBaseTile nearbyTile in nearbyTiles)
                    {
                        nearbyTile.SetVisible(true);
                    }
                    stair.SetupNearbyTiles(nearbyTiles);
                    tile = stair;
                }
                break;

                case DungeonBaseTile d:
                case ITileBase t:
                {
                    throw new InvalidCastException($"Tile {nameof(tile)} was not set to an appropriate type. {tile.GetType()}");
                }

                default:
                {
                    throw new ArgumentOutOfRangeException($"Tile {nameof(tile)} case was not defined for {tile.GetType()}");
                }
                }
                oldTile = tile;
            }
        }
コード例 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="tileLocation">x,y location</param>
 /// <param name="floor">Floor you go to when moved onto</param>
 /// <param name="nextFloorTile"></param>
 public StairTile(Vector2d tileLocation, int floor, ITileBase nextFloorTile) : base(tileLocation)
 {
     _nextFloorValue = floor;
     _nextFloorTile  = nextFloorTile;
 }