Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public CreatureCommand Act(int x, int y)
  2. {
  3. var diggersLocation = FindDigger();
  4. if (diggersLocation != null)
  5. {
  6. var deltaX = Math.Sign(diggersLocation.Item1 - x);
  7. var deltaY = Math.Sign(diggersLocation.Item2 - y);
  8. if (deltaX != 0 && CanMove(x + deltaX, y))
  9. return new CreatureCommand { DeltaX = deltaX };
  10. if (deltaY != 0 && CanMove(x, y + deltaY))
  11. return new CreatureCommand { DeltaY = deltaY };
  12. }
  13. return new CreatureCommand();
  14. }
  15.  
  16. public bool CanMove(int x, int y)
  17. {
  18. return !(Game.Map[x, y] is Terrain
  19. || Game.Map[x, y] is Monster
  20. || Game.Map[x, y] is Sack);
  21. }
  22.  
  23. public Tuple<int, int> FindDigger()
  24. {
  25. for (var x = 0; x < Game.MapWidth; x++)
  26. for (var y = 0; y < Game.MapHeight; y++)
  27. {
  28. if (Game.Map[x, y] is Player)
  29. {
  30. return Tuple.Create(x, y);
  31. }
  32. }
  33. return null;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement