PageRenderTime 49ms CodeModel.GetById 19ms app.highlight 9ms RepoModel.GetById 19ms app.codeStats 0ms

/WorldView/Utilities/Comparers.cs

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