A tile on the map used to represent an actor.
Inheritance: Tile
コード例 #1
0
ファイル: Netlogic.cs プロジェクト: propra13-orga/gruppe22
        /// <summary>
        /// React to incoming events
        /// </summary>
        /// <param name="DownStream"></param>
        /// <param name="eventID"></param>
        /// <param name="data"></param>
        public override void HandleEvent(bool DownStream, Events eventID, params object[] data)
        {
            if (DownStream) // Received from Frontend
            {
                switch (eventID)
                {
                    case Events.ChangeMap:
                        _map.ClearActors();
                        _map.FromXML((string)data[0], null, true);
                        _parent.HandleEvent(true, Events.ChangeMap, (int)data[1]);
                        break;
                    case Events.FinishedAnimation:
                        _network.SendMessage(PacketType.FinishedAnim, (int)data[0], (int)(Activity)data[1], (int)_map.actors[(int)data[0]].moveIndex);
                        _map.actors[(int)data[0]].locked = false;
                        break;

                    case Events.TileEntered:
                        _network.SendMessage(PacketType.FinishedMove, (int)data[0], (int)(Direction)data[1], (int)_map.actors[(int)data[0]].moveIndex);
                        _map.actors[(int)data[0]].locked = false;
                        break;
                    case Events.MoveActor:
                        if (!_map.actors[(int)data[0]].locked)
                        {
                            _map.actors[(int)data[0]].locked = true;
                            _network.SendMessage(PacketType.Move,
                                (int)data[0], (int)(Direction)data[1],
                                (int)data[2],
                                (int)_map.actors[(int)data[0]].tile.coords.x,
                                (int)_map.actors[(int)data[0]].tile.coords.y
                                );
                        }
                        break;
                    case Events.Chat:
                        _network.SendMessage(PacketType.Chat, (string)data[0]);
                        break;
                    case Events.ContinueGame:
                        _network.SendMessage(PacketType.Pause, false);
                        break;
                    case Events.Pause:
                        _network.SendMessage(PacketType.Pause, true);
                        break;

                }
            }
            else // Received from Network
            {

                switch (eventID)
                {
                    case Events.TrapActivate:
                        _map[(Coords)data[0]].trap.status = (TrapState)data[1];
                        break;
                    case Events.Disconnect:
                        _parent.HandleEvent(false, eventID, data);
                        break;
                    case Events.RemovePlayer:
                        _map.actors[(int)data[0]].online = false;
                        _parent.HandleEvent(false, Events.AddPlayer);
                        break;
                    case Events.AddPlayer:
                        Actor actor = (Actor)data[2];
                        actor.id = (int)data[0];
                        ActorTile actortile = new ActorTile(_map[(Coords)data[1]], actor);
                        actor.tile = actortile;
                        actortile.enabled = (actor.health > 0);
                        actortile.parent = _map[(Coords)data[1]];
                        _map[(Coords)data[1]].Add(actortile);
                        _map.updateTiles.Add((Coords)data[1]);

                        if (_map.actors.Count <= (int)data[0])
                        {
                            _map.actors.Add(actor);
                        }
                        else
                        {
                            if (_map.actors[(int)data[0]].tile != null)
                            {
                                Coords source = ((FloorTile)_map.actors[(int)data[0]].tile.parent).coords;
                                ((FloorTile)_map.actors[(int)data[0]].tile.parent).Remove(_map.actors[(int)data[0]].tile);
                                // Remove old tile from updatelist (if no other actor or trap)
                                if (!((_map[source].hasEnemy)
                    || (_map[source].hasPlayer)
                    || (_map[source].hasTrap)))
                                    _map.updateTiles.Remove(source);
                            }
                            _map.actors[(int)data[0]] = actor;
                        }
                        _map.actors[(int)data[0]].online = true;
                        _parent.HandleEvent(false, Events.AddPlayer);
                        break;
                    case Events.ContinueGame:
                        _parent.HandleEvent(true, Backend.Events.ContinueGame, true);
                        break;

                    case Events.Chat:
                        _parent.HandleEvent(false, Backend.Events.ShowMessage, data);
                        break;
                    case Events.ShowMessage:
                        _parent.HandleEvent(false, Backend.Events.ShowMessage, data);
                        break;
                    case Events.MoveActor:
                        if ((int)data[0] < _map.actors.Count)
                        {
                            _map.actors[(int)data[0]].moveIndex = (int)data[2];
                            _map.actors[(int)data[0]].direction = (Direction)data[1];

                            _map.PositionActor(_map.actors[(int)data[0]], (Coords)data[3]);
                            if ((Coords)data[3] != (Coords)data[4])
                            {
                                _parent.HandleEvent(false, Events.MoveActor, data);
                            }
                            else
                            {
                                _map.actors[(int)data[0]].locked = false;
                            }
                        }
                        break;

                    case Events.AnimateActor:
                        if ((int)data[0] < _map.actors.Count)
                        {
                            _map.actors[(int)data[0]].locked = true;
                            _map.actors[(int)data[0]].moveIndex = (int)data[2];
                            _map.actors[(int)data[0]].direction = (Direction)data[3];
                            _parent.HandleEvent(false, Backend.Events.AnimateActor, (int)data[0], (Activity)data[1]);
                        }
                        break;
                    case Events.ActorText:
                        _parent.HandleEvent(false, Backend.Events.ActorText, (int)data[0], data[1], data[2]);

                        // defender, _map.actors[defender].tile.coords, "Evade")
                        break;
                    case Events.DamageActor:
                        if ((int)data[0] < _map.actors.Count)
                        {
                            _map.actors[(int)data[0]].locked = false;
                            _map.actors[(int)data[0]].health = (int)data[2];
                            _map.actors[(int)data[0]].moveIndex = (int)data[4];
                            // , defender, _map.actors[defender].tile.coords, _map.actors[defender].health, damage);

                            _map.actors[(int)data[0]].direction = (Direction)data[5];
                        }
                        _parent.HandleEvent(false, Backend.Events.DamageActor, data);
                        break;
                    case Events.KillActor:
                        _map.actors[(int)data[0]].locked = false;
                        _map.actors[(int)data[0]].moveIndex = (int)data[3];
                        _map.actors[(int)data[0]].health = 0;
                        _map.actors[(int)data[0]].direction = (Direction)data[4];
                        _parent.HandleEvent(false, Backend.Events.KillActor, data);
                        break;
                    case Events.PlaySound:
                        _parent.HandleEvent(false, Backend.Events.PlaySound, data);
                        break;
                    case Events.Dialog:
                        //from, to, message, new Backend.DialogLine[] { new Backend.DialogLine("Goodbye", -1) }
                        _parent.HandleEvent(false, Backend.Events.Dialog, _map.actors[(int)data[0]], _map.actors[(int)data[1]], data[2]);
                        break;
                    case Events.Shop:
                        if (((int)data[0] < _map.actors.Count) && ((int)data[1] < _map.actors.Count))
                            _parent.HandleEvent(false, Backend.Events.Shop, _map.actors[(int)data[0]], _map.actors[(int)data[1]]);
                        break;
                    case Events.GameOver:
                        _parent.HandleEvent(false, Backend.Events.GameOver, data);
                        break;
                }

            };
        }
コード例 #2
0
ファイル: Map.cs プロジェクト: propra13-orga/gruppe22
        /// <summary>
        /// Load a map from a file
        /// </summary>
        /// <param name="filename">The filename to read from</param>
        /// <param name="player">The starting position on the loaded map</param>
        public void ReadXML(XmlReader xmlr, Backend.Coords targetCoords = null, bool resetPlayer = false)
        {
            List<Player> players = new List<Player>();

            // Move all players to the new map
            if (_actors.Count > 0)
            {
                for (int i = 0; i < _actors.Count; ++i)
                {
                    if (_actors[i].tile != null)
                        _actors[i].tile.enabled = false;
                    if (_actors[i] is Player)
                    {
                        players.Add(_actors[i] as Player);
                        players[players.Count - 1].tile = null;
                        break;
                    }
                }
            }
            ClearActors();

            _tiles.Clear();
            _updateTiles.Clear();
            xmlr.MoveToContent();//xml
            _width = int.Parse(xmlr.GetAttribute("width"));
            _height = int.Parse(xmlr.GetAttribute("height"));
            if (xmlr.GetAttribute("name") != null) _name = xmlr.GetAttribute("name");
            if (xmlr.GetAttribute("level") != null) _level = int.Parse(xmlr.GetAttribute("level"));
            if (xmlr.GetAttribute("dungeon") != null) _dungeonname = xmlr.GetAttribute("dungeon");
            if (xmlr.GetAttribute("floor") != null) _floorFile = xmlr.GetAttribute("floor");
            if (xmlr.GetAttribute("wall") != null) _wallFile = xmlr.GetAttribute("wall");
            if (xmlr.GetAttribute("id") != null) _id = Int32.Parse(xmlr.GetAttribute("id"));

            if (xmlr.GetAttribute("light") != null) _light = int.Parse(xmlr.GetAttribute("light"));
            if (xmlr.GetAttribute("music") != null) _music = xmlr.GetAttribute("music");

            xmlr.ReadStartElement("GameMap");//GameMap

            for (int row = 0; row < _height; ++row)
            {
                _tiles.Add(new List<FloorTile>());
                for (int col = 0; col < _width; ++col)
                {
                    _tiles[row].Add(new FloorTile(this, new Backend.Coords(col, row)));
                }
            }

            while ((xmlr.NodeType != XmlNodeType.EndElement) && (xmlr.NodeType != XmlNodeType.None))
            { // Add Tiles and overlay-Tiles
                switch (xmlr.Name)
                {
                    case "Tile":
                        FloorTile tile = _tiles[Int32.Parse(xmlr.GetAttribute("CoordY"))][Int32.Parse(xmlr.GetAttribute("CoordX"))];
                        if (xmlr.GetAttribute("visited") != null)
                        {
                            tile.visible = Boolean.Parse(xmlr.GetAttribute("visited"));
                        }
                        if (!xmlr.IsEmptyElement)
                        {
                            xmlr.Read();

                            while ((xmlr.NodeType != XmlNodeType.EndElement))
                            {
                                switch (xmlr.Name)
                                {
                                    case "WallTile":
                                        WallTile wall = new WallTile(this);
                                        if (xmlr.GetAttribute("Enabled") != null) wall.enabled = Boolean.Parse(xmlr.GetAttribute("Enabled"));
                                        if (xmlr.GetAttribute("Health") != null) wall.health = Int32.Parse(xmlr.GetAttribute("Health"));
                                        if (xmlr.GetAttribute("Type") != null) wall.type = (WallType)Enum.Parse(typeof(WallType), xmlr.GetAttribute("Type").ToString());

                                        if (xmlr.GetAttribute("Illusion") != null) wall.illusion = Boolean.Parse(xmlr.GetAttribute("Illusion"));
                                        if (xmlr.GetAttribute("Illusionvisible") != null) wall.illusionVisible = Boolean.Parse(xmlr.GetAttribute("Illusionvisible"));
                                        tile.Add(wall);
                                        break;
                                    case "ProjectileTile":
                                        {
                                            uint id = 0;
                                            if (xmlr.GetAttribute("id", _id.ToString()) != null) id = UInt32.Parse(xmlr.GetAttribute("id"));
                                            Direction dir = Direction.Up;
                                            if (xmlr.GetAttribute("direction", _id.ToString()) != null) dir = (Direction)Enum.Parse(typeof(Direction), xmlr.GetAttribute("direction").ToString());
                                            ProjectileTile projectile = new ProjectileTile(tile, dir, id);
                                        }
                                        break;
                                    case "ItemTile":
                                        Item item = new Item();
                                        xmlr.Read();
                                        item.Load(xmlr);
                                        ItemTile itemTile = new ItemTile(tile, item);
                                        item.tile = itemTile;
                                        tile.Add(itemTile);
                                        xmlr.Read(); // End Item
                                        break;

                                    case "TargetTile":
                                        tile.Add(new TargetTile(tile));
                                        break;

                                    case "TrapTile":
                                        TrapTile trap = new TrapTile(this, Int32.Parse(xmlr.GetAttribute("damage")));
                                        if (xmlr.GetAttribute("penetrate") != null) trap.penetrate = Int32.Parse(xmlr.GetAttribute("penetrate"));

                                        if (xmlr.GetAttribute("evade") != null) trap.evade = Int32.Parse(xmlr.GetAttribute("evade"));

                                        if (xmlr.GetAttribute("changing") != null)
                                        {
                                            trap.type = trap.type | TrapType.Changing;
                                        }
                                        if (xmlr.GetAttribute("hidden") != null)
                                        {
                                            trap.type = trap.type | TrapType.Hidden;
                                        }
                                        if (xmlr.GetAttribute("onlyonce") != null)
                                        {
                                            trap.type = trap.type | TrapType.OnlyOnce;
                                        }
                                        if (xmlr.GetAttribute("broken") != null)
                                        {
                                            trap.status = TrapState.Destroyed;
                                        }
                                        if (xmlr.GetAttribute("disabled") != null)
                                        {
                                            trap.status = TrapState.Disabled;
                                        }
                                        if (xmlr.GetAttribute("invisible") != null)
                                        {
                                            trap.status = TrapState.NoDisplay;
                                        }
                                        tile.Add(trap);
                                        _updateTiles.Add(tile.coords);
                                        break;
                                    case "ReservedTile":
                                        ReservedTile reserved = new ReservedTile(tile);

                                        if (xmlr.GetAttribute("Enabled") != null)
                                        { reserved.enabled = Boolean.Parse(xmlr.GetAttribute("Enabled")); }

                                        if (xmlr.GetAttribute("CanEnter") != null)
                                        { reserved.canEnter = Boolean.Parse(xmlr.GetAttribute("CanEnter")); }
                                        if (xmlr.GetAttribute("Filename") != null)
                                        { reserved.filename = xmlr.GetAttribute("Filename"); }
                                        if (xmlr.GetAttribute("Index") != null)
                                        { reserved.index = Int32.Parse(xmlr.GetAttribute("Index")); }

                                        tile.Add(reserved);

                                        break;

                                    case "DoorTile":
                                        DoorTile door = new DoorTile(tile);
                                        if (xmlr.GetAttribute("open") != null)
                                        { door.open = Boolean.Parse(xmlr.GetAttribute("open")); }

                                        if (xmlr.GetAttribute("key") != null)
                                        { door.key = int.Parse(xmlr.GetAttribute("key")); }
                                        tile.Add(door);
                                        break;

                                    case "TeleportTile":

                                        TeleportTile transporter = new TeleportTile(tile, xmlr.GetAttribute("nextRoom"), new Backend.Coords(Int32.Parse(xmlr.GetAttribute("nextX")), Int32.Parse(xmlr.GetAttribute("nextY"))));
                                        if (xmlr.GetAttribute("hidden") != null)
                                        { transporter.hidden = Boolean.Parse(xmlr.GetAttribute("hidden")); }
                                        if (xmlr.GetAttribute("enabled") != null)
                                        { transporter.enabled = Boolean.Parse(xmlr.GetAttribute("enabled")); }
                                        if (xmlr.GetAttribute("teleport") != null)
                                        { transporter.teleport = Boolean.Parse(xmlr.GetAttribute("teleport")); }
                                        if (xmlr.GetAttribute("down") != null)
                                        { transporter.down = Boolean.Parse(xmlr.GetAttribute("down")); }

                                        tile.Add(transporter);
                                        break;

                                    case "TriggerTile":
                                        Backend.Coords target = new Backend.Coords(-1, -1);
                                        if (xmlr.GetAttribute("affectX") != null) target.x = Int32.Parse(xmlr.GetAttribute("affectX"));

                                        if (xmlr.GetAttribute("affectY") != null) target.y = Int32.Parse(xmlr.GetAttribute("affectY"));

                                        TriggerTile trigger = new TriggerTile(tile, target);

                                        if (xmlr.GetAttribute("explanation") != null) { trigger.explanationEnabled = xmlr.GetAttribute("explanation"); };
                                        if (xmlr.GetAttribute("explanationdisabled") != null) { trigger.explanationDisabled = xmlr.GetAttribute("explanationdisabled"); };
                                        if (xmlr.GetAttribute("enabled") != null) { trigger.enabled = Boolean.Parse(xmlr.GetAttribute("enabled")); };
                                        if (xmlr.GetAttribute("repeat") != null) { trigger.repeat = Int32.Parse(xmlr.GetAttribute("repeat")); };

                                        if (xmlr.GetAttribute("alwaysShowDisabled") != null) { trigger.alwaysShowDisabled = Boolean.Parse(xmlr.GetAttribute("alwaysShowDisabled")); };
                                        if (xmlr.GetAttribute("alwaysShowEnabled") != null) { trigger.alwaysShowEnabled = Boolean.Parse(xmlr.GetAttribute("alwaysShowEnabled")); };

                                        if (xmlr.GetAttribute("tileimage") != null) { trigger.tileimage = xmlr.GetAttribute("tileimage"); };
                                        if (xmlr.GetAttribute("reactToEnemies") != null) { trigger.reactToEnemies = Boolean.Parse(xmlr.GetAttribute("reactToEnemies")); };
                                        if (xmlr.GetAttribute("reactToObjects") != null) { trigger.reactToObjects = Boolean.Parse(xmlr.GetAttribute("reactToObjects")); };
                                        if (xmlr.GetAttribute("reactToItem") != null)
                                        {
                                            trigger.reactToItem = Int32.Parse(xmlr.GetAttribute("reactToItem"));
                                        }
                                        tile.Add(trigger);
                                        break;
                                    case "CheckpointTile":
                                        int bonusLifes = 0;
                                        bool visited = false;

                                        if (xmlr.GetAttribute("bonuslife") != null)
                                            bonusLifes = Convert.ToInt32(xmlr.GetAttribute("bonuslife"));
                                        if (xmlr.GetAttribute("visited") != null)
                                            visited = Convert.ToBoolean(xmlr.GetAttribute("visited"));
                                        tile.Add(new CheckpointTile(tile, visited, bonusLifes));
                                        break;

                                    case "ActorTile":
                                        Actor actor;
                                        xmlr.Read();
                                        switch (xmlr.Name)
                                        {
                                            case "Enemy":
                                                actor = new Enemy();
                                                actor.Load(xmlr);
                                                break;
                                            case "Player":
                                                actor = new Player();
                                                actor.Load(xmlr);
                                                break;
                                            default:
                                                actor = new NPC();
                                                actor.Load(xmlr);
                                                break;
                                        }
                                        while (actor.id > _actors.Count - 1)
                                        {
                                            _actors.Add(new NPC());
                                            _actors[_actors.Count - 1].id = _actors.Count - 1;
                                        }

                                        if (!(actor is Player))
                                        {
                                            ActorTile tile2 = new ActorTile(tile, actor);
                                            tile2.enabled = (actor.health > 0);
                                            actor.tile = tile2;
                                            tile.Add(tile2);
                                            _actors[actor.id] = actor;
                                            _updateTiles.Add(tile.coords);
                                        }
                                        else
                                        {
                                            if (players.Count > 0)
                                            {
                                                bool found = false;
                                                for (int i = 0; i < players.Count; ++i)
                                                {
                                                    if (players[i].GUID == actor.GUID)
                                                    {
                                                        if (!resetPlayer)
                                                            actor.copyFrom(players[i]);
                                                        players.RemoveAt(i);
                                                        found = true;
                                                        break;
                                                    }
                                                }
                                            }
                                            if (targetCoords == null)
                                            {
                                                targetCoords = tile.coords;
                                            }
                                            if (!resetPlayer)
                                            {

                                                ActorTile actortile = new ActorTile(this[targetCoords], actor);
                                                actor.tile = actortile;
                                                actortile.enabled = (actor.health > 0);
                                                actortile.parent = this[targetCoords];
                                                this[targetCoords].Add(actortile);
                                                _actors[actor.id] = actor;
                                                _updateTiles.Add(targetCoords);
                                                Uncover(actors[actor.id].tile.coords, actors[actor.id].viewRange);
                                            }
                                            else
                                            {
                                                ActorTile actortile = new ActorTile(tile, actor);
                                                actor.tile = actortile;
                                                actortile.enabled = (actor.health > 0);
                                                actortile.parent = tile;
                                                tile.Add(actortile);
                                                _actors[actor.id] = actor;
                                                _updateTiles.Add(tile.coords);
                                                Uncover(actors[actor.id].tile.coords, actors[actor.id].viewRange);
                                            }

                                        }

                                        break;
                                }
                                xmlr.Read();
                            }
                            xmlr.ReadEndElement();
                        }
                        else
                        {
                            xmlr.Read();
                        }
                        break;
                }
            }

            if (targetCoords == null)
            {
                targetCoords = new Coords(1, 1);
            }

            while (players.Count > 0)
            {
                ActorTile actortile = new ActorTile(this[targetCoords], players[0]);
                actortile.enabled = (players[0].health > 0);
                actortile.parent = this[targetCoords];
                this[targetCoords].Add(actortile);
                players[0].tile = actortile;
                _updateTiles.Add(targetCoords);
                bool found = false;
                foreach (Actor a in _actors)
                {
                    if ((a.GUID == players[0].GUID) && (players[0].GUID != ""))
                    {
                        found = true;
                        a.copyFrom(players[0]);
                        a.tile = actortile;
                        break;
                    }
                }
                if (!found)
                {
                    foreach (Actor a in _actors)
                    {
                        if ((a is Player) && (a.GUID == ""))
                        {
                            found = true;
                            a.copyFrom(players[0]);
                            a.GUID = players[0].GUID;
                            a.tile = actortile;
                            break;
                        }
                    }
                }
                if (!found)
                {
                    players[0].id = _actors.Count;
                    _actors.Add(players[0]);
                }

                players.RemoveAt(0);
            }
            foreach (Actor a in _actors)
            {
                if (a.tile == null)
                {
                    ActorTile actortile = new ActorTile(this[targetCoords], a);
                    actortile.enabled = (a.health > 0);
                    actortile.parent = this[targetCoords];
                    this[targetCoords].Add(actortile);
                    a.tile = actortile;
                    a.online = false;
                    _updateTiles.Add(targetCoords);
                }
            }
        }
コード例 #3
0
ファイル: Generator.cs プロジェクト: propra13-orga/gruppe22
        /// <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;
        }
コード例 #4
0
ファイル: PureLogic.cs プロジェクト: propra13-orga/gruppe22
        public void ReassignPlayer()
        {
            int _playerID = -1;
            for (int i = 0; i < map.actors.Count; ++i)
            {
                if (map.actors[i] is Player)
                {

                    if ((_playerID == -1) && (map.actors[i].tile != null))
                    {
                        _playerID = i;
                        map.actors[i].online = true;

                    }
                    else
                    {
                        map.actors[i].online = false;
                    }
                }
            }
            if (_playerID < 0)
            {
                new Backend.Coords(1, 1);
                Player player = new Player(100, 0, 30);
                player.id = _map.actors.Count;
                ActorTile playerTile = new ActorTile(_map[1, 1], player);
                player.tile = playerTile;
                _map[1, 1].Add(playerTile);
                player.online = true;
                _playerID = _map.actors.Count;
                map.actors.Add(player);
            }
            _parent.HandleEvent(true, Backend.Events.ChangeMap, _playerID);
        }
コード例 #5
0
ファイル: Generator.cs プロジェクト: propra13-orga/gruppe22
        /// <summary>
        /// Method to add a shop to the map.
        /// The method adds a NPC with a shop and some custom tiles around him.
        /// </summary>
        public void AddShop()
        {
            int x = -1;
            while (x == -1)
            {
                x = 4 + r.Next(_width - 6);
                if ((_tiles[0][x].hasTeleport) ||
                    (_tiles[0][x + 1].hasTeleport) ||
                    (_tiles[0][x - 1].hasTeleport))
                    x = -1;
            }
            ClearTile(x - 1, 2);

            ClearTile(x + 1, 2);
            ClearTile(x - 1, 1);
            ClearTile(x, 1);
            ClearTile(x + 1, 1);

            NPC npc = new NPC(-1, -1, -1, -1, "", r, _level, true);
            npc.gold = 50000;
            npc.hasShop = true;
            for (int count = 0; count < 25; ++count)
            {
                npc.AddItem(new Item(r, 0, _level, false));
            }
            ActorTile NPCTile = new ActorTile(_tiles[2][x], npc);
            npc.tile = NPCTile;
            npc.stunned = -1;
            _tiles[2][x].Add(NPCTile);
            _actors.Add(npc);

            _tiles[2][x + 1].Add(new ReservedTile(_tiles[2][x + 1], ".\\Content\\shop.xml", 0));
            // 448, 192, 64, 64));
            //_tiles[2][pos.x - 1].Add(new ReservedTile(this, ".\\Content\\shop.xml", 1));
            // 354, 509, 64, 96)
            _tiles[2][x - 1].Add(new ReservedTile(_tiles[2][x - 1], ".\\Content\\shop.xml", 2));
            // 195, 256, 64, 64
            _tiles[1][x].Add(new ReservedTile(_tiles[1][x], ".\\Content\\shop.xml", 3));
            // 0, 512, 96, 128

            _music = "shop.wav";
        }
コード例 #6
0
ファイル: Generator.cs プロジェクト: propra13-orga/gruppe22
 /// <summary>
 /// Method to add the player to a room.
 /// </summary>
 /// <param name="pos">The position at which the player will spawn, (1,1) by default</param>
 public void AddPlayer(Coords pos)
 {
     if (pos == null)
     {
         pos = new Backend.Coords(1, 1);
     }
     Player player = new Player(100, 0, 30);
     ActorTile playerTile = new ActorTile(_tiles[pos.y][pos.x], player);
     player.tile = playerTile;
     _tiles[pos.y][pos.x].Add(playerTile);
     _actors.Add(player);
 }
コード例 #7
0
ファイル: Generator.cs プロジェクト: propra13-orga/gruppe22
        /// <summary>
        /// Method to add NPCs in a room.
        /// By default the NPCs have some money and a dialogue.
        /// </summary>
        /// <param name="amount">1 by default</param>
        public void AddNPC(int amount = -1)
        {
            if (amount < 0) amount = 1;
            for (int i = 0; i < amount; ++i)
            {
                int count = 0;
                Path pos = new Path(1 + r.Next(_width - 2), 1 + r.Next(_height - 2));
                while ((count < _width * height) && (pos.x > 0)
             && (_tiles[pos.y][pos.x].overlay.Count != 0)
             )
                {
                    count += 1;
                    pos.x += 1;
                    if (pos.x > _width - 2)
                    {
                        pos.x = 1;
                        pos.y += 1;
                    };
                    if (pos.y > _height - 2)
                    {
                        pos.y = 1;
                        pos.x = 1;
                    }
                    if (count >= _width * _height)
                    {
                        pos.x = -1;
                        pos.y = -1;
                    }
                }

                if ((pos.x >= 0) && (pos.x < _width) && (pos.y < _height) && (pos.y >= 0))
                {
                    NPC npc = new NPC(-1, -1, -1, -1, "", r, _level);
                    npc.gold = 50000;
                    npc.hasShop = false;
                    npc.hasDialog = true;
                    ActorTile NPCTile = new ActorTile(_tiles[pos.y][pos.x], npc);
                    npc.tile = NPCTile;
                    _tiles[pos.y][pos.x].Add(NPCTile);
                    _actors.Add(npc);
                }
            }
        }
コード例 #8
0
ファイル: Generator.cs プロジェクト: propra13-orga/gruppe22
        /// <summary>
        /// Method to generate the enemys for a room.
        /// The method places enemys at free position and initializes them.
        /// </summary>
        /// <param name="amount">The number of enemys for a room, 5 by default</param>
        public void AddEnemies(int amount = -1)
        {
            if (amount < 0) amount = 5;
            for (int i = 0; i < amount; ++i)
            {
                int count = 0;
                Path pos = new Path(1 + r.Next(_width - 2), 1 + r.Next(_height - 2));
                while ((count < _width * height) && (pos.x > 0)
             && (_tiles[pos.y][pos.x].overlay.Count != 0)
             )
                {
                    count += 1;
                    pos.x += 1;
                    if (pos.x > _width - 2)
                    {
                        pos.x = 1;
                        pos.y += 1;
                    };
                    if (pos.y > _height - 2)
                    {
                        pos.y = 1;
                        pos.x = 1;
                    }
                    if (count >= _width * _height)
                    {
                        pos.x = -1;
                        pos.y = -1;
                    }
                }

                if ((pos.x >= 0) && (pos.x < _width) && (pos.y < _height) && (pos.y >= 0))
                {
                    Enemy enemy = new Enemy(-1, -1, -1, -1, "", r, (_id == 1) ? 0 : _level);
                    ActorTile enemyTile = new ActorTile(_tiles[pos.y][pos.x], enemy);
                    enemy.tile = enemyTile;
                    _tiles[pos.y][pos.x].Add(enemyTile);
                    _actors.Add(enemy);
                }
            }
        }
コード例 #9
0
ファイル: Generator.cs プロジェクト: propra13-orga/gruppe22
        /// <summary>
        /// Method to add a boss enemy to a room.
        /// A boss is more powerful than a normal enemy
        /// and the room gets a special sound if there is a boss in it.
        /// </summary>
        public void AddBoss()
        {
            for (int x = 0; x < _width; ++x)
            {
                for (int y = 0; y < _height; ++y)
                {
                    if ((_tiles[y][x].hasEnemy) || (_tiles[y][x].hasNPC) || (_tiles[y][x].hasTreasure))
                    {
                        ClearTile(x, y);
                    }

                }
            }

            Backend.Coords pos = new Backend.Coords(2 + r.Next(_width - 4), 2 + r.Next(_height - 4));
            for (int x = -1; x < 2; ++x)
            {
                for (int y = -1; y < 2; ++y)
                {
                    ClearTile(pos.x + x, pos.y + y);

                }
            }

            Enemy boss = new Enemy(-1, -1, -1, -1, "", r, 10 + _level);
            if (r.NextDouble() >= 0.5)
            {
                boss.fireDefense = 70;
                boss.fireDamage += r.Next(10);
            }
            else
            {
                boss.iceDefense = 70;
                boss.iceDamage += r.Next(10);
            }
            ActorTile BossTile = new ActorTile(_tiles[pos.y][pos.x], boss);
            boss.tile = BossTile;
            _tiles[pos.y][pos.x].Add(BossTile);
            _actors.Add(boss);
            if (_level == 1) _music = "boss1.wav"; else _music = "boss2.wav";
        }