controls string on server side
This commit is contained in:
parent
603a53eef7
commit
7bc45d1d58
3 changed files with 22 additions and 27 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Net.WebSockets;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using TanksServer.GameLogic;
|
||||
|
||||
|
@ -51,7 +52,7 @@ internal sealed class PlayerInfoConnection(
|
|||
var tankInfo = tank != null
|
||||
? new TankInfo(tank.Orientation, tank.ExplosiveBullets, tank.Position.ToPixelPosition(), tank.Moving)
|
||||
: null;
|
||||
var info = new PlayerInfo(player.Name, player.Scores, player.Controls, tankInfo);
|
||||
var info = new PlayerInfo(player.Name, player.Scores, ControlsToString(player.Controls), tankInfo);
|
||||
var response = JsonSerializer.SerializeToUtf8Bytes(info, _context.PlayerInfo);
|
||||
|
||||
if (response.SequenceEqual(_lastMessage))
|
||||
|
@ -60,5 +61,22 @@ internal sealed class PlayerInfoConnection(
|
|||
return _lastMessage = response;
|
||||
}
|
||||
|
||||
private static string ControlsToString(PlayerControls controls)
|
||||
{
|
||||
var str = new StringBuilder("[ ");
|
||||
if (controls.Forward)
|
||||
str.Append("▲ ");
|
||||
if (controls.Backward)
|
||||
str.Append("▼ ");
|
||||
if (controls.TurnLeft)
|
||||
str.Append("◄ ");
|
||||
if (controls.TurnRight)
|
||||
str.Append("► ");
|
||||
if (controls.Shoot)
|
||||
str.Append("• ");
|
||||
str.Append(']');
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
public void Dispose() => _wantedFrames.Dispose();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,6 @@ internal sealed record class TankInfo(
|
|||
internal sealed record class PlayerInfo(
|
||||
string Name,
|
||||
Scores Scores,
|
||||
PlayerControls Controls,
|
||||
string Controls,
|
||||
TankInfo? Tank
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue