package pathgame.gameplay; import pathgame.algorithm.TravellingSalesAlg; import pathgame.logging.Logger; import pathgame.tilemap.TileMap; import pathgame.tilemap.TileMapGenerator; public final class Level { private final Player player = new Player(); private int level = 1; private TileMap map = null; private boolean showScoreMenu = false; private boolean showAfterScore = false; public Level() { reset(); } public void tick(Gamestate gamestate) { map.tick(); if(gamestate.is(Gamestates.GAMEPLAY) && !showScoreMenu) { player.tick(map); } if(gamestate.is(Gamestates.GAMEPLAY) && !showScoreMenu && (player.hasLost() || player.hasWon())) { showScoreMenu = true; } else if(showScoreMenu && Keys.CONFIRM_KEY.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()); TravellingSalesAlg.calcSalesPathLen(map); player.setEnergySupply(1000); // ToDo: insert value of algorithm Logger.onLevelReset(level, player, map); } public TileMap getMap() { return map; } public Player getPlayer() { return player; } public int getLevel() { return level; } public boolean isShowingAfterScore() { return showAfterScore; } public void setShowAfterScore(boolean show) { showAfterScore = show; } public boolean isShowingScoreMenu() { return showScoreMenu; } }