public abstract class Game
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected class |
Game.Bucket
Class for helping collision detection.
|
Modifier and Type | Field and Description |
---|---|
protected MovingAvatar |
avatar
Quick reference to the gamer
|
protected int |
block_size
Size of the block in pixels.
|
protected Game.Bucket[] |
bucketList
Arraylist to hold collisions between objects in every frame
|
protected java.util.HashMap<java.lang.Character,java.util.ArrayList<java.lang.String>> |
charMapping
Mapping between characters in the level and the entities they represent.
|
protected Content[] |
classConst
Content objects for the different sprite types..
|
protected java.util.ArrayList<Effect>[][] |
collisionEffects
Relationships for collisions: double array of (list of) effects.
|
protected java.util.ArrayList<Pair> |
definedEffects
Pairs of all defined effects in the game.
|
protected java.util.ArrayList<java.lang.Integer> |
definedEOSEffects
List of types that can trigger an EOS effect.
|
protected java.util.ArrayList<Effect>[] |
eosEffects
List of EOS effects
|
protected int |
frame_rate
Default frame rate of the basic game.
|
protected ForwardModel |
fwdModel
State observation for this game.
|
protected int |
gameTick
Game tick
|
protected java.util.TreeSet<Event> |
historicEvents
Historic of events related to the avatar happened during the game.
|
protected boolean |
is_stochastic
Indicates if the game is stochastic.
|
protected boolean |
isEnded
Indicates if the game is ended.
|
protected java.util.ArrayList<java.lang.Integer>[] |
iSubTypes
For each entry, int identifier of sprite type, a list with all the itypes this
sprite belongs to.
|
static KeyInput |
ki
Key input
|
protected java.util.ArrayList<VGDLSprite> |
kill_list
List of sprites killed in the game.
|
protected int |
MAX_SPRITES
Maximum number of sprites in a game.
|
protected int |
nextSpriteID
Next ID to generate for sprites;
|
protected int |
num_sprites
Number of sprites this game has.
|
protected java.awt.Color[] |
resources_colors
Color for each resource
|
protected int[] |
resources_limits
Limit number of each resource type
|
protected double |
score
Score of the game.
|
protected java.awt.Dimension |
screenSize
Screen size.
|
protected boolean[] |
singletons
Singletons of the game.
|
protected java.awt.Dimension |
size
Dimensions of the game.
|
protected SpriteGroup[] |
spriteGroups
Groups of sprites in the level.
|
protected int[] |
spriteOrder
z-level of sprite types (in case of overlap)
|
protected java.util.ArrayList<Termination> |
terminations
Termination set conditions to finish the game.
|
protected Types.WINNER |
winner
Indicates if the game has been won by the player.
|
Constructor and Description |
---|
Game()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
_updateCollisionDict(VGDLSprite sprite) |
VGDLSprite |
addSprite(int itype,
Vector2d position)
Adds a sprite given a content and position.
|
VGDLSprite |
addSprite(SpriteContent content,
Vector2d position,
int itype)
Adds a sprite given a content and position.
|
protected void |
addSprite(VGDLSprite sprite,
int itype)
Adds a new sprite to the pool of sprites of the game.
|
abstract void |
buildLevel(java.lang.String gamelvl)
Builds a level, receiving a file name.
|
protected void |
checkTimeOut()
Checks if the game must finish because of number of cycles played.
|
protected void |
clearAll()
Deletes all the sprites killed in the previous step.
|
void |
disqualify()
Disqualifies the player in the game, and also sets the isEnded flag to true.
|
protected void |
eventHandling()
Handles collisions and triggers events.
|
MovingAvatar |
getAvatar()
Returns the avatar of the game.
|
java.util.HashMap<java.lang.Character,java.util.ArrayList<java.lang.String>> |
getCharMapping()
Returns the char mapping of this array, that relates characters in the level with
sprite names that it references.
|
java.util.ArrayList<Effect> |
getCollisionEffects(int spriteItype1,
int spriteItype2)
Gets the array of collisions defined for two types of sprites.
|
java.util.ArrayList<Pair> |
getDefinedEffects()
Returns all paired effects defined in the game.
|
java.util.ArrayList<java.lang.Integer> |
getDefinedEosEffects()
Returns the list of sprite type with at least one EOS effect defined.
|
java.util.ArrayList<Effect> |
getEosEffects(int obj1)
Returns all EOS effects defined in the game.
|
int |
getGameTick()
Returns the current game tick of this game.
|
int |
getNumSprites(int itype)
Returns the number of sprites of the type given by parameter, and all its subtypes
|
StateObservation |
getObservation()
Retuns the observation of this state.
|
java.util.Random |
getRandomGenerator()
Returns the sampleRandom object
|
java.awt.Color |
getResourceColor(int resourceId)
Gets the color of the resource of type resourceId
|
int |
getResourceLimit(int resourceId)
Gets the maximum amount of resources of type resourceId that are allowed by entities in the game.
|
java.awt.Dimension |
getScreenSize()
Gets the dimensions of the screen.
|
java.util.Iterator<VGDLSprite> |
getSpriteGroup(int spriteItype)
Gets an iterator for the collection of sprites for a particular sprite type.
|
int[] |
getSpriteOrder()
Gets the order in which the sprites are drawn.
|
java.util.TreeMap<java.lang.Integer,VGDLSprite> |
getSprites(int spriteItype)
Gets the collection of sprites for a particular sprite type.
|
java.util.ArrayList<Termination> |
getTerminations()
Gets the array of termination conditions for this game.
|
Types.WINNER |
getWinner()
Returns the winner of this game.
|
void |
initForwardModel()
Starts the forward model for the game.
|
void |
initSprites(java.util.ArrayList<java.lang.Integer> spOrder,
java.util.ArrayList<java.lang.Integer> sings,
java.util.HashMap<java.lang.Integer,SpriteContent> constructors)
Initializes the sprite structures that hold the game.
|
boolean |
isGameOver()
Indicates if the game is over, or if it is still being played.
|
void |
killSprite(VGDLSprite sprite)
Kills a given sprite, adding it to the list of sprites killed at this step.
|
protected void |
parseParameters(GameContent content)
Reads the parameters of a game type.
|
double |
playGame(AbstractPlayer player,
int randomSeed)
Plays the game, graphics enabled.
|
void |
reset()
Sets the game back to the state prior to load a level.
|
void |
reverseDirection(VGDLSprite sprite)
Reverses the direction of a given sprite.
|
double |
runGame(AbstractPlayer player,
int randomSeed)
Runs a game, without graphics.
|
void |
setAvatar(MovingAvatar newAvatar)
Sets the avatar of the game.
|
void |
setStochastic(boolean stoch)
Defines this game as stochastic (or not) depending on the parameter passed.
|
protected void |
terminationHandling()
Handles termination conditions, for every termination defined in 'terminations' array.
|
protected void |
tick()
Performs one tick for the game: calling update(this) in all sprites.
|
protected int[] spriteOrder
protected boolean[] singletons
protected Content[] classConst
protected SpriteGroup[] spriteGroups
protected java.util.ArrayList<Effect>[][] collisionEffects
protected java.util.ArrayList<Pair> definedEffects
protected java.util.ArrayList<Effect>[] eosEffects
protected java.util.ArrayList<java.lang.Integer> definedEOSEffects
protected java.util.TreeSet<Event> historicEvents
protected java.util.ArrayList<java.lang.Integer>[] iSubTypes
protected Game.Bucket[] bucketList
protected java.util.HashMap<java.lang.Character,java.util.ArrayList<java.lang.String>> charMapping
protected java.util.ArrayList<Termination> terminations
protected java.util.ArrayList<VGDLSprite> kill_list
protected int[] resources_limits
protected java.awt.Color[] resources_colors
protected java.awt.Dimension screenSize
protected java.awt.Dimension size
protected boolean is_stochastic
protected int num_sprites
protected int gameTick
public static KeyInput ki
protected int block_size
protected MovingAvatar avatar
protected boolean isEnded
protected Types.WINNER winner
protected int frame_rate
protected ForwardModel fwdModel
protected double score
protected int MAX_SPRITES
protected int nextSpriteID
public void initSprites(java.util.ArrayList<java.lang.Integer> spOrder, java.util.ArrayList<java.lang.Integer> sings, java.util.HashMap<java.lang.Integer,SpriteContent> constructors)
spOrder
- order of sprite types to be drawn on the screen.sings
- sprites that are marked as singletons.constructors
- map of sprite constructor's information.public void reset()
public void initForwardModel()
protected void parseParameters(GameContent content)
content
- list of parameter-value pairs.protected void addSprite(VGDLSprite sprite, int itype)
sprite
- the new sprite to add.itype
- main int type of this sprite (leaf of the hierarchy of types).public int getNumSprites(int itype)
itype
- parent itype requested.public double runGame(AbstractPlayer player, int randomSeed)
player
- Player that plays this game.randomSeed
- sampleRandom seed for the whole game.public double playGame(AbstractPlayer player, int randomSeed)
player
- Player that plays this game.randomSeed
- sampleRandom seed for the whole game.protected void checkTimeOut()
public void disqualify()
protected void tick()
protected void eventHandling()
protected void terminationHandling()
protected void clearAll()
public VGDLSprite addSprite(int itype, Vector2d position)
itype
- integer that identifies the definition of the sprite to addposition
- where the sprite has to be placed.public VGDLSprite addSprite(SpriteContent content, Vector2d position, int itype)
content
- definition of the sprite to addposition
- where the sprite has to be placed.itype
- integer identifier of this type of sprite.public void _updateCollisionDict(VGDLSprite sprite)
public void reverseDirection(VGDLSprite sprite)
sprite
- sprite to reverse.public void killSprite(VGDLSprite sprite)
sprite
- the sprite to kill.public java.util.Iterator<VGDLSprite> getSpriteGroup(int spriteItype)
spriteItype
- type of the sprite to retrieve.public java.util.TreeMap<java.lang.Integer,VGDLSprite> getSprites(int spriteItype)
spriteItype
- type of the sprite to retrieve.public java.util.ArrayList<Effect> getCollisionEffects(int spriteItype1, int spriteItype2)
spriteItype1
- type of the first sprite.spriteItype2
- type of the second sprite.public java.util.ArrayList<Pair> getDefinedEffects()
public java.util.ArrayList<java.lang.Integer> getDefinedEosEffects()
public java.util.ArrayList<Effect> getEosEffects(int obj1)
public java.util.HashMap<java.lang.Character,java.util.ArrayList<java.lang.String>> getCharMapping()
public java.util.ArrayList<Termination> getTerminations()
public int getResourceLimit(int resourceId)
resourceId
- the id of the resource to query for.public java.awt.Color getResourceColor(int resourceId)
resourceId
- id of the resource to query for.public java.awt.Dimension getScreenSize()
public void setStochastic(boolean stoch)
stoch
- true if the game is stochastic.public MovingAvatar getAvatar()
public void setAvatar(MovingAvatar newAvatar)
newAvatar
- the avatar of the game.public boolean isGameOver()
public StateObservation getObservation()
public java.util.Random getRandomGenerator()
public int getGameTick()
public Types.WINNER getWinner()
public int[] getSpriteOrder()
public abstract void buildLevel(java.lang.String gamelvl)
gamelvl
- file name containing the level.