PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/WorldView/Utilities/Comparers.cs

#
C# | 105 lines | 80 code | 23 blank | 2 comment | 17 complexity | fcc80495383ecbe96ec07230aae3e53c MD5 | raw file
  1. using System;
  2. using System.Collections;
  3. using System.Windows.Forms;
  4. using System.Collections.Generic;
  5. using MoreTerra.Structures;
  6. namespace MoreTerra.Utilities
  7. {
  8. class ChestComparerX : IComparer
  9. {
  10. int IComparer.Compare(object one, object two)
  11. {
  12. Int32 oneX, twoX;
  13. if (one.GetType() == typeof(TreeNode))
  14. {
  15. if (((TreeNode)one).Parent != null)
  16. return 1;
  17. oneX = getXCoord(((TreeNode)one).Text);
  18. twoX = getXCoord(((TreeNode)two).Text);
  19. } else {
  20. throw new NotImplementedException("ChestComparerX can not handle type " + one.GetType().ToString());
  21. }
  22. return oneX - twoX;
  23. }
  24. private Int32 getXCoord(String s)
  25. {
  26. String[] sa;
  27. // "Chest at (" "," ")"
  28. sa = s.Split(new char[] { '(', ',' });
  29. return Int32.Parse(sa[1]);
  30. }
  31. }
  32. class ChestComparerY : IComparer
  33. {
  34. int IComparer.Compare(object one, object two)
  35. {
  36. Int32 oneY, twoY;
  37. if (one.GetType() == typeof(TreeNode))
  38. {
  39. if (((TreeNode)one).Parent != null)
  40. return 1;
  41. oneY = getYCoord(((TreeNode)one).Text);
  42. twoY = getYCoord(((TreeNode)two).Text);
  43. }
  44. else
  45. {
  46. throw new NotImplementedException("ChestComparerY can not handle type " + one.GetType().ToString());
  47. }
  48. return oneY - twoY;
  49. }
  50. private Int32 getYCoord(String s)
  51. {
  52. String[] sa;
  53. // "Chest at (" "," ")"
  54. sa = s.Split(new char[] { ',', ')' });
  55. return Int32.Parse(sa[1]);
  56. }
  57. }
  58. class ChestListComparerX : IComparer<Chest>
  59. {
  60. public int Compare(Chest one, Chest two)
  61. {
  62. Int32 oneX, twoX;
  63. if (one == null || two == null)
  64. return 1;
  65. oneX = one.Coordinates.X;
  66. twoX = two.Coordinates.X;
  67. return oneX - twoX;
  68. }
  69. }
  70. class ChestListComparerY : IComparer<Chest>
  71. {
  72. public int Compare(Chest one, Chest two)
  73. {
  74. Int32 oneY, twoY;
  75. if (one == null || two == null)
  76. return 1;
  77. oneY = one.Coordinates.Y;
  78. twoY = two.Coordinates.Y;
  79. return oneY - twoY;
  80. }
  81. }
  82. }