Level.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. public final static float ALGORITHM_1 = 1.0f;
  7. public final static float ALGORITHM_2 = 1.1f;
  8. public final static float ALGORITHM_3 = 1.2f;
  9. public final static float ALGORITHM_4 = 1.3f;
  10. private final Player player = new Player();
  11. private int level = 1;
  12. private TileMap map = null;
  13. private int algorithm = 0;
  14. private boolean showScoreMenu = false;
  15. private boolean showAfterScore = false;
  16. public Level() {
  17. reset();
  18. }
  19. public void tick(Gamestate gamestate, Keys keys) {
  20. map.tick();
  21. if(gamestate.is(Gamestates.GAMEPLAY) && !showScoreMenu) {
  22. player.tick(map, keys);
  23. }
  24. if(gamestate.is(Gamestates.GAMEPLAY) && !showScoreMenu && (player.hasLost() || player.hasWon())) {
  25. showScoreMenu = true;
  26. } else if(showScoreMenu && keys.confirm.getTime() == 1) {
  27. showScoreMenu = false;
  28. showAfterScore = true;
  29. }
  30. }
  31. public void nextLevel() {
  32. level++;
  33. reset();
  34. }
  35. public void reset() {
  36. int levelW = Math.round(16.0f + (level * 16.0f / 9.0f));
  37. int levelH = Math.round(9.0f + (level * 16.0f / 16.0f));
  38. int towns = Math.round(2.0f + level * 0.5f);
  39. map = TileMapGenerator.getMap(levelW, levelH, level, towns);
  40. player.reset(map.getHomeX(), map.getHomeY());
  41. player.setObjectivesAmount(map.getNumberOfTowns());
  42. algorithm = TravellingSalesAlg.calcSalesPathLen(map, player);
  43. player.setEnergySupply(Math.round(algorithm * ALGORITHM_4));
  44. }
  45. public TileMap getMap() {
  46. return map;
  47. }
  48. public Player getPlayer() {
  49. return player;
  50. }
  51. public int getLevel() {
  52. return level;
  53. }
  54. public int getAlgorithmValue() {
  55. return algorithm;
  56. }
  57. public boolean isShowingAfterScore() {
  58. return showAfterScore;
  59. }
  60. public void setShowAfterScore(boolean show) {
  61. showAfterScore = show;
  62. }
  63. public boolean isShowingScoreMenu() {
  64. return showScoreMenu;
  65. }
  66. }