Package com.starpoints.game
Class Thing
- java.lang.Object
-
- com.starpoints.game.Thing
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public abstract class Thing extends java.lang.Object implements java.io.Serializable, java.lang.Cloneable
Abstract superclass for anything on a Starpoint field, especially figures, items and fogs. Every Thing has a current energy and a maximum energy limit.As long as a Thing is placed on the field, it has x and y-coordinates.
The status of a thing might be one of the following: OK, EXPLODING, DESTROYED, INVULNERABLE. If invulnerable, no energy losses or calls of the die()-method have an effect. If the energy losses and gains in a round result in an energy level of 0 or less, the things status is set to exploding. This is done as well if the die()-method is called. Further handling of the exploding state is implemented in subclasses.
Every Thing might have an image, if not, an inner and outer color is provided for painting. A text can be set to be displayed next to the thing by using drawText(), each text is displayed for MAX_TEXTPAINT rounds.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static boolean
DEBUG
Debug flag.protected int
energy
The current energy level of this thing.protected boolean
energyFx
Flag, if energy max fx should be performed.protected boolean
energyMaxSoundPlayed
Flag, if sound for reached energy maximum was playedprotected java.util.List<EnergyModifier>
energyModifications
A list of energy modifications during one round.protected int
explosionCounter
Counter for explosion effects.protected Game
game
Reference to the game.protected java.lang.String
imageName
Name of the things imageprotected int
innerColor
The color for this thing.protected int
invulnCount
Counter for invulnerability.protected boolean
isAffectedByBlack
Flag, if thing is affected by holes.protected boolean
isAffectedByGray
Flag, if thing is affected by gray points.protected Level
level
Level this thing is used in.static int
MAX_TEXTPAINT
Constant for text duration.protected int
maxEnergy
The energy maximum of this thing.static int
nextID
NextID for Player identification.protected int
outerColor
The color used for painting shadow effects.protected Point
p
The point this figure occupies.protected int
shieldCount
Current general shielding.protected Status
status
The current status of this thing.protected java.util.ArrayList<java.lang.String>
text
Text to display
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addEnergy(int newEnergy, AnimationInfo animation)
Adds the given amount to this things energy level.void
addShielding(int power)
Adds the given shielding against energy loss in general.protected void
addStateProperties(ThingState state, AnimationInfo animation)
Override in superclasses, to add properties necessary for thing painting.boolean
affectsBlue()
Checks, if this thing affects blue points.void
clearTexts()
Clears the list of texts to display at the thing.protected abstract ThingState
createState(AnimationInfo animation)
void
die(Thing source, DieReason reason, AnimationInfo animation)
Sets the status of the thing to exploding (if it is not invulnerabe).void
displayText(java.lang.String txt)
Displays a text at the thing.void
displayText(java.lang.String txt, int color)
Displays a text at the figure.boolean
entersColor(int c, AnimationInfo animation)
Called, if the thing occupies a point with the given color.boolean
equals(java.lang.Object o)
Checks, if the other Object is a thing with the same id.int
getColor()
Returns the things color.int
getEnergy()
Returns the energy level of this thing.int
getEnergyMaxCount()
Gets a counter, since the energy maximum was reached.int
getExplosionCounter()
Gets the counter for how many rounds this thing is already exploding.Field
getField()
Gets the field of the current level, this item is used in.Game
getGame()
Returns the game this thing is part of.int
getID()
Gets this figures ID.java.lang.String
getImageName(AnimationInfo animation)
Returns image name relative to path /pics, without suffix.int
getInnerColor()
Gets the inner color for painting this thing.int
getInvulnerableRounds()
Returns the number of rounds, this thing is invulnerable.Level
getLevel()
Gets the current level, this item is used in.int
getMaxEnergy()
Returns the maximum energy level of this thing.abstract java.lang.String
getName()
Returns a display name for the thing.static int
getNextID()
Gets the next possible ID for a figure.int
getOuterColor()
Gets the outer color for painting this thing.Point
getPoint()
Gets the point this figure occupies.int
getShadowColor()
Returns the things color for shadowing.int
getShield()
Returns the current shielding against energy loss in general.protected java.lang.Object
getStateObject(java.lang.Object val, AnimationInfo animation)
Might be used to retrieve a State object for a given obejct.Status
getStatus()
Gets this figures status.java.lang.String
getText()
Gets the text to display at the thing.int
getTextColor()
Gets the color for a text to display at the thing.int
getTextPaintCount()
Gets the counter for text display at the thing.int
getX()
Returns the x coordinate of this thing.int
getY()
Returns the y coordinate of this thing.int
hashCode()
Gets the hash code.void
invulnerable(int rounds)
Makes this thing invulnerable for the given number of rounds.boolean
isAffectedByBlack()
Returns, if this thing is affected by black points.boolean
isAffectedByGray()
Returns, if this thing is affected by gray points.boolean
isDestroyed()
Checks, if the thing is destroyed.boolean
isExploding()
Checks, if the thing is exploding.boolean
isInvulnerable()
Checks, if the thing is invulnerable.boolean
isOK()
Checks, if the thing is ok (either normal state or invulerable).boolean
isShowingEnergyFx()
Checks, if energy fx should be shown for this thing.protected void
onEnemyKilled(Figure figure, int roundCount, DieReason reason, AnimationInfo animation)
Called, if a figure was destroyed by this thing.protected int
onExplode(int min, Thing source, AnimationInfo animation)
Called, if energy loss with reason explode occurs.void
removeEnergy(int min, Thing source, DieReason reason, AnimationInfo animation)
Removes the given amount from this things energy level (if it is not invulnerable).protected ThingState
retrieveState(ThingState state, AnimationInfo animation)
Retrieves this things state in the state parameter and returns it.void
setEnergy(int newEnergy)
Sets this things energy level.void
setEnergyMaxCount(int energyMaxCount)
Sets a counter, since the energy maximum was reached.protected void
setGame(Game game)
Sets the game for this thing.void
setMaxEnergy(int maxEnergy)
Sets the energy maximum for this thing.void
setPoint(Point p)
Sets the point this thing occupies.void
setStatus(Status newStatus)
Sets this things status.boolean
staysOnColor(int c, AnimationInfo animation)
Called, if the thing stays on a point with the given color.protected boolean
stepText()
Displays the next text in the list.protected void
updateEnergy(AnimationInfo animation)
Updates the figures energy depending on the energy modifiers of the round.protected abstract void
updateExplodingStatus(AnimationInfo animation)
Handles the things status during update phase of the round when thing is exploding.protected void
updateThing(AnimationInfo animation)
Updates this thing after each round.
-
-
-
Field Detail
-
DEBUG
protected static final boolean DEBUG
Debug flag.- See Also:
- Constant Field Values
-
MAX_TEXTPAINT
public static final int MAX_TEXTPAINT
Constant for text duration.- See Also:
- Constant Field Values
-
maxEnergy
protected int maxEnergy
The energy maximum of this thing.
-
energy
protected int energy
The current energy level of this thing.
-
energyFx
protected boolean energyFx
Flag, if energy max fx should be performed.
-
p
protected Point p
The point this figure occupies.
-
text
protected java.util.ArrayList<java.lang.String> text
Text to display
-
status
protected Status status
The current status of this thing.
-
explosionCounter
protected int explosionCounter
Counter for explosion effects.
-
shieldCount
protected int shieldCount
Current general shielding.
-
invulnCount
protected int invulnCount
Counter for invulnerability.
-
innerColor
protected int innerColor
The color for this thing.
-
outerColor
protected int outerColor
The color used for painting shadow effects.
-
energyMaxSoundPlayed
protected boolean energyMaxSoundPlayed
Flag, if sound for reached energy maximum was played
-
imageName
protected java.lang.String imageName
Name of the things image
-
isAffectedByBlack
protected boolean isAffectedByBlack
Flag, if thing is affected by holes.
-
isAffectedByGray
protected boolean isAffectedByGray
Flag, if thing is affected by gray points.
-
energyModifications
protected java.util.List<EnergyModifier> energyModifications
A list of energy modifications during one round. All energy changes are handled accumulated during updateEnergy().
-
level
protected Level level
Level this thing is used in.
-
game
protected Game game
Reference to the game.
-
nextID
public static int nextID
NextID for Player identification.
-
-
Method Detail
-
setGame
protected void setGame(Game game)
Sets the game for this thing.- Parameters:
game
- The game.
-
getField
public Field getField()
Gets the field of the current level, this item is used in.- Returns:
- The current field in the game.
-
getLevel
public Level getLevel()
Gets the current level, this item is used in.- Returns:
- The current level of the game.
-
getX
public int getX()
Returns the x coordinate of this thing.- Returns:
- The x coordinate on the field, or -1, if not placed.
-
getY
public int getY()
Returns the y coordinate of this thing.- Returns:
- The y coordinate on the field, or -1, if not placed.
-
setPoint
public void setPoint(Point p)
Sets the point this thing occupies.- Parameters:
p
- The point on the field.
-
getPoint
public Point getPoint()
Gets the point this figure occupies.- Returns:
- This things point.
-
getEnergy
public int getEnergy()
Returns the energy level of this thing.- Returns:
- The energy.
-
getMaxEnergy
public int getMaxEnergy()
Returns the maximum energy level of this thing.- Returns:
- The energy maximum.
-
getText
public java.lang.String getText()
Gets the text to display at the thing.- Returns:
- The text.
-
getTextColor
public int getTextColor()
Gets the color for a text to display at the thing.- Returns:
- The color.
-
clearTexts
public void clearTexts()
Clears the list of texts to display at the thing.
-
getTextPaintCount
public int getTextPaintCount()
Gets the counter for text display at the thing.- Returns:
- The TextPaintCount.
-
getExplosionCounter
public int getExplosionCounter()
Gets the counter for how many rounds this thing is already exploding.- Returns:
- The ExplosionCounter.
-
getOuterColor
public int getOuterColor()
Gets the outer color for painting this thing.- Returns:
- The outer color.
-
getInnerColor
public int getInnerColor()
Gets the inner color for painting this thing.- Returns:
- The outer color.
-
isShowingEnergyFx
public boolean isShowingEnergyFx()
Checks, if energy fx should be shown for this thing.- Returns:
- true, if energy fx should be shown for this thing.
-
setMaxEnergy
public void setMaxEnergy(int maxEnergy)
Sets the energy maximum for this thing.- Parameters:
maxEnergy
- The energy maximum.
-
getEnergyMaxCount
public int getEnergyMaxCount()
Gets a counter, since the energy maximum was reached.- Returns:
- A counter, since the energy maximum was reached.
-
setEnergyMaxCount
public void setEnergyMaxCount(int energyMaxCount)
Sets a counter, since the energy maximum was reached.- Parameters:
energyMaxCount
- A counter value, since the energy maximum was reached.
-
getShield
public int getShield()
Returns the current shielding against energy loss in general.- Returns:
- The shield level, or 0, if no sheilding present
-
getStatus
public Status getStatus()
Gets this figures status.- Returns:
- This things status
-
setStatus
public void setStatus(Status newStatus)
Sets this things status.- Parameters:
newStatus
- This things status
-
getImageName
public java.lang.String getImageName(AnimationInfo animation)
Returns image name relative to path /pics, without suffix. image (item paints as small oval in inner and outer color).- Parameters:
animation
- The AnimationInfo.- Returns:
- null as default.
-
getColor
public int getColor()
Returns the things color.- Returns:
- The things color
-
getShadowColor
public int getShadowColor()
Returns the things color for shadowing.- Returns:
- The things color for shadowing
-
getInvulnerableRounds
public int getInvulnerableRounds()
Returns the number of rounds, this thing is invulnerable.- Returns:
- The rounds or 0, if not invulnerable
-
invulnerable
public void invulnerable(int rounds)
Makes this thing invulnerable for the given number of rounds.- Parameters:
rounds
- The number of rounds.
-
isOK
public boolean isOK()
Checks, if the thing is ok (either normal state or invulerable).- Returns:
- true, if the figures status is OK or INVULNERABLE.
-
isExploding
public boolean isExploding()
Checks, if the thing is exploding.- Returns:
- true, if the figures status is EXPLODING.
-
isDestroyed
public boolean isDestroyed()
Checks, if the thing is destroyed.- Returns:
- true, if the figures status is DESTROYED.
-
isInvulnerable
public boolean isInvulnerable()
Checks, if the thing is invulnerable.- Returns:
- true, if the thing is invulnerable.
-
isAffectedByBlack
public boolean isAffectedByBlack()
Returns, if this thing is affected by black points.- Returns:
- true, if holes affects this thing.
-
isAffectedByGray
public boolean isAffectedByGray()
Returns, if this thing is affected by gray points.- Returns:
- true, if the gray color affects this thing.
-
entersColor
public boolean entersColor(int c, AnimationInfo animation)
Called, if the thing occupies a point with the given color. Checks immunity for black or gray, if it affects blue, or true for any other color.- Parameters:
c
- The color the entered point has.animation
- The AnimationInfo.- Returns:
- true, if the color affects this thing.
-
affectsBlue
public boolean affectsBlue()
Checks, if this thing affects blue points.- Returns:
- true, if blue point is affected.
-
staysOnColor
public boolean staysOnColor(int c, AnimationInfo animation)
Called, if the thing stays on a point with the given color. Checks immunity for black or gray, or true for any other color.- Parameters:
c
- The color the things point has.animation
- The AnimationInfo- Returns:
- true, if the color affects this thing.
-
die
public void die(Thing source, DieReason reason, AnimationInfo animation)
Sets the status of the thing to exploding (if it is not invulnerabe). Plays an explosion sound with strength 2.- Parameters:
source
- The death source.reason
- The death reason.animation
- The AnimationInfo
-
getGame
public Game getGame()
Returns the game this thing is part of. Returns null, if the field or the fields level is null.- Returns:
- The game.
-
displayText
public void displayText(java.lang.String txt)
Displays a text at the thing.- Parameters:
txt
- The text
-
displayText
public void displayText(java.lang.String txt, int color)
Displays a text at the figure.- Parameters:
txt
- The textcolor
- The text color
-
stepText
protected boolean stepText()
Displays the next text in the list.- Returns:
- true, if there's another text to display, false otherwise
-
addShielding
public void addShielding(int power)
Adds the given shielding against energy loss in general.- Parameters:
power
- The shield power equal to the damage energy level to shield against.
-
addEnergy
public void addEnergy(int newEnergy, AnimationInfo animation)
Adds the given amount to this things energy level. The energy maximum is given by the value of MAXENERGY.- Parameters:
newEnergy
- The energy to add.animation
- The AnimationInfo.
-
setEnergy
public void setEnergy(int newEnergy)
Sets this things energy level. The energy maximum is given by the value of MAXENERGY.- Parameters:
newEnergy
- The energy.
-
removeEnergy
public void removeEnergy(int min, Thing source, DieReason reason, AnimationInfo animation)
Removes the given amount from this things energy level (if it is not invulnerable). Any present shielding will first be removed. If the energy level is reduced to 0, the thing will explode.- Parameters:
min
- The energy to remove.source
- The source for the energy loss.reason
- The reason for the energy loss.animation
- The AnimationInfo.
-
onExplode
protected int onExplode(int min, Thing source, AnimationInfo animation)
Called, if energy loss with reason explode occurs. Override in subclasses to change energy losses by explosions.- Parameters:
min
- The energy loss.source
- The source of the explosion.animation
- The AnimationInfo.- Returns:
- The modified energy loss.
-
updateThing
protected void updateThing(AnimationInfo animation)
Updates this thing after each round.- Parameters:
animation
- The AnimationInfo.
-
updateExplodingStatus
protected abstract void updateExplodingStatus(AnimationInfo animation)
Handles the things status during update phase of the round when thing is exploding.- Parameters:
animation
- The AnimationInfo.
-
updateEnergy
protected void updateEnergy(AnimationInfo animation)
Updates the figures energy depending on the energy modifiers of the round.- Parameters:
animation
- The AnimationInfo.
-
onEnemyKilled
protected void onEnemyKilled(Figure figure, int roundCount, DieReason reason, AnimationInfo animation)
Called, if a figure was destroyed by this thing. Does nothing per default. Override in subclasses for some special behaviour if a figure was killed.- Parameters:
figure
- The killed figureroundCount
- The round count.reason
- The die reason.animation
- The AnimationInfo.
-
equals
public final boolean equals(java.lang.Object o)
Checks, if the other Object is a thing with the same id.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- The object to compare.- Returns:
- true, if Thing with same id is passed.
-
hashCode
public final int hashCode()
Gets the hash code.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- The things id.
-
getID
public final int getID()
Gets this figures ID.- Returns:
- The ID.
-
getNextID
public static int getNextID()
Gets the next possible ID for a figure. Calling this method is valid Integer.MAXINT times- Returns:
- a unique integer ID.
-
getName
public abstract java.lang.String getName()
Returns a display name for the thing.- Returns:
- The things name.
-
retrieveState
protected ThingState retrieveState(ThingState state, AnimationInfo animation)
Retrieves this things state in the state parameter and returns it. Call this from subclasses to store common thing properties in specialized state object.- Parameters:
state
- The state object to store information in.animation
- The AnimationInfo.- Returns:
- state.
-
addStateProperties
protected void addStateProperties(ThingState state, AnimationInfo animation)
Override in superclasses, to add properties necessary for thing painting.- Parameters:
state
- The state to add properties to.animation
- The current AnimationInfo.
-
createState
protected abstract ThingState createState(AnimationInfo animation)
-
getStateObject
protected java.lang.Object getStateObject(java.lang.Object val, AnimationInfo animation)
Might be used to retrieve a State object for a given obejct. Returns a points ID, an items or fogs state or a figures ID. The val itself for any other type.- Parameters:
val
- The value to get a state object for.animation
- The AnimationInfo.- Returns:
- The state object representing val.
-
-