123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- package pathgame.gameplay;
- import pathgame.algorithm.TravellingSalesAlg;
- import pathgame.logging.Logger;
- import pathgame.tilemap.TileMap;
- import pathgame.tilemap.TileMapGenerator;
- /**
- * A level of the game containing the current map and the current player
- *
- * @author julia
- */
- 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;
- /**
- * Contructor generating and initializing new Level and Player
- */
- public Level()
- {
- reset();
- }
- /**
- * Checks gamestate changes every gametick based on user input and game
- * events
- *
- * @param gamestate the gamestate
- */
- 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;
- }
- }
- /**
- * Loads the next level
- */
- public void nextLevel()
- {
- level++;
- reset();
- }
- /**
- * Resets the current level
- */
- 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));
- Logger.onLevelReset(level, player, map);
- }
- /**
- * Returns the map of the current level
- *
- * @return the map of the current level
- */
- public TileMap getMap()
- {
- return map;
- }
- /**
- * Returns the player of the current level
- *
- * @return the player of the current level
- */
- public Player getPlayer()
- {
- return player;
- }
- /**
- * Returns the current level
- *
- * @return the current level
- */
- public int getLevel()
- {
- return level;
- }
-
- /**
- * Returns the energy use of the algorithm
- *
- * @return the energy use of the algorithm
- */
- public int getAlgorithmValue()
- {
- return algorithm;
- }
-
- /**
- * Returns if the AfterScoreMenu is showed
- *
- * @return if the AfterScoreMenu is showed
- */
- public boolean isShowingAfterScore()
- {
- return showAfterScore;
- }
- /**
- * Sets if the AfterScoreMenu should be showed
- *
- * @param show sets if the AfterScore should be showed
- */
- public void setShowAfterScore(boolean show)
- {
- showAfterScore = show;
- }
- /**
- * Returns if the ScoreMenu is showed
- *
- * @return if the ScoreMenu is showed
- */
- public boolean isShowingScoreMenu()
- {
- return showScoreMenu;
- }
- }
|