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


C# Column.Add方法代码示例

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


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

示例1: ImportLevel

        /// <summary>
        /// Imports a level file. You can read the Level file format description on this file header
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Exception Loading level file:  + path</exception>
        public LevelModel ImportLevel(string path)
        {
            string line = string.Empty;
            BlockTypeEnum blockType = BlockTypeEnum.EMPTY;

            LevelModel model = new LevelModel();

            try
            {
                // Read the level file
                using (Stream fs = WaveServices.Storage.OpenContentFile(path))
                //using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read))
                using (BufferedStream bs = new BufferedStream(fs, 8388608)) // 8Mb buffer it's a good buffer for files.
                using (StreamReader sr = new StreamReader(bs))
                {
                    float blockScaleX = 1.0f;
                    float blockScaleY = 1.0f;
                    float blockScaleZ = 1.0f;

                    // FIRST LINE of the file: Block X scale
                    if (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        float.TryParse(line, NumberStyles.Number, CultureInfo.InvariantCulture, out blockScaleX);
                        ModelFactoryService.Instance.Scale.X= blockScaleX;
                    }

                    // SECOND LINE of the file: Block Y Scale
                    if (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        float.TryParse(line, NumberStyles.Number, CultureInfo.InvariantCulture, out blockScaleY);
                        ModelFactoryService.Instance.Scale.Y = blockScaleY;
                    }

                    // THIRD LINE of the file: Block Z Scale
                    if (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();
                        float.TryParse(line, NumberStyles.Number, CultureInfo.InvariantCulture, out blockScaleZ);
                        ModelFactoryService.Instance.Scale.Z = blockScaleZ;
                    }

                    // The rest of the file is the level
                    while (!sr.EndOfStream)
                    {
                        line = sr.ReadLine();

                        if(!string.IsNullOrWhiteSpace(line)) // line must be filled with data
                        {
                            string[] splitted = line.Split(SEPARATOR); // split the line
                            if(splitted.Count() > 0)
                            {
                                Column column = new Column(); // creates the column
                                foreach(string value in splitted)
                                {
                                    blockType = BlockTypeEnum.EMPTY; // default value if reading error or out of block type error
                                    Enum.TryParse<BlockTypeEnum>(value, out blockType);
                                    column.Add(blockType);
                                }
                                model.ColumnCollection.Enqueue(column);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception Loading level file: " + path, ex);
            }

            return model;
        }
开发者ID:dezol,项目名称:QuickStarters,代码行数:79,代码来源:ImportService.cs


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