Example #1
0
        public WorldObjects ToEntity(State state)
        {
            var worldObjects = new WorldObjects(state);

            foreach (var worldObjectsXml in this)
            {
                worldObjects.Add(worldObjectsXml.ToEntity(state));
            }

            return(worldObjects);
        }
Example #2
0
 public void AddObject(WorldObject obj)
 {
     WorldObjects.Add(obj);
     if (obj is IPlayer)
     {
         Player = (IPlayer)obj;
     }
     if (obj is IDynamicObject)
     {
         DynamicObjects.Add((IDynamicObject)obj);
     }
 }
Example #3
0
        private void SetPlayers(Player[] players)
        {
            TotalPlayers = players.Length;
            PlayerList   = players;
            var i = 0;

            foreach (var player in players)
            {
                player.CurrentNode    = StartingNode;
                player.ActualLocation = StartingNode.GetTravelPosition(i, TotalPlayers);
                WorldObjects.Add(player);
                i++;
            }
        }
Example #4
0
        /// <summary>
        /// Used in the default world generator to add objects to the world at pseudo-random locations.
        /// </summary>
        /// <param name="randomifier">A pseudo random number. If the number is divisible by 10 and the remainder is 0 you place a mountain
        /// else if you divide by 8 and the remainder is 0 you get an item, else if you divide by 2 and the remainder is 0 you place a creature.</param>
        /// <param name="x">x coordinate for the object</param>
        /// <param name="y">y coordinate for the object</param>
        protected virtual void PlaceObject(int randomifier, int x, int y)
        {
            if (WorldObjects.Contains(WorldObjects.Find(obj => obj.Position == new Point(x, y))))
            {
                return;
            }
            if (Creatures.Contains(Creatures.Find(obj => obj.Position == new Point(x, y))))
            {
                return;
            }

            if (randomifier % 10 == 0)
            {
                WorldObjects.Add(new ImpassableTerrain("Mountain", new Point(x, y)));
            }
            else if (randomifier % 8 == 0)
            {
                WorldObjects.Add(new InteractableWorldObject(new Item("Angel Statue"), new Point(x, y)));
            }
            else if (randomifier % 2 == 0)
            {
                Random       random = new Random();
                BaseCreature creature;
                switch (random.Next(0, 3))
                {
                case 0:
                    creature = _premadeCreatures.Centaur;
                    break;

                case 1:
                    creature = _premadeCreatures.Goblin;
                    break;

                case 2:
                    creature = _premadeCreatures.Mage;
                    break;

                default:
                    creature = _premadeCreatures.Peasant;
                    break;
                }

                creature.Position = new Point(x, y);
                creature.Attach(this);
                Creatures.Add(creature);
            }
        }