You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.7 KiB

  1. /**
  2. * @file Common.java
  3. *
  4. * @author Christos Choutouridis AEM:8997
  5. * @email cchoutou@ece.auth.gr
  6. */
  7. package net.hoo2.auth.labyrinth;
  8. /**
  9. * Application wide object to hold settings like values for the session.
  10. */
  11. class Defaults {
  12. static int boardSize = 15; /**@< Default board's size (if no one set it via command line) */
  13. }
  14. /**
  15. * Helper C++-like enumerator class to hold direction
  16. */
  17. class Direction {
  18. static final int UP =1; /**< North direction */
  19. static final int RIGHT =3; /**< East direction */
  20. static final int DOWN =5; /**< South direction */
  21. static final int LEFT =7; /**< West direction */
  22. }
  23. /**
  24. * @brief
  25. * An Application wide board position implementation holding just the coordinates
  26. *
  27. * Position is a helper class to enable us cope with the redundant position data (id and coordinates).
  28. * This class provide both static conversion functionalities between id and coordinates
  29. * and data representation in the coordinates system.
  30. */
  31. class Position {
  32. /**
  33. * Basic constructor from coordinates
  34. * @param x The x coordinate
  35. * @param y The y coordinate
  36. */
  37. protected Position(int x, int y) {
  38. this.x = x;
  39. this.y = y;
  40. }
  41. /**
  42. * Basic constructor from Id
  43. * @param tileId The id of tile
  44. */
  45. protected Position(int tileId) {
  46. this.x = toX(tileId);
  47. this.y = toY(tileId);
  48. }
  49. /** @name non-static API */
  50. /** @{ */
  51. protected int getX() { return x; } /**< Read access to x coordinate */
  52. protected int getY() { return y; } /**< Read access to y coordinate */
  53. protected int getID(){ return toID(x, y); } /**< Virtual read access to id coordinate */
  54. /** @} */
  55. /** @name Static convention utilities */
  56. /** @{ */
  57. /**
  58. * Takes x and y coordinates and return the calculated Id coordinate
  59. * @param x The x coordinate
  60. * @param y The y coordinate
  61. * @return The converted value
  62. */
  63. protected static int toID(int x, int y) {
  64. return y * Defaults.boardSize + x;
  65. }
  66. /**
  67. * Takes Id coordinate and return the corresponding x coordinate
  68. * @param id The id coordinate
  69. * @return The x coordinate
  70. */
  71. protected static int toX(int id){
  72. return id % Defaults.boardSize;
  73. }
  74. /**
  75. * Takes Id coordinate and return the corresponding y coordinate
  76. * @param id The id coordinate
  77. * @return The y coordinate
  78. */
  79. protected static int toY(int id) {
  80. return id / Defaults.boardSize;
  81. }
  82. /** @} */
  83. /** @name private data types */
  84. /** @{ */
  85. private int x; /**< The x coordinate of the constructed Position object */
  86. private int y; /**< The y coordinate of the constructed Position object */
  87. /** @} */
  88. }