12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package pathgame.gameplay;
- import pathgame.algorithm.TravellingSalesAlg;
- import pathgame.tilemap.TileMap;
- import pathgame.tilemap.TileMapGenerator;
- public final class Level {
- public final static float ALGORITHM_1 = 1.0f;
- public final static float ALGORITHM_2 = 1.1f;
- public final static float ALGORITHM_3 = 1.2f;
- public final static float ALGORITHM_4 = 1.3f;
- private final Player player = new Player();
- private int level = 1;
- private TileMap map = null;
- private int algorithm = 0;
- private boolean showScoreMenu = false;
- private boolean showAfterScore = false;
- public Level() {
- reset();
- }
- public void tick(Gamestate gamestate, Keys keys) {
- map.tick();
- if(gamestate.is(Gamestates.GAMEPLAY) && !showScoreMenu) {
- player.tick(map, keys);
- }
- if(gamestate.is(Gamestates.GAMEPLAY) && !showScoreMenu && (player.hasLost() || player.hasWon())) {
- showScoreMenu = true;
- } else if(showScoreMenu && keys.confirm.getTime() == 1) {
- showScoreMenu = false;
- showAfterScore = true;
- }
- }
- public void nextLevel() {
- level++;
- reset();
- }
- public void reset() {
- int levelW = Math.round(16.0f + (level * 16.0f / 9.0f));
- int levelH = Math.round(9.0f + (level * 16.0f / 16.0f));
- int towns = Math.round(2.0f + level * 0.5f);
- map = TileMapGenerator.getMap(levelW, levelH, level, towns);
- player.reset(map.getHomeX(), map.getHomeY());
- player.setObjectivesAmount(map.getNumberOfTowns());
- algorithm = TravellingSalesAlg.calcSalesPathLen(map, player);
- player.setEnergySupply(Math.round(algorithm * ALGORITHM_4));
- }
- public TileMap getMap() {
- return map;
- }
- public Player getPlayer() {
- return player;
- }
- public int getLevel() {
- return level;
- }
- public int getAlgorithmValue() {
- return algorithm;
- }
- public boolean isShowingAfterScore() {
- return showAfterScore;
- }
- public void setShowAfterScore(boolean show) {
- showAfterScore = show;
- }
- public boolean isShowingScoreMenu() {
- return showScoreMenu;
- }
- }
|