send scores to big display
This commit is contained in:
parent
a89392beb8
commit
7f00160780
1 changed files with 305 additions and 126 deletions
64
TanksServer/ServicePointDisplay/DisplayBufferView.cs
Normal file
64
TanksServer/ServicePointDisplay/DisplayBufferView.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
using TanksServer.Models;
|
||||
|
||||
namespace TanksServer.ServicePointDisplay;
|
||||
|
||||
internal class DisplayBufferView(byte[] data)
|
||||
{
|
||||
public byte[] Data => data;
|
||||
|
||||
public ushort Mode
|
||||
{
|
||||
get => GetTwoBytes(0);
|
||||
set => SetTwoBytes(0, value);
|
||||
}
|
||||
|
||||
public ushort TileX
|
||||
{
|
||||
get => GetTwoBytes(2);
|
||||
set => SetTwoBytes(2, value);
|
||||
}
|
||||
|
||||
public ushort TileY
|
||||
{
|
||||
get => GetTwoBytes(4);
|
||||
set => SetTwoBytes(4, value);
|
||||
}
|
||||
|
||||
public ushort WidthInTiles
|
||||
{
|
||||
get => GetTwoBytes(6);
|
||||
set => SetTwoBytes(6, value);
|
||||
}
|
||||
|
||||
public ushort RowCount
|
||||
{
|
||||
get => GetTwoBytes(8);
|
||||
set => SetTwoBytes(8, value);
|
||||
}
|
||||
|
||||
public TilePosition Position
|
||||
{
|
||||
get => new(TileX, TileY);
|
||||
set
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(value.X, ushort.MaxValue);
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(value.Y, ushort.MaxValue);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(value.X);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(value.Y);
|
||||
|
||||
TileX = (ushort)value.X;
|
||||
TileY = (ushort)value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
private ushort GetTwoBytes(int index)
|
||||
{
|
||||
return (ushort)(data[index] * byte.MaxValue + data[index + 1]);
|
||||
}
|
||||
|
||||
private void SetTwoBytes(int index, ushort value)
|
||||
{
|
||||
data[index] = (byte)(value / byte.MaxValue);
|
||||
data[index + 1] = (byte)(value % byte.MaxValue);
|
||||
}
|
||||
}
|
||||
Reference in a new issue