You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.IO.Pipes;
  2. using Microsoft.Extensions.Options;
  3. using uqac_ia_aspirobot.Interfaces;
  4. namespace uqac_ia_aspirobot.Common
  5. {
  6. public class ArClient
  7. {
  8. private readonly ArConfig _options;
  9. private NamedPipeClientStream _client;
  10. private ArStreamString _stream;
  11. public ArClient(IOptions<ArConfig> options)
  12. {
  13. _options = options.Value;
  14. }
  15. public void Setup()
  16. {
  17. _client = new NamedPipeClientStream(_options.PipeServer, _options.PipeName, PipeDirection.InOut);
  18. _client.Connect();
  19. _stream = new ArStreamString(_client);
  20. }
  21. public int GetEnvWidth()
  22. {
  23. _stream.Write(ArServer.ArCommands.EnvGetWidth);
  24. return _stream.ReadInt();
  25. }
  26. public RoomState GetRoomState(int x, int y)
  27. {
  28. _stream.Write(ArServer.ArCommands.RoomGetState);
  29. _stream.Write(x);
  30. _stream.Write(y);
  31. return _stream.ReadEnum<RoomState>();
  32. }
  33. public void RemoveDust(int x, int y)
  34. {
  35. _stream.Write(ArServer.ArCommands.RoomRemoveDust);
  36. _stream.Write(x);
  37. _stream.Write(y);
  38. }
  39. public void RemoveJewel(int x, int y)
  40. {
  41. _stream.Write(ArServer.ArCommands.RoomRemoveJewel);
  42. _stream.Write(x);
  43. _stream.Write(y);
  44. }
  45. }
  46. }