Coord.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package pathgame.algorithm;
  2. /** Simple class for storing 2D x and y coordinates
  3. *
  4. */
  5. public class Coord {
  6. private int x, y;
  7. private boolean isBoatTile = false;
  8. /** Create new coordinate with given x and y value
  9. *
  10. * @param x position of Coord
  11. * @param y position of Coord
  12. */
  13. Coord(int x, int y) {
  14. this.x = x;
  15. this.y = y;
  16. }
  17. /** Creates new cooridnate with given x and y value and sets isBoatTile to given value
  18. *
  19. * @param x position of Coord
  20. * @param y position of Coord
  21. * @param isBoatTile set to true if part of a boat path; used for debug purposes
  22. */
  23. Coord(int x, int y, boolean isBoatTile) {
  24. this.x = x;
  25. this.y = y;
  26. this.isBoatTile = isBoatTile;
  27. }
  28. /** Returns x position of Coord
  29. *
  30. * @return x position
  31. */
  32. public int getX() {
  33. return x;
  34. }
  35. /** Returns y position of Coord
  36. *
  37. * @return y position
  38. */
  39. public int getY() {
  40. return y;
  41. }
  42. /** Adds given value to x position of Coord
  43. *
  44. * @param x value to be added to x position
  45. */
  46. public void changeX(int x) {
  47. this.x += x;
  48. }
  49. /** Adds given value to y position of Coord
  50. *
  51. * @param y value to be added to y position
  52. */
  53. public void changeY(int y) {
  54. this.y += y;
  55. }
  56. /** Sets x and y position of Coord to given values
  57. *
  58. * @param x new x position of Coord
  59. * @param y new y position of Coord
  60. */
  61. public void setCoord(int x, int y) {
  62. this.x = x;
  63. this.y = y;
  64. }
  65. /** Returns isBoatTile, which is true if Coord is part of a boat path
  66. *
  67. * @return isBoatTile of Coord
  68. */
  69. public boolean isBoatTile() {
  70. return isBoatTile;
  71. }
  72. /** Sets isBoatTile to given value
  73. *
  74. * @param isBoatTile value isBoatTile gets set to
  75. */
  76. public void setBoatTile(boolean isBoatTile) {
  77. this.isBoatTile = isBoatTile;
  78. }
  79. }