FieldPos.cs 933 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // $Id$
  2. namespace DataStructures
  3. {
  4. public struct FieldPos
  5. {
  6. public int X;
  7. public int Y;
  8. public FieldPos(int X, int Y)
  9. {
  10. this.X = X;
  11. this.Y = Y;
  12. }
  13. public static bool operator ==(FieldPos p1, FieldPos p2)
  14. {
  15. return p1.X == p2.X && p1.Y == p2.Y;
  16. }
  17. public static bool operator !=(FieldPos p1, FieldPos p2)
  18. {
  19. return p1.X != p2.X || p1.Y != p2.Y;
  20. }
  21. public override bool Equals(object obj)
  22. {
  23. if (!(obj is FieldPos))
  24. return false;
  25. FieldPos pos = (FieldPos) obj;
  26. return this == pos;
  27. }
  28. public override int GetHashCode()
  29. {
  30. return base.GetHashCode();
  31. }
  32. public FieldPos Up
  33. {
  34. get {
  35. return new FieldPos(X, Y-1);
  36. }
  37. }
  38. public FieldPos Down
  39. {
  40. get {
  41. return new FieldPos(X, Y+1);
  42. }
  43. }
  44. public FieldPos Left
  45. {
  46. get {
  47. return new FieldPos(X-1, Y);
  48. }
  49. }
  50. public FieldPos Right
  51. {
  52. get {
  53. return new FieldPos(X+1, Y);
  54. }
  55. }
  56. }
  57. }