Пример #1
0
        private static Door buildDoor(Wall wall, Node node)
        {
            Door door;

            if (node is Pair)
                door = new Door(wall, ((Pair)node).value);
            else
            {
                door = new Door(wall, "");

                foreach (Node n in node.children)
                {
                    if (n is Pair)
                    {
                        Pair p = (Pair)n;

                        if (p.name.Equals("Target", StringComparison.OrdinalIgnoreCase))
                            door.name = p.value;
                        else if (p.name.Equals("Locked", StringComparison.OrdinalIgnoreCase))
                            door.locked = bool.Parse(p.value);
                        else if (p.name.Equals("Visible", StringComparison.OrdinalIgnoreCase))
                            door.visible = bool.Parse(p.value);
                        else if (p.name.Equals("Description", StringComparison.OrdinalIgnoreCase))
                            door.description = p.value;
                    }
                }
            }

            return door;
        }
Пример #2
0
        public Room(string name)
        {
            this.name = name;

            north = new Wall(this, "north");
            east = new Wall(this, "east");
            south = new Wall(this, "south");
            west = new Wall(this, "west");

            center = new Wall(this, "center");
        }
Пример #3
0
 public Door(Wall parent, string target)
     : base(parent, target)
 {
     update();
 }
Пример #4
0
        public Item(Wall parent, string name)
        {
            this.parent = parent;
            this.name = name;

            children = new List<Item>();
            aliases = new List<string>();

            commands = new Dictionary<string, Command>();
        }
Пример #5
0
 public void setWall(Direction direction, Wall wall)
 {
     switch (direction)
     {
         case Direction.NORTH: north = wall; break;
         case Direction.SOUTH: south = wall; break;
         case Direction.EAST: east = wall; break;
         case Direction.WEST: west = wall; break;
     }
 }
Пример #6
0
        private static Item buildItem(Player player, Wall wall, Node node)
        {
            Item item = new Item(wall, node.name);

            bool hasDescription = false;

            List<string> commands = new List<string>();
            commands.Add("use");
            commands.Add("examine");

            foreach (Node n in node.children)
            {
                if (n is Pair)
                {
                    Pair p = (Pair)n;

                    if (p.name.Equals("Description", StringComparison.OrdinalIgnoreCase))
                    {
                        item.description = p.value;
                        hasDescription = true;
                    }
                    else if (p.name.Equals("Takeable", StringComparison.OrdinalIgnoreCase))
                        item.takeable = bool.Parse(p.value);
                    else if (p.name.Equals("UseIfNotEquipped", StringComparison.OrdinalIgnoreCase))
                        item.useIfNotEquipped = bool.Parse(p.value);
                    else if (p.name.Equals("Visible", StringComparison.OrdinalIgnoreCase))
                        item.visible = bool.Parse(p.value);
                    else if (p.name.Equals("Detail", StringComparison.OrdinalIgnoreCase))
                        item.detail = p.value;
                    else if (p.name.Equals("Alias", StringComparison.OrdinalIgnoreCase))
                    {
                        string[] aliases = p.value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                        foreach (string s in aliases)
                            item.addAlias(s.Trim());
                    }
                    else if (p.name.Equals("Commands", StringComparison.OrdinalIgnoreCase))
                    {
                        string[] cs = p.value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                        foreach (string s in cs)
                            commands.Add(s.Trim());
                    }
                    else if (commands.Contains(p.name))
                    {
                        item.addCommand(p.name, createCommand(player, item, p.value, null));
                    }
                }
                else
                {
                    if (!n.name.Equals("Children", StringComparison.OrdinalIgnoreCase))
                        throw new InvalidDataException("Cannot have a node under an item except for Children.");

                    item.addAll(buildItems(player, wall, n));
                }
            }

            if (!hasDescription)
                throw new InvalidDataException("No description found in Item.");

            return item;
        }
Пример #7
0
        private static void buildWall(Player player, Wall wall, Node node)
        {
            foreach (Node n in node.children)
            {
                if (n.name.Equals("Door", StringComparison.OrdinalIgnoreCase))
                    wall.door = buildDoor(wall, n);
            }

            wall.items = buildItems(player, wall, node);
        }
Пример #8
0
        private static List<Item> buildItems(Player player, Wall wall, Node node)
        {
            List<Item> items = new List<Item>();

            foreach (Node n in node.children)
            {
                if (n.name.Equals("Door", StringComparison.OrdinalIgnoreCase))
                    continue;

                if (n is Pair)
                    throw new InvalidDataException("Cannot have a free standing pair under Items");
                else
                    items.Add(buildItem(player, wall, n));
            }

            return items;
        }