本文整理汇总了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;
}
}
}
示例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);
}