Level.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package pathgame.gameplay;
  2. import pathgame.algorithm.TravellingSalesAlg;
  3. import pathgame.tilemap.TileMap;
  4. import pathgame.tilemap.TileMapGenerator;
  5. public final class Level
  6. {
  7. private final Player player = new Player();
  8. private int level = 1;
  9. private TileMap map = null;
  10. private boolean showScoreMenu = false;
  11. private boolean showAfterScore = false;
  12. public Level()
  13. {
  14. reset();
  15. }
  16. public void tick(Gamestate gamestate)
  17. {
  18. map.tick();
  19. if(gamestate.is(Gamestates.GAMEPLAY) && !showScoreMenu)
  20. {
  21. player.tick(map);
  22. }
  23. if(gamestate.is(Gamestates.GAMEPLAY) && !showScoreMenu && (player.hasLost() || player.hasWon()))
  24. {
  25. showScoreMenu = true;
  26. }
  27. else if(showScoreMenu && Keys.CONFIRM_KEY.getTime() == 1)
  28. {
  29. showScoreMenu = false;
  30. showAfterScore = true;
  31. }
  32. }
  33. public void nextLevel()
  34. {
  35. level++;
  36. reset();
  37. }
  38. public void reset()
  39. {
  40. int levelW = Math.round(16.0f + (level * 16.0f / 9.0f));
  41. int levelH = Math.round(9.0f + (level * 16.0f / 16.0f));
  42. int towns = Math.round(2.0f + level * 0.5f);
  43. map = TileMapGenerator.getMap(levelW, levelH, level, towns);
  44. player.reset(map.getHomeX(), map.getHomeY());
  45. player.setObjectivesAmount(map.getNumberOfTowns());
  46. TravellingSalesAlg.calcSalesPathLen(map);
  47. player.setEnergySupply(1000); // ToDo: insert value of algorithm
  48. }
  49. public TileMap getMap()
  50. {
  51. return map;
  52. }
  53. public Player getPlayer()
  54. {
  55. return player;
  56. }
  57. public int getLevel()
  58. {
  59. return level;
  60. }
  61. public boolean isShowingAfterScore()
  62. {
  63. return showAfterScore;
  64. }
  65. public void setShowAfterScore(boolean show)
  66. {
  67. showAfterScore = show;
  68. }
  69. public boolean isShowingScoreMenu()
  70. {
  71. return showScoreMenu;
  72. }
  73. }