当前位置: 首页>>代码示例>>C#>>正文


C# Tokenizer.GetKeywordName方法代码示例

本文整理汇总了C#中Tokenizer.GetKeywordName方法的典型用法代码示例。如果您正苦于以下问题:C# Tokenizer.GetKeywordName方法的具体用法?C# Tokenizer.GetKeywordName怎么用?C# Tokenizer.GetKeywordName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tokenizer的用法示例。


在下文中一共展示了Tokenizer.GetKeywordName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadItems

        public static void LoadItems()
        {
            Game.Instance.Log("Loading items...");

            string path = "../../System/items.txt";

            Tokenizer t = new Tokenizer();
            int errors = 0;

            t.AddKeywords(new TupleList<string, Type>{
                {"weapon", Type.Weapon},
                {"gun", Type.Gun},
                {"armor", Type.Armor},
                {"potion", Type.Potion},
                {"ammo", Type.Ammo},
                {"other", Type.Other}
            });

            t.AddKeywords(new TupleList<string, Keyword>{
                {"name", Keyword.Name},
                {"desc", Keyword.Desc},
                {"value", Keyword.Value},
                {"weight", Keyword.Weight},
                {"attack", Keyword.Attack},
                {"defense", Keyword.Defense},
                {"subtype", Keyword.Subtype},
                {"material", Keyword.Material},
                {"range", Keyword.Range},
                {"capacity", Keyword.Capacity}
            });

            t.AddKeywords(new TupleList<string, WeaponType>{
                {"slash", WeaponType.Slash},
                {"pierce", WeaponType.Pierce},
                {"blunt", WeaponType.Blunt}
            });

            t.AddKeywords(new TupleList<string, Material>{
                {"wood", Material.Wood},
                {"iron", Material.Iron},
                {"steel", Material.Steel},
                {"silver", Material.Silver}
            });

            t.AddKeywords(new TupleList<string, AmmoType>{
                {"bullet9mm", AmmoType.Bullet9mm}
            });

            if (!t.FromFile(path))
                throw new Exception(string.Format("Failed to open file \"{0}\".", path));

            try
            {
                while(t.Next())
                {
                retry:
                    try
                    {

                        Item item = new Item();

                        // type
                        item.type = t.GetKeyword<Type>();
                        t.Next();

                        // id
                        item.id = t.GetItem();
                        t.Next();

                        // {
                        t.AssertSymbol('{');
                        t.Next();

                        bool[] have = new bool[(int)Keyword.Max];

                        while(true)
                        {
                            if (t.IsSymbol('}'))
                                break;

                            Keyword key = t.GetKeyword<Keyword>();
                            string key_name = t.GetKeywordName();
                            t.Next();

                            if(have[(int)key])
                                throw new Exception(string.Format("Item '{0}' already have {1}.", item.id, key_name));
                            have[(int)key] = true;

                            if(!CanHave(item.type, key))
                                throw new Exception(string.Format("Item '{0}' can't have {1}.", item.id, key_name));

                            switch(key)
                            {
                                case Keyword.Name:
                                    item.name = t.GetString();
                                    break;
                                case Keyword.Desc:
                                    item.desc = t.GetString();
                                    break;
                                case Keyword.Value:
//.........这里部分代码省略.........
开发者ID:Tomash667,项目名称:hunters,代码行数:101,代码来源:Item.cs


注:本文中的Tokenizer.GetKeywordName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。