Package com.starpoints.game
Class Level
- java.lang.Object
-
- com.starpoints.game.AbstractLevel
-
- com.starpoints.game.Level
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class Level extends AbstractLevel implements java.io.Serializable, java.lang.Cloneable
A level stores game informations and handles the figures and field. The level properties, different classes of enemy figures, items and colors are retrieved from a LevelInfo object.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static booleanDEBUGDebug flag.protected FieldfieldThe field.protected GamegameThe game.protected java.util.ArrayList<Figure>pointBonusWinnersThe possibilities for the different classes of items.protected booleansetToLevelOverFlag, if switched to next level by setting gameOver().
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FogcreateRandomFog()Gets a random fog.LevelStatecreateState(AnimationInfo animation)Creates a GameState object representing the current state of the game.voiddisplayMessage(java.lang.String msg, int duration, MessagePosition pos, int c, FontSize size)Fires a displayMessage event to all listeners.intgetBackgroundColor()Returns the background color for this level.intgetBackgroundForeColor()Returns the background forecolor for this level.doublegetBlackRainProb()Gets the probability for a black rain in this level.intgetColorProbability(int color)Gets the probability of a certain random color (in percent).intgetCyanProb()Gets the probability for new items on cyan.EffectsgetEffects()Returns the effects of this level.java.util.List<Figure>getEnemies()Returns the enemy figures.intgetExplosionEnergyLoss()Gets the energy loss while standing in an explosion for one round.FieldgetField()Returns the field of this level.protected FieldInfogetFieldInfo()Gets this levels FieldInfo.java.util.List<Figure>getFigures()Returns a list of all figures in the level.intgetFogDensity()Gets the levels fog density.FoggetFogForClass(java.lang.String clas)Returns a new instance of a Figure of the given class.GamegetGame()Returns the game.intgetGrayEnergyLoss()Gets the energy loss while standing a gray point for one round.intgetHeatGain()Returns the heat gain on red points.intgetHeight()Gets the width of this levels height.intgetInitialSwirlingRounds()Returns the number of rounds the color swirling effects long.intgetItemdensity()Gets the item density for random items.intgetLevelColor()Gets this levels color.LevelInfogetLevelInfo()Gets the info object describing this level.java.lang.StringgetLevelInfoText()Gets the info text to display at the beginning of a level.java.lang.StringgetLevelIntroText()Gets an intro text for the LevelIntro-sequence.java.lang.StringgetLevelSound()Returns the name for the sound file for the next level fx.java.lang.StringgetLevelText()Gets the levels intro text.intgetMagentaEnergyGain()Gets the energy gain while standing a magenta point for one round.java.lang.StringgetName()Gets this levels name.OptionsgetOptions()Gets the game options.java.util.List<PlayerFigure>getPlayers()Returns the player figures.intgetRandomColor(boolean includeSwirling)Gets a random color depending on the color probability definitions for this level..ItemgetRandomItem()Gets a random item.PointgetRandomPoint()Gets a random point on the field.intgetRoundCount()Gets the number of rounds still to play.intgetRoundLimit()Gets the initial number of rounds to play in this level.intgetWidth()Gets the width of this levels field.booleanhasReplay()Gets, if replay is enabled for this level.protected voidinitField()Initializes the field.booleanisDirectFlashing()Checks, if the sequence LevelOver - LevelIntro - LevelInfo is skipped (e.g. in tutorial).booleanislastFigureWinning()Checks, if the last figure alive wins this level.booleanisLevelOver()Checks, if this level is over.booleanisloosingLives()Checks, if lifes are lost in this level.booleanisOnlyOnce()Checks, if this level is played only once, independent of the level winner.booleanisOnlyWinnerGettingPoints()Checks, if only the winners level score is added to the score.booleanisPlacingItems()Checks, if random items are placed at the beginning of this level.booleanisShowingLevelProps()Checks, if the level properties should be shown before level starts.booleanisSwitchingToSecretLevel()Checks, if the next level to enter can be a secret level.booleanisTeamMode()Gets, if playing in team mode.booleanisTutorial()Returns false, because this is no tutorial level.voidonEnemyKilled(Figure killer, Figure enemy, AnimationInfo animation)Called by figure, if it killed an enemy, checks for dontKill setting.voidplaceFixedFogs()Places the defined fogs of the LevelInfo on the field.voidplaceFixedItems()Places the defined items of the LevelInfo on the field.voidplaceFogs()Randomly places fogs on the field.voidplaceFogs(int fogdensity)Randomly places fogs on the field.voidplaceItems(int itemdensity)Randomly places items on the field.voidplaceThings()Randomly places items on the field.voidreInit()Reinitializes the current level after level over.voidsetBackgroundColor(int c)Sets the background color for this level.voidsetBackgroundForeColor(int c)Sets the background forecolor for this level.booleanstepToNextLevel()Returns, if the player doesn't need to win to step to next level.voidswitchToNextLevel()Switches to the next level.voidswitchToSecretLevel()Switches to the next secret level.java.lang.StringtoString()Returns a string representation for this level.voidupdateLevel(AnimationInfo animation)Updates the field by calling the update method for the field, and increases the round counter.booleanwasSwitchedToSecretLevel()Returns true, if the level was switched to a secret level (but is not itself already secret).
-
-
-
Field Detail
-
DEBUG
protected static final boolean DEBUG
Debug flag.- See Also:
- Constant Field Values
-
game
protected Game game
The game.
-
pointBonusWinners
protected java.util.ArrayList<Figure> pointBonusWinners
The possibilities for the different classes of items.
-
field
protected Field field
The field.
-
setToLevelOver
protected boolean setToLevelOver
Flag, if switched to next level by setting gameOver().
-
-
Method Detail
-
reInit
public void reInit()
Reinitializes the current level after level over.
-
getBackgroundColor
public int getBackgroundColor()
Returns the background color for this level.- Returns:
- The background
-
getBackgroundForeColor
public int getBackgroundForeColor()
Returns the background forecolor for this level.- Returns:
- The background
-
setBackgroundColor
public void setBackgroundColor(int c)
Sets the background color for this level.- Parameters:
c- The background color
-
setBackgroundForeColor
public void setBackgroundForeColor(int c)
Sets the background forecolor for this level.- Parameters:
c- The background forecolor
-
islastFigureWinning
public boolean islastFigureWinning()
Checks, if the last figure alive wins this level.- Returns:
- levelInfo.lastFigureWins.
-
isSwitchingToSecretLevel
public boolean isSwitchingToSecretLevel()
Checks, if the next level to enter can be a secret level.- Returns:
- true, if switchToSecretLevel was called before.
-
getPlayers
public java.util.List<PlayerFigure> getPlayers()
Returns the player figures.- Returns:
- An array of player figures
-
getEnemies
public java.util.List<Figure> getEnemies()
Returns the enemy figures.- Returns:
- An array of enemy figures
-
getFigures
public java.util.List<Figure> getFigures()
Returns a list of all figures in the level.- Returns:
- A list of all figures.
-
getEffects
public Effects getEffects()
Returns the effects of this level.- Returns:
- The effects.
-
getField
public Field getField()
Returns the field of this level.- Returns:
- The field.
-
isLevelOver
public boolean isLevelOver()
Checks, if this level is over. Depending on the number of players, this will return (checked in this order): - true, if switchToNextLevel was called.
- true, if round limit is reached.
- false, if the lastFigureWins-Flag is false.
- true, if one player is playing and has killed all enemies.
- true, if two players are playing, and one has dies.
- false otherwise- Returns:
- true, if the game is over.
-
getRandomColor
public int getRandomColor(boolean includeSwirling)
Gets a random color depending on the color probability definitions for this level..- Parameters:
includeSwirling- Flag, if swirling colors should be included in random colors- Returns:
- A color.
-
displayMessage
public void displayMessage(java.lang.String msg, int duration, MessagePosition pos, int c, FontSize size)Fires a displayMessage event to all listeners.- Parameters:
msg- The messageduration- Duration in rounds.pos- The Message position.c- The message color.size- The font size.
-
getLevelSound
public java.lang.String getLevelSound()
Returns the name for the sound file for the next level fx.- Returns:
- The level sound.
-
stepToNextLevel
public boolean stepToNextLevel()
Returns, if the player doesn't need to win to step to next level.- Returns:
- false per default.
-
getInitialSwirlingRounds
public int getInitialSwirlingRounds()
Returns the number of rounds the color swirling effects long.- Returns:
- The length of swirling effects
-
getHeatGain
public int getHeatGain()
Returns the heat gain on red points. Doubled for orange points.- Returns:
- The heat gain on red points.
-
switchToNextLevel
public void switchToNextLevel()
Switches to the next level. Secret levels are skipped when using this method. To switch to a secret level, use switchToSecretLevel.
-
switchToSecretLevel
public void switchToSecretLevel()
Switches to the next secret level. If the next level in the level set is no secret level, this method behaves as switchToNextLevel.
-
wasSwitchedToSecretLevel
public boolean wasSwitchedToSecretLevel()
Returns true, if the level was switched to a secret level (but is not itself already secret).- Returns:
-
updateLevel
public void updateLevel(AnimationInfo animation)
Updates the field by calling the update method for the field, and increases the round counter. Additionally, the Special point bonus is checked for each figure.- Parameters:
animation- The AnimationInfo
-
getOptions
public Options getOptions()
Gets the game options.- Returns:
- The options.
-
getRoundCount
public int getRoundCount()
Gets the number of rounds still to play.- Returns:
- The number of rounds
-
getRoundLimit
public int getRoundLimit()
Gets the initial number of rounds to play in this level.- Returns:
- The number of rounds
-
placeThings
public void placeThings()
Randomly places items on the field.
-
isPlacingItems
public boolean isPlacingItems()
Checks, if random items are placed at the beginning of this level.- Returns:
- true, if random items are placed.
-
isDirectFlashing
public boolean isDirectFlashing()
Checks, if the sequence LevelOver - LevelIntro - LevelInfo is skipped (e.g. in tutorial).- Returns:
- true, if the sequence in-between two levels is skipped for this level.
-
getItemdensity
public int getItemdensity()
Gets the item density for random items.- Returns:
- The item density.
-
placeItems
public void placeItems(int itemdensity)
Randomly places items on the field.- Parameters:
itemdensity- The item density.
-
placeFixedItems
public void placeFixedItems()
Places the defined items of the LevelInfo on the field.
-
placeFogs
public void placeFogs()
Randomly places fogs on the field.
-
placeFixedFogs
public void placeFixedFogs()
Places the defined fogs of the LevelInfo on the field.
-
placeFogs
public void placeFogs(int fogdensity)
Randomly places fogs on the field.- Parameters:
fogdensity- the fog density.
-
isTeamMode
public boolean isTeamMode()
Gets, if playing in team mode.- Returns:
- true, if playing in team mode
-
getCyanProb
public int getCyanProb()
Gets the probability for new items on cyan.- Returns:
- The new item probability.
-
getExplosionEnergyLoss
public int getExplosionEnergyLoss()
Gets the energy loss while standing in an explosion for one round.- Returns:
- the energy loss
-
getGrayEnergyLoss
public int getGrayEnergyLoss()
Gets the energy loss while standing a gray point for one round.- Returns:
- the energy loss
-
getMagentaEnergyGain
public int getMagentaEnergyGain()
Gets the energy gain while standing a magenta point for one round.- Returns:
- the energy gain
-
getRandomItem
public Item getRandomItem()
Gets a random item. In case anything fails, an ItemPoints will be returned.- Returns:
- An item.
-
createRandomFog
public Fog createRandomFog()
Gets a random fog. In case anything fails, null will be returned.- Returns:
- A random fog.
-
getName
public java.lang.String getName()
Gets this levels name.- Returns:
- The level name.
-
isOnlyOnce
public boolean isOnlyOnce()
Checks, if this level is played only once, independent of the level winner.- Returns:
- true, if level is played only once.
-
getWidth
public int getWidth()
Gets the width of this levels field.- Returns:
- The field width.
-
getHeight
public int getHeight()
Gets the width of this levels height.- Returns:
- The field height.
-
getRandomPoint
public Point getRandomPoint()
Gets a random point on the field.- Returns:
- A random point
-
getFogForClass
public Fog getFogForClass(java.lang.String clas)
Returns a new instance of a Figure of the given class. If the class cannot be found or another Exception occurs during figure creation, null is returned.- Parameters:
clas- The class of the fog- Returns:
- A fog of the desired class (s.a.)
-
hasReplay
public boolean hasReplay()
Gets, if replay is enabled for this level.- Returns:
- levelInfo.hasReplay.
-
getFieldInfo
protected FieldInfo getFieldInfo()
Gets this levels FieldInfo.- Returns:
- The field info for this level.
-
initField
protected void initField()
Initializes the field.
-
getLevelColor
public int getLevelColor()
Gets this levels color.- Returns:
- LevelInfo.levelColor.
-
isTutorial
public boolean isTutorial()
Returns false, because this is no tutorial level.- Returns:
- false.
-
onEnemyKilled
public void onEnemyKilled(Figure killer, Figure enemy, AnimationInfo animation)
Called by figure, if it killed an enemy, checks for dontKill setting.- Parameters:
killer- The killer.enemy- The killed figure.animation- The AnimationInfo.
-
getLevelText
public java.lang.String getLevelText()
Gets the levels intro text.- Returns:
- LevelInfo.levelText.
-
getFogDensity
public int getFogDensity()
Gets the levels fog density.- Returns:
- LevelInfo.fogdensity.
-
isShowingLevelProps
public boolean isShowingLevelProps()
Checks, if the level properties should be shown before level starts.- Returns:
- LevelInfo.showLevelProps.
-
getColorProbability
public int getColorProbability(int color)
Gets the probability of a certain random color (in percent). Or 0, if not in the colors array.- Parameters:
color- The color to get the probability for.- Returns:
- The probability for that color.
-
getBlackRainProb
public double getBlackRainProb()
Gets the probability for a black rain in this level.- Returns:
- LevelInfo.blackRainProb.
-
isloosingLives
public boolean isloosingLives()
Checks, if lifes are lost in this level.- Returns:
- LevelInfo.looseLives.
-
isOnlyWinnerGettingPoints
public boolean isOnlyWinnerGettingPoints()
Checks, if only the winners level score is added to the score.- Returns:
- LevelInfo.onlyWinnerGetsPoints.
-
getGame
public Game getGame()
Returns the game.- Returns:
- The game.
-
getLevelInfo
public LevelInfo getLevelInfo()
Gets the info object describing this level.- Returns:
- This levels LevelInfo.
-
getLevelInfoText
public java.lang.String getLevelInfoText()
Gets the info text to display at the beginning of a level.- Returns:
- The String (formatted for PainterText).
-
getLevelIntroText
public java.lang.String getLevelIntroText()
Gets an intro text for the LevelIntro-sequence.- Returns:
- "Enter LEVELNAME..."
-
toString
public java.lang.String toString()
Returns a string representation for this level.- Overrides:
toStringin classjava.lang.Object- Returns:
- Level name, round count and the list of level figures.
-
createState
public LevelState createState(AnimationInfo animation)
Creates a GameState object representing the current state of the game.- Parameters:
animation- The AnimationInfo.- Returns:
- The LevelState.
-
-