當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。