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.

EnvEnvironment.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Microsoft.Extensions.Options;
  5. using uqac_ia_aspirobot.Interfaces;
  6. namespace uqac_ia_aspirobot.Environment
  7. {
  8. public class EnvEnvironment : IEnvironment
  9. {
  10. private readonly IServiceProvider _serviceProvider;
  11. private readonly EnvConfig _options;
  12. protected readonly IDictionary<string, IRoom> _rooms = new Dictionary<string, IRoom>();
  13. protected string GetKey(int x, int y)
  14. {
  15. return $"{x},{y}";
  16. }
  17. public EnvEnvironment(IServiceProvider serviceProvider, IOptions<EnvConfig> options)
  18. {
  19. _serviceProvider = serviceProvider;
  20. _options = options.Value;
  21. }
  22. public void Setup()
  23. {
  24. for (var x = 0; x < _options.Width; ++x)
  25. {
  26. for (var y = 0; y < _options.Height; ++y)
  27. {
  28. var room = _serviceProvider.GetService<IRoom>();
  29. room.X = x;
  30. room.Y = y;
  31. _rooms.Add(GetKey(x, y), room);
  32. }
  33. }
  34. }
  35. public int GetWidth()
  36. {
  37. return _options.Width;
  38. }
  39. public int GetHeight()
  40. {
  41. return _options.Height;
  42. }
  43. public IRoom GetRoom(int x, int y)
  44. {
  45. return _rooms[GetKey(x, y)];
  46. }
  47. }
  48. }