The tile which ends the game if the player enters it.
Наследование: Tile
Пример #1
0
        /// <summary>
        /// Method to generate a room from a string (e.g. a .txt)
        /// </summary>
        /// <param name="input">The string from which the room will be constructed</param>
        /// <param name="roomID">The number of the room.</param>
        /// <param name="MaxRoom">The max number of rooms</param>
        /// <returns>True.</returns>
        public bool FromString(string input, int roomID, int MaxRoom)
        {
            int col = 0, row = 0, maxcol = 0;
            _tiles.Add(new List<GeneratorTile>());
            foreach (char c in input)
            {
                switch (c)
                {
                    case '#':
                        _tiles[row].Add(new GeneratorTile(this, new Backend.Coords(col, row), true, r));
                        col += 1;
                        break;
                    case '\n':
                        if (col > maxcol) { maxcol = col; };

                        col = 0;
                        row += 1;
                        _tiles.Add(new List<GeneratorTile>());
                        break;
                    case 'S':

                        _tiles[row].Add(new GeneratorTile(this, new Backend.Coords(col, row), false, r));

                        if (roomID != 1)
                        {
                            _tiles[row][col].Add(new TeleportTile(_tiles[row][col], "room" + (roomID - 1).ToString() + ".xml", new Backend.Coords(col, row)));
                            _exits.Add(new Exit(new Backend.Coords(col, row), "room" + (roomID).ToString() + ".xml", new Backend.Coords(col, row), "room" + (roomID - 1).ToString() + ".xml"));
                        }
                        else
                        {
                            AddPlayer(new Backend.Coords(col, row));
                        }
                        col += 1;
                        break;
                    case 'G':
                        _tiles[row].Add(new GeneratorTile(this, new Backend.Coords(col, row), false, r));

                        if (roomID == MaxRoom)
                        {
                            TargetTile target = new TargetTile(_tiles[row][col]);
                            _tiles[row][col].Add(target);
                        }
                        else
                        {
                            _tiles[row][col].Add(new TeleportTile(_tiles[row][col], "room" + (roomID + 1).ToString() + ".xml", new Backend.Coords(col, row)));
                            _exits.Add(new Exit(new Backend.Coords(col, row), "room" + (roomID).ToString() + ".xml", new Backend.Coords(col, row), "room" + (roomID + 1).ToString() + ".xml"));
                        }
                        col += 1;
                        break;
                    case 'F':
                        _tiles[row].Add(new GeneratorTile(this, new Backend.Coords(col, row), false, r));

                        Enemy enemy = new Enemy(-1, -1, -1, -1, "", r);
                        ActorTile enemyTile = new ActorTile(_tiles[row][col], enemy);
                        enemy.tile = enemyTile;
                        _tiles[row][col].Add(enemyTile);
                        _actors.Add(enemy);
                        col += 1;
                        break;
                    default:
                        _tiles[row].Add(new GeneratorTile(this, new Backend.Coords(col, row), false, r));
                        col += 1;
                        break;
                }

            }
            if (col > maxcol) { maxcol = col; };

            _width = maxcol;
            _height = row + 1;
            // Fill all rows to maximum width
            for (int i = 0; i < _height; ++i)
            {
                while (_tiles[i].Count < maxcol)
                {
                    _tiles[i].Add(new GeneratorTile(this, new Backend.Coords(_tiles[i].Count + 1, i), false, r));
                }
            }
            return true;
        }