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.

98 lines
3.1 KiB

  1. package playground;
  2. import org.apache.log4j.LogManager;
  3. import org.apache.log4j.Logger;
  4. /**
  5. * Advanced version of abstract {@link BreakoutLevelBase} providing a complete implementation of
  6. * {@link #prepareLevel(String)}. Additionally abstract methods for number of bricks in X and Y
  7. * direction are provided as well as abstract methods for brick sizes and start coordinates.
  8. *
  9. * @see #calcNrBricksX()
  10. * @see #calcNrBricksY()
  11. * @see #getBrickSizeX()
  12. * @see #getBrickSizeY()
  13. * @see #getBrickStartX()
  14. * @see #getBrickStartY()
  15. *
  16. */
  17. public abstract class BreakoutLevelBaseAdvanced extends BreakoutLevelBase {
  18. private static Logger logger = LogManager.getLogger(BreakoutLevelBaseAdvanced.class);
  19. /**
  20. * provides the number of bricks to be set in horizontal direction.
  21. *
  22. * @return positive value of how many bricks are to be next to each other in X direction
  23. */
  24. protected abstract int calcNrBricksX();
  25. /**
  26. * provides the number of bricks to be set in vertical direction.
  27. *
  28. * @return positive value of how many bricks are to be next to each other in Y direction
  29. */
  30. protected abstract int calcNrBricksY();
  31. /**
  32. * provides the length of one brick.
  33. *
  34. * @return positive value of how long a brick should be in X direction.
  35. */
  36. protected abstract double getBrickSizeX();
  37. /**
  38. * provides the height of one brick.
  39. *
  40. * @return positive value of how high a brick should be in Y direction.
  41. */
  42. protected abstract double getBrickSizeY();
  43. /**
  44. * provides the start coordinate of upper left corner (X value).
  45. *
  46. * @return positive value of the X coordinate to use as the starting point of the upper left
  47. * corner of the brick set.
  48. */
  49. protected abstract double getBrickStartX();
  50. /**
  51. * provides the start coordinate of upper left corner (Y value).
  52. *
  53. * @return positive value of the Y coordinate to use as the starting point of the upper left
  54. * corner of the brick set.
  55. */
  56. protected abstract double getBrickStartY();
  57. /**
  58. * Prepares a complete Breakout type level and uses the values provided by implementations of
  59. * {@link #calcNrBricksX()} and {@link #calcNrBricksY()} to generate the stone matrix.
  60. * Furthermore, it relies on the methods {@link #createEgoObject()}, {@link #createBall} and {@link #createBrick},
  61. * which are meant to be overwritten in subclasses. <br>
  62. * Attention: For collision detection bricks created by {@link #createBrick(int, int)} need to have the String 'brick' in ID.
  63. *
  64. * @see LevelBreakoutBase#prepareLevel(String) for further information.
  65. *
  66. * @param level String passes by the game engine (not used currently and can be ignored).
  67. *
  68. */
  69. @Override
  70. public void prepareLevel(String level) {
  71. for (int y = 0; y < this.calcNrBricksY(); y++) {
  72. for (int x = 0; x < this.calcNrBricksX(); x++) {
  73. logger.trace("trying to create brick X, Y (" + x + "," + y + ")");
  74. this.addObject(this.createBrick(x, y));
  75. }
  76. }
  77. this.ego = this.createEgoObject();
  78. this.ball = this.createBall();
  79. this.addObject(this.ego);
  80. this.addObject(this.ball);
  81. logger.info("level preperation succeeded.");
  82. }
  83. }