本文整理汇总了C#中Message.GetByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# Message.GetByteArray方法的具体用法?C# Message.GetByteArray怎么用?C# Message.GetByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.GetByteArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseWorld
private WorldBlock[,,] ParseWorld(Message m, int sizeX, int sizeY, uint offset)
{
// Find the start of the world
uint start = 0;
for (uint i = offset; i <= m.Count - 1; i++)
{
if (m[i] as string != null && m.GetString(i) == "ws")
{
start = i + 1;
break;
}
}
// Generate an empty world
WorldBlock[,,] worldArray = GetEmptyWorld(sizeX, sizeY, Block.GravityNothing, Block.GravityNothing);
// Parse the world data
uint pointer = start;
do
{
// Exit once we reached the end
if (m[pointer] as string != null && m.GetString(pointer) == "we")
break;
var block = (Block)m.GetInteger(pointer++);
int l = m.GetInteger(pointer++);
byte[] byteArrayX = m.GetByteArray(pointer++);
byte[] byteArrayY = m.GetByteArray(pointer++);
switch (block)
{
case Block.CoinDoor:
case Block.CoinGate:
uint coinsToCollect = m.GetUInt(pointer++);
for (int i = 0; i <= byteArrayX.Length - 1; i += 2)
{
int x = byteArrayX[i] * 256 + byteArrayX[i + 1];
int y = byteArrayY[i] * 256 + byteArrayY[i + 1];
worldArray[l, x, y].SetCoinDoor((CoinDoorBlock)block, coinsToCollect);
}
break;
case Block.MusicPiano:
case Block.MusicDrum:
uint soundId = m.GetUInt(pointer++);
for (int i = 0; i <= byteArrayX.Length - 1; i += 2)
{
int x = byteArrayX[i] * 256 + byteArrayX[i + 1];
int y = byteArrayY[i] * 256 + byteArrayY[i + 1];
worldArray[l, x, y].SetSound((SoundBlock)block, soundId);
}
break;
case Block.HazardSpike:
case Block.DecorSciFi2013BlueSlope:
case Block.DecorSciFi2013BlueStraight:
case Block.DecorSciFi2013YellowSlope:
case Block.DecorSciFi2013YellowStraight:
case Block.DecorSciFi2013GreenSlope:
case Block.DecorSciFi2013GreenStraight:
uint rotation = m.GetUInt(pointer++);
for (int i = 0; i <= byteArrayX.Length - 1; i += 2)
{
int x = byteArrayX[i] * 256 + byteArrayX[i + 1];
int y = byteArrayY[i] * 256 + byteArrayY[i + 1];
worldArray[l, x, y].SetRotatable((RotatableBlock)block, rotation);
}
break;
case Block.Portal:
case Block.InvisiblePortal:
var portalRotation = (PortalRotation)m.GetUInt(pointer++);
uint portalId = m.GetUInt(pointer++);
uint portalTarget = m.GetUInt(pointer++);
for (int i = 0; i <= byteArrayX.Length - 1; i += 2)
{
int x = byteArrayX[i] * 256 + byteArrayX[i + 1];
int y = byteArrayY[i] * 256 + byteArrayY[i + 1];
worldArray[l, x, y].SetPortal((PortalBlock)block, portalId, portalTarget, portalRotation);
}
break;
case Block.WorldPortal:
string worldPortalTarget = m.GetString(pointer++);
for (int i = 0; i <= byteArrayX.Length - 1; i += 2)
{
int x = byteArrayX[i] * 256 + byteArrayX[i + 1];
int y = byteArrayY[i] * 256 + byteArrayY[i + 1];
worldArray[l, x, y].SetWorldPortal((WorldPortalBlock)block, worldPortalTarget);
}
break;
case Block.DecorSign:
case Block.DecorLabel:
string text = m.GetString(pointer++);
//.........这里部分代码省略.........
示例2: GetWorld
internal static BlockDataWorld GetWorld(Message m, int width, int height, uint offset = InitOffset)
{
var world = new BlockDataWorld(width, height);
uint pointer = GetStart(m, offset);
string strValue2;
while ((strValue2 = m[pointer] as string) == null || strValue2 != "we")
{
var block = m.GetInteger(pointer++);
var l = (Layer)m.GetInteger(pointer++);
byte[] byteArrayX = m.GetByteArray(pointer++);
byte[] byteArrayY = m.GetByteArray(pointer++);
switch (l)
{
case Layer.Background:
var bgWorldBlock = new BackgroundBlock((Background.Id)block);
foreach (Point pos in GetPos(byteArrayX, byteArrayY))
world.Background[pos.X, pos.Y] = new BlockData<BackgroundBlock>(bgWorldBlock);
break;
case Layer.Foreground:
ForegroundBlock foregroundBlock;
BlockArgsType blockArgsType = WorldUtils.GetBlockArgsType(WorldUtils.GetForegroundType(id: (Foreground.Id)block));
switch (blockArgsType)
{
case BlockArgsType.None:
foregroundBlock = new ForegroundBlock((Foreground.Id)block);
break;
case BlockArgsType.Number:
uint i = m.GetUInt(pointer++);
foregroundBlock = new ForegroundBlock((Foreground.Id)block, i);
break;
case BlockArgsType.String:
string str = m.GetString(pointer++);
foregroundBlock = new ForegroundBlock((Foreground.Id)block, str);
break;
case BlockArgsType.Portal:
var portalRotation = (Morph.Id)m.GetUInt(pointer++);
uint portalId = m.GetUInt(pointer++);
uint portalTarget = m.GetUInt(pointer++);
foregroundBlock = new ForegroundBlock((Foreground.Id)block, portalId, portalTarget, portalRotation);
break;
case BlockArgsType.Label:
string text = m.GetString(pointer++);
string textcolor = m.GetString(pointer++);
foregroundBlock = new ForegroundBlock((Foreground.Id)block, text, textcolor);
break;
default:
throw new NotSupportedException("Invalid block.");
}
var fg = new BlockData<ForegroundBlock>(foregroundBlock);
foreach (Point pos in GetPos(byteArrayX, byteArrayY))
world.Foreground[pos.X, pos.Y] = fg;
break;
}
}
return world;
}
示例3: Connection_OnMessage
/// <summary>
/// Handles all incoming PlayerIO messages
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="m">The message.</param>
static void Connection_OnMessage(object sender, Message m)
{
if (m.Type != "init")
return;
Console.WriteLine("Inited");
globalConn.Disconnect();
Minimap minimap = new Minimap();
minimap.width = m.GetInt(15);
minimap.height = m.GetInt(16);
minimap.initialize();
Console.WriteLine("Parsing init data...");
uint p = 22;
while (m[p] as string != "ws") p++;
p++;
// Parse world data
while (p < m.Count) {
uint blockId = m.GetUInt(p);
int layer = m.GetInt(p + 1);
byte[] xs = m.GetByteArray(p + 2),
ys = m.GetByteArray(p + 3);
for (var b = 0; b < xs.Length; b += 2) {
int nx = (xs[b] << 8) | xs[b + 1],
ny = (ys[b] << 8) | ys[b + 1];
minimap.drawBlock(layer, nx, ny, blockId);
}
p += 4;
if (m[p] as string == "we")
break;
while (p + 3 < m.Count) {
if (m[p + 2] is byte[])
break;
p++;
}
}
minimap.rewriteForegroundBlocks();
minimap.Save(worldID + ".png");
generating_minimap = false;
}
示例4: ParseWorld
private WorldBlock[,,] ParseWorld(Message m, int sizeX, int sizeY, uint offset)
{
// Find the start of the world
uint start = 0;
for (uint i = offset; i <= m.Count - 1; i++)
{
string strValue;
if ((strValue = m[i] as string) != null && strValue == "ws")
{
start = i + 1;
break;
}
}
// Generate an empty world
WorldBlock[,,] worldArray = this.GetEmptyWorld(sizeX, sizeY);
// Parse the world data
uint pointer = start;
string strValue2;
while ((strValue2 = m[pointer] as string) == null || strValue2 != "we")
{
var block = (Block)m.GetInteger(pointer++);
int l = m.GetInteger(pointer++);
try
{
byte[] byteArrayX = m.GetByteArray(pointer++);
byte[] byteArrayY = m.GetByteArray(pointer++);
IEnumerable<WorldBlock> wblocks = this.GetBlocks(l, byteArrayX, byteArrayY, worldArray);
if (BlockUtils.IsCoinDoorOrGate(block))
{
uint coinsToCollect = m.GetUInt(pointer++);
foreach (WorldBlock wblock in wblocks)
wblock.SetCoinDoor((CoinDoorBlock)block, coinsToCollect);
}
else if (BlockUtils.IsPurpleDoorOrGateOrSwitch(block))
{
uint purpleId = m.GetUInt(pointer++);
foreach (WorldBlock wblock in wblocks)
wblock.SetPurpleDoor((PurpleDoorBlock)block, purpleId);
}
else if (BlockUtils.IsDeathDoorOrGate(block))
{
uint deathsRequired = m.GetUInt(pointer++);
foreach (WorldBlock wblock in wblocks)
wblock.SetDeathDoor((DeathDoorBlock)block, deathsRequired);
}
else if (BlockUtils.IsSound(block))
{
uint soundId = m.GetUInt(pointer++);
foreach (WorldBlock wblock in wblocks)
wblock.SetSound((SoundBlock)block, soundId);
}
else if (BlockUtils.IsRotatable(block))
{
uint rotation = m.GetUInt(pointer++);
foreach (WorldBlock wblock in wblocks)
wblock.SetRotatable((RotatableBlock)block, rotation);
}
else if (BlockUtils.IsPortal(block))
{
var portalRotation = (PortalRotation)m.GetUInt(pointer++);
uint portalId = m.GetUInt(pointer++);
uint portalTarget = m.GetUInt(pointer++);
foreach (WorldBlock wblock in wblocks)
wblock.SetPortal((PortalBlock)block, portalId, portalTarget, portalRotation);
}
else if (BlockUtils.IsWorldPortal(block))
{
string worldPortalTarget = m.GetString(pointer++);
foreach (WorldBlock wblock in wblocks)
wblock.SetWorldPortal((WorldPortalBlock)block, worldPortalTarget);
}
else if (BlockUtils.IsSign(block))
{
string text = m.GetString(pointer++);
foreach (WorldBlock wblock in wblocks)
wblock.SetSign((SignBlock)block, text);
}
else if (BlockUtils.IsLabel(block))
{
string text = m.GetString(pointer++);
string textColor = m.GetString(pointer++);
foreach (WorldBlock wblock in wblocks)
wblock.SetLabel((LabelBlock)block, text, textColor);
}
else
{
foreach (WorldBlock wblock in wblocks)
wblock.SetBlock(block);
}
}
catch (Exception ex)
{
this.Logger.Log(LogPriority.Error,
"Exception when parsing block {0} on layer {1}. The error was: {2}", block, l, ex.Message);
//.........这里部分代码省略.........
示例5: Load2Array
/// <summary>
///
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
private Pixel[,] Load2Array(Message e)
{
Pixel[,] array = MapData;
int w = array.GetLength(0);
int h = array.GetLength(1);
for (int yn = 0; yn < h; yn++)
{
for (int xn = 0; xn < w; xn++)
{
array[xn, yn] = new Pixel();
}
}
byte[] xarray, yarray;
int x, y;
int id;
uint n = 0;
while (n < e.Count)
{
if (e.GetString(n) == "ws")
break;
n++;
}
n++;
while (n < e.Count)
{
if (e.GetString(n) == "we")
break;
id = e.GetInt(n);
xarray = e.GetByteArray(n + 2);
yarray = e.GetByteArray(n + 3);
for (int i = 0; i < xarray.Length; i += 2)
{
x = xarray[i] << 8 | xarray[i + 1];
y = yarray[i] << 8 | yarray[i + 1];
if (id < 500) array[x, y].Foreground = id;
if (id >= 500) array[x, y].Background = id;
switch (id)
{
case 43:
case 165:
array[x, y].Coins = e.GetInt(n + 4);
n += 5;
break;
case 77:
case 83:
array[x, y].Sound = e.GetInt(n + 4);
n += 5;
break;
case 242:
array[x, y].Rotation = e.GetInt(n + 4);
array[x, y].ThisID = e.GetInt(n + 5);
array[x, y].TargetID = e.GetInt(n + 6);
n += 7;
break;
default:
n += 4;
break;
}
}
}
return array;
}