Exemple #1
0
    /// <summary>
    /// Returns a <see cref="System.String"/> that represents the current <see cref="DungeonData"/>.
    /// </summary>
    /// <returns>
    /// A <see cref="System.String"/> that represents the current <see cref="DungeonData"/>.
    /// </returns>
    public override string ToString()
    {
        string ret = "";

        ret += "Dungeon " + width + "x" + height + ". Entrance in " + entranceX + ":" + entranceY + "\n";

        ret += "\nRooms: ";
        for (int i = 0; i < rooms.Count; i++)
        {
            ret += ("Room" + i + " (" + Rooms [i].x + "," + Rooms [i].y + "," + Rooms [i].width + "," + Rooms [i].height + "), ");
        }

        ret += "\n\nRoads: ";
        for (int i = 0; i < rooms.Count; i++)
        {
            ret += ("Road" + i + " (" + Roads [i].x1 + "," + Roads [i].y1 + "," + Roads [i].x2 + "," + Roads [i].y2 + "), ");
        }

        ret += "\n\nMap:\n";


        string[,] tiles = new string[width, height];
        foreach (KeyValuePair <int, DungeonDataTile> kvp in Tiles)
        {
            int             code = kvp.Key;
            DungeonDataTile tile = kvp.Value;

            int i, j;
            DungeonUtils.GetIndexesOfTileByCode(code, out i, out j);
            if (tile.room != null)
            {
                tiles [i, j] = "0 ";
            }
            else if (tile.road != null)
            {
                tiles [i, j] = "X ";
            }
            else
            {
                tiles [i, j] = "- ";
            }
        }

        for (int j = 0; j < height; j++)
        {
            for (int i = 0; i < width; i++)
            {
                ret += tiles [i, j];
            }
            ret += "\n";
        }

        return(ret);
    }
Exemple #2
0
    /// <summary>
    /// Prepares tile objects such as a walls, passages, floors and ceilings.
    /// </summary>
    /// <param name='dungeon'>
    /// Dungeon.
    /// </param>
    public static void PrepareBaseGeometry(DungeonData dungeon)
    {
        Dictionary <int, DungeonDataTile> tiles = dungeon.Tiles;

        // For every tile in map
        foreach (KeyValuePair <int, DungeonDataTile> kvp in tiles)
        {
            int             code = kvp.Key;
            DungeonDataTile tile = kvp.Value;

            int i, j;
            DungeonUtils.GetIndexesOfTileByCode(code, out i, out j);

            // If current tile is a room..
            if (tiles [code].room != null)
            {
                // Set floor
                DungeonObject floor = new DungeonObject(code, DungeonObjectType.Floor, "dirt_floor");
                tile.Objects.Add(floor);

                // Set ceiling
                DungeonObject ceiling = new DungeonObject(code, DungeonObjectType.Ceiling, "dirt_ceiling");
                tile.Objects.Add(ceiling);

                // LEFT wall
                // If it is a left border set left wall
                if (i == 0)
                {
                    DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i - 1, j, i, j);
                    tile.Objects.Add(newWall);
                }
                else
                {
                    int leftCode = DungeonUtils.GetCodeOfTileByIndex(i - 1, j);
                    if (tiles.ContainsKey(leftCode))
                    {
                        if (tiles [leftCode].room == null && tiles [leftCode].road != null)
                        {
                            DungeonObject newPassage = PrepareWallObject(code, DungeonObjectType.Passage, "passage_rock_arc", i - 1, j, i, j);
                            tile.Objects.Add(newPassage);
                        }
                        else if (tiles [leftCode].room == null && tiles [leftCode].road == null)
                        {
                            DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i - 1, j, i, j);
                            tile.Objects.Add(newWall);
                        }
                    }
                }

                // TOP wall
                // If it is a top border set top wall
                if (j == 0)
                {
                    DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i, j - 1, i, j);
                    tile.Objects.Add(newWall);
                }
                else
                {
                    int topCode = DungeonUtils.GetCodeOfTileByIndex(i, j - 1);
                    if (tiles.ContainsKey(topCode))
                    {
                        if (tiles [topCode].room == null && tiles [topCode].road != null)
                        {
                            DungeonObject newPassage = PrepareWallObject(code, DungeonObjectType.Passage, "passage_rock_arc", i, j - 1, i, j);
                            tile.Objects.Add(newPassage);
                        }
                        else if (tiles [topCode].room == null && tiles [topCode].road == null)
                        {
                            DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i, j - 1, i, j);
                            tile.Objects.Add(newWall);
                        }
                    }
                }

                // RIGHT wall
                // If it is a right border set right wall
                if (i == dungeon.width - 1)
                {
                    DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i + 1, j, i, j);
                    tile.Objects.Add(newWall);
                }
                else
                {
                    int rightCode = DungeonUtils.GetCodeOfTileByIndex(i + 1, j);
                    if (tiles.ContainsKey(rightCode))
                    {
                        if (tiles [rightCode].room == null && tiles [rightCode].road != null)
                        {
                            DungeonObject newPassage = PrepareWallObject(code, DungeonObjectType.Passage, "passage_rock_arc", i + 1, j, i, j);
                            tile.Objects.Add(newPassage);
                        }
                        else if (tiles [rightCode].room == null && tiles [rightCode].road == null)
                        {
                            DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i + 1, j, i, j);
                            tile.Objects.Add(newWall);
                        }
                    }
                }

                // BOTTOM wall
                // If it is a bottom border set bottom wall
                if (j == dungeon.height - 1)
                {
                    DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i, j + 1, i, j);
                    tile.Objects.Add(newWall);
                }
                else
                {
                    int bottomCode = DungeonUtils.GetCodeOfTileByIndex(i, j + 1);
                    if (tiles.ContainsKey(bottomCode))
                    {
                        if (tiles [bottomCode].room == null && tiles [bottomCode].road != null)
                        {
                            DungeonObject newPassage = PrepareWallObject(code, DungeonObjectType.Passage, "passage_rock_arc", i, j + 1, i, j);
                            tile.Objects.Add(newPassage);
                        }
                        else if (tiles [bottomCode].room == null && tiles [bottomCode].road == null)
                        {
                            DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i, j + 1, i, j);
                            tile.Objects.Add(newWall);
                        }
                    }
                }
            }
            else if (tiles [code].road != null)
            {
                // Set floor
                DungeonObject floor = new DungeonObject(code, DungeonObjectType.Floor, "dirt_floor");
                tile.Objects.Add(floor);

                // Set ceiling
                DungeonObject ceiling = new DungeonObject(code, DungeonObjectType.Ceiling, "dirt_ceiling");
                tile.Objects.Add(ceiling);

                // LEFT wall
                // If it is a left border set left wall
                if (i == 0)
                {
                    DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i - 1, j, i, j);
                    tile.Objects.Add(newWall);
                }
                else
                {
                    int leftCode = DungeonUtils.GetCodeOfTileByIndex(i - 1, j);
                    if (tiles.ContainsKey(leftCode))
                    {
                        if (tiles [leftCode].room != null)
                        {
                            DungeonObject newPassage = PrepareWallObject(code, DungeonObjectType.Passage, "passage_rock_arc", i - 1, j, i, j);
                            tile.Objects.Add(newPassage);
                        }
                        else if (tiles [leftCode].room == null && tiles [leftCode].road == null)
                        {
                            DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i - 1, j, i, j);
                            tile.Objects.Add(newWall);
                        }
                    }
                }

                // TOP wall
                // If it is a top border set top wall
                if (j == 0)
                {
                    DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i, j - 1, i, j);
                    tile.Objects.Add(newWall);
                }
                else
                {
                    int topCode = DungeonUtils.GetCodeOfTileByIndex(i, j - 1);
                    if (tiles.ContainsKey(topCode))
                    {
                        if (tiles [topCode].room != null)
                        {
                            DungeonObject newPassage = PrepareWallObject(code, DungeonObjectType.Passage, "passage_rock_arc", i, j - 1, i, j);
                            tile.Objects.Add(newPassage);
                        }
                        else if (tiles [topCode].room == null && tiles [topCode].road == null)
                        {
                            DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i, j - 1, i, j);
                            tile.Objects.Add(newWall);
                        }
                    }
                }

                // RIGHT wall
                // If it is a right border set right wall
                if (i == dungeon.width - 1)
                {
                    DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i + 1, j, i, j);
                    tile.Objects.Add(newWall);
                }
                else
                {
                    int rightCode = DungeonUtils.GetCodeOfTileByIndex(i + 1, j);
                    if (tiles.ContainsKey(rightCode))
                    {
                        if (tiles [rightCode].room != null)
                        {
                            DungeonObject newPassage = PrepareWallObject(code, DungeonObjectType.Passage, "passage_rock_arc", i + 1, j, i, j);
                            tile.Objects.Add(newPassage);
                        }
                        else if (tiles [rightCode].room == null && tiles [rightCode].road == null)
                        {
                            DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i + 1, j, i, j);
                            tile.Objects.Add(newWall);
                        }
                    }
                }

                // BOTTOM wall
                // If it is a bottom border set bottom wall
                if (j == dungeon.height - 1)
                {
                    DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i, j + 1, i, j);
                    tile.Objects.Add(newWall);
                }
                else
                {
                    int bottomCode = DungeonUtils.GetCodeOfTileByIndex(i, j + 1);
                    if (tiles.ContainsKey(bottomCode))
                    {
                        if (tiles [bottomCode].room != null)
                        {
                            DungeonObject newPassage = PrepareWallObject(code, DungeonObjectType.Passage, "passage_rock_arc", i, j + 1, i, j);
                            tile.Objects.Add(newPassage);
                        }
                        else if (tiles [bottomCode].room == null && tiles [bottomCode].road == null)
                        {
                            DungeonObject newWall = PrepareWallObject(code, DungeonObjectType.Wall, "wall_rock", i, j + 1, i, j);
                            tile.Objects.Add(newWall);
                        }
                    }
                }
            }
        }
    }