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


C# BinaryWriter.WriteField方法代码示例

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


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

示例1: SaveMissions

 public static void SaveMissions(this PlayerModel player, BinaryWriter writer)
 {
     foreach (var mission in player.Missions)
     {
         writer.Write(mission.Id);
         writer.WriteField(SaveField.CustomDate, mission.Date);
         writer.Write(mission.ClientName.PadRight(10, ' ').ToCharArray());
         writer.Write((short)mission.RewardAmount);
         writer.Write((byte)mission.Type);
         writer.Write((byte)mission.Difficulty);
         writer.Write((byte)mission.TargetStarSystem.Coords.Y);
         writer.Write((byte)mission.TargetStarSystem.Coords.X);
         switch (mission.Type)
         {
             case MissionType.PackageDelivery:	writer.Write(mission.PackageDescription.PadRight(20).ToCharArray());	break;
             case MissionType.GoodsDelivery	:	writer.Write((byte)mission.GoodsToDeliver_Type);	writer.Write((byte)mission.GoodsToDeliver_Amount);	break;
             case MissionType.Assassination	:	mission.AssassinationTarget.Save(writer);	break;
         }
     }
 }
开发者ID:ZeroByte1987,项目名称:ConsoleGames,代码行数:20,代码来源:SaveLoad.cs

示例2: Save

        public static void Save(this GalaxyModel galaxy, BinaryWriter writer)
        {
            var galaxySizeX = galaxy.StarSystems.GetLength(1);
            var galaxySizeY = galaxy.StarSystems.GetLength(0);
            writer.WriteField(SaveField.GameDate,		galaxy.GameDate);
            writer.WriteField(SaveField.LastEventDate,	galaxy.LastEventDate);
            writer.WriteField(SaveField.RandomSeed,	0);	writer.Write(galaxy.RandomSeed);
            writer.WriteField(SaveField.AlienStrength,	(int)galaxy.AlienStrength);
            writer.WriteField(SaveField.StarSystems,	(galaxySizeX << 8) + galaxySizeY);

            #region Star System Array

            for (var i = 0; i < galaxySizeY; i++)
                for (var j = 0; j < galaxySizeX; j++)
                {
                    var starSystem = galaxy.StarSystems[i,j];
                    writer.WriteField(SaveField.StarName,		starSystem.Name);
                    writer.WriteField(SaveField.TechLevel,		starSystem.TechLevel);
                    writer.WriteField(SaveField.IsExplored,		starSystem.IsExplored);
                    writer.WriteField(SaveField.Allegiance,		(int)starSystem.Allegiance);
                    writer.WriteField(SaveField.CurrentEvent,	(int)starSystem.CurrentEvent);
                    writer.WriteField(SaveField.EventDuration,	starSystem.EventDuration);

                    writer.WriteField(SaveField.GoodsLegality,	Enums.All_Merchandise.Count);
                    foreach (var merch in Enums.All_Merchandise)
                        writer.Write((byte)(starSystem.IllegalGoods.Contains(merch) ? 1 : 0));

                    writer.WriteField(SaveField.PriceDeviations, Enums.All_Merchandise.Count);
                    for (var k = 0; k < Enums.All_Merchandise.Count; k++)
                        writer.Write((sbyte)(starSystem.PriceChanges[k]));

                    writer.WriteField(SaveField.StarSystemDataEnd,	0);
                }

            #endregion

            #region Global Event Log

            writer.WriteField(SaveField.GlobalEventsLog,	galaxy.GlobalEventLog.Count);
            foreach (var t in galaxy.GlobalEventLog)
            {
                writer.Write((byte)t.StarSystemIndex);
                writer.Write((byte)t.Event);
                writer.Write((short)t.EventValue);
                writer.WriteField(SaveField.CustomDate, t.EventDate);
            }

            #endregion

            writer.WriteField(SaveField.GalaxyDataEnd,	0);
        }
开发者ID:ZeroByte1987,项目名称:ConsoleGames,代码行数:51,代码来源:SaveLoad.cs


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