Tile.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace AStar
  8. {
  9. public class Tile
  10. {
  11. #region Properties
  12. public int X { get; set; }
  13. public int Y { get; set; }
  14. // 장애물 여부
  15. public bool IsBlock { get; set; }
  16. // Draw를 위한 값
  17. public Rectangle Region { get; set; }
  18. // Draw를 위한 값
  19. public string Text { get; set; }
  20. // G + H
  21. public int F { get { return G + H; } }
  22. // START ~ 현재
  23. public int G { get; private set; }
  24. // 현재 ~ END
  25. public int H { get; private set; }
  26. public Tile Parent { get; private set; }
  27. #endregion
  28. #region Public Method
  29. public void Execute(Tile parent, Tile endTile)
  30. {
  31. Parent = parent;
  32. G = CalcGValue(parent, this);
  33. int diffX = Math.Abs(endTile.X - X);
  34. int diffY = Math.Abs(endTile.Y - Y);
  35. H = (diffX + diffY) * 10;
  36. }
  37. #endregion
  38. #region Static Method
  39. public static int CalcGValue(Tile parent, Tile current)
  40. {
  41. int diffX = Math.Abs(parent.X - current.X);
  42. int diffY = Math.Abs(parent.Y - current.Y);
  43. int value = 10;
  44. if (diffX == 1 && diffY == 0) value = 10;
  45. else if (diffX == 0 && diffY == 1) value = 10;
  46. else if (diffX == 1 && diffY == 1) value = 14;
  47. return parent.G + value;
  48. }
  49. #endregion
  50. }
  51. }