org.eviline
Class Field

java.lang.Object
  extended by org.eviline.Field
All Implemented Interfaces:
Serializable

public class Field
extends Object
implements Serializable

Object which keeps track of the tetris matrix itself. It keeps an array of Block enums to store the state of the matrix, using null to store an empty area.

This is the "engine" of tetrevil.

Author:
robin
See Also:
Serialized Form

Field Summary
protected  ShapeDirection autoShift
          The direction of the currently active DAS
static int BUFFER
          The size of the buffer area around the matrix in each direction
protected  EventDispatcher dispatcher
           
protected  Block[][] field
          The matrix itself
protected  boolean gameOver
          Whether a game is over
protected  int garbage
           
protected  boolean ghosting
          Whether ghosting is enabled
protected  int ghostY
          The vertical position of the current shape's ghost
static int HEIGHT
          The height of the matrix
protected  int lines
          The number of lines scored so far
protected  EvilineListener[] listeners
          Event listeners
protected  BlockMetadata[][] metadata
           
protected  boolean multiplayer
           
protected  boolean paused
          Whether a game is paused
protected  boolean playing
          Whether a game is playing
protected  Randomizer provider
          The source of shapes
protected  double score
           
protected  double scoreFactor
           
protected  Shape shape
          The current shape
protected  int shapeId
           
protected  int shapeX
          The horizontal position of the current shape
protected  int shapeY
          The vertical position of the current shape
protected  boolean unpausable
           
static int WIDTH
          The width of the matrix
protected  boolean winner
           
 
Constructor Summary
Field()
           
 
Method Summary
 void addEvilineListener(EvilineListener l)
          Add a tetrevil listener to this field
protected  void applyGarbage()
           
 void autoshift()
          Auto-shift the current shape all the way to the left or right.
 void clockTick()
          Cause one clock tick.
 Field copy()
           
 Field copyInto(Field target)
          Copy this Field into a target and return the target.
protected  void fireClockTicked()
           
protected  void fireGameOver()
           
protected  void fireGamePaused()
           
protected  void fireGameReset()
           
protected  void fireGarbageReceived(int lines)
           
protected  void fireHardDropped()
           
protected  void fireLinesCleared(int lines)
           
protected  void fireRotatedLeft()
           
protected  void fireRotatedRight()
           
protected  void fireShapeLocked()
           
protected  void fireShapeSpawned()
           
protected  void fireShiftedLeft()
           
protected  void fireShiftedRight()
           
 void garbage(int lines)
           
 ShapeDirection getAutoShift()
           
 Block getBlock(int x, int y)
          Return the block at the specified x,y pair, with the current shape and current ghost applied.
 Block[][] getField()
           
 Block getFieldBlock(int x, int y)
           
 int getGhostY()
           
 int getLines()
           
 BlockMetadata getMetadata(int x, int y)
           
 Randomizer getProvider()
           
 double getScore()
           
 double getScoreFactor()
           
 Shape getShape()
           
 int getShapeX()
           
 int getShapeY()
           
 void hardDrop()
           
 boolean isGameOver()
           
 boolean isGhosting()
           
 boolean isGrounded()
          Returns whether the current shape is "grounded", e.g.
 boolean isMultiplayer()
           
 boolean isPaused()
           
 boolean isPlaying()
           
 boolean isUnpausable()
           
 boolean isWinner()
           
 Field newInstance()
           
 void reghost()
          Recalculate the ghost location
 void removeEvilineListener(EvilineListener l)
          Remove a tetrevil listener from this field
 void reset()
          Reset the field
 void reverseRotateLeft()
           
 void reverseRotateRight()
           
 void rotateLeft()
          Counter-clockwise shape rotation
 void rotateRight()
          Clockwise shape rotation
 void setAutoShift(ShapeDirection autoShift)
           
 void setField(Block[][] field)
           
 void setGameOver(boolean gameOver)
           
 void setGhosting(boolean ghosting)
           
 void setLines(int lines)
           
 void setMultiplayer(boolean multiplayer)
           
 void setPaused(boolean paused)
           
 void setProvider(Randomizer provider)
           
 void setScore(double score)
           
 void setScoreFactor(double scoreFactor)
           
 void setShape(Shape shape)
           
 void setShapeX(int shapeX)
           
 void setShapeY(int shapeY)
           
 void setUnpausable(boolean unpausable)
           
 void setWinner(boolean winner)
           
 void shiftDown()
           
 void shiftLeft()
          Shift the current shape one to the left
 void shiftRight()
          Shift the current shape one to the right
 void softDrop()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HEIGHT

public static final int HEIGHT
The height of the matrix

See Also:
Constant Field Values

WIDTH

public static final int WIDTH
The width of the matrix

See Also:
Constant Field Values

BUFFER

public static final int BUFFER
The size of the buffer area around the matrix in each direction

See Also:
Constant Field Values

field

protected Block[][] field
The matrix itself


metadata

protected transient BlockMetadata[][] metadata

provider

protected Randomizer provider
The source of shapes


shape

protected Shape shape
The current shape


shapeX

protected int shapeX
The horizontal position of the current shape


shapeY

protected int shapeY
The vertical position of the current shape


ghosting

protected boolean ghosting
Whether ghosting is enabled


ghostY

protected int ghostY
The vertical position of the current shape's ghost


playing

protected boolean playing
Whether a game is playing


gameOver

protected boolean gameOver
Whether a game is over


paused

protected boolean paused
Whether a game is paused


garbage

protected int garbage

lines

protected int lines
The number of lines scored so far


score

protected double score

scoreFactor

protected double scoreFactor

autoShift

protected ShapeDirection autoShift
The direction of the currently active DAS


unpausable

protected boolean unpausable

winner

protected transient boolean winner

multiplayer

protected transient boolean multiplayer

shapeId

protected transient int shapeId

listeners

protected transient EvilineListener[] listeners
Event listeners


dispatcher

protected transient EventDispatcher dispatcher
Constructor Detail

Field

public Field()
Method Detail

newInstance

public Field newInstance()

copyInto

public Field copyInto(Field target)
Copy this Field into a target and return the target.

Parameters:
target - The destination and return Field
Returns:
The target

copy

public Field copy()

reset

public void reset()
Reset the field


clockTick

public void clockTick()
Cause one clock tick. One clock tick means one movement of gravity downwards. Tetrevil does not keep a separate 60Hz clock, or some other such independent clock.


isGrounded

public boolean isGrounded()
Returns whether the current shape is "grounded", e.g. can be locked but isn't

Returns:

shiftLeft

public void shiftLeft()
Shift the current shape one to the left


shiftRight

public void shiftRight()
Shift the current shape one to the right


shiftDown

public void shiftDown()

softDrop

public void softDrop()

hardDrop

public void hardDrop()

autoshift

public void autoshift()
Auto-shift the current shape all the way to the left or right.


reghost

public void reghost()
Recalculate the ghost location


rotateLeft

public void rotateLeft()
Counter-clockwise shape rotation


reverseRotateLeft

public void reverseRotateLeft()

rotateRight

public void rotateRight()
Clockwise shape rotation


reverseRotateRight

public void reverseRotateRight()

garbage

public void garbage(int lines)

applyGarbage

protected void applyGarbage()

getBlock

public Block getBlock(int x,
                      int y)
Return the block at the specified x,y pair, with the current shape and current ghost applied. Used by field renderers such as TetrevilTableModel

Parameters:
x -
y -
Returns:

getFieldBlock

public Block getFieldBlock(int x,
                           int y)

getMetadata

public BlockMetadata getMetadata(int x,
                                 int y)

addEvilineListener

public void addEvilineListener(EvilineListener l)
Add a tetrevil listener to this field

Parameters:
l -

removeEvilineListener

public void removeEvilineListener(EvilineListener l)
Remove a tetrevil listener from this field

Parameters:
l -

fireClockTicked

protected void fireClockTicked()

fireGameOver

protected void fireGameOver()

fireGamePaused

protected void fireGamePaused()

fireGameReset

protected void fireGameReset()

fireShiftedLeft

protected void fireShiftedLeft()

fireShiftedRight

protected void fireShiftedRight()

fireRotatedLeft

protected void fireRotatedLeft()

fireRotatedRight

protected void fireRotatedRight()

fireLinesCleared

protected void fireLinesCleared(int lines)

fireGarbageReceived

protected void fireGarbageReceived(int lines)

fireShapeSpawned

protected void fireShapeSpawned()

fireShapeLocked

protected void fireShapeLocked()

fireHardDropped

protected void fireHardDropped()

getProvider

public Randomizer getProvider()

setProvider

public void setProvider(Randomizer provider)

getShape

public Shape getShape()

getShapeX

public int getShapeX()

getShapeY

public int getShapeY()

getGhostY

public int getGhostY()

isGameOver

public boolean isGameOver()

setShape

public void setShape(Shape shape)

setShapeX

public void setShapeX(int shapeX)

setShapeY

public void setShapeY(int shapeY)

setGameOver

public void setGameOver(boolean gameOver)

getLines

public int getLines()

setLines

public void setLines(int lines)

isPaused

public boolean isPaused()

setPaused

public void setPaused(boolean paused)

getAutoShift

public ShapeDirection getAutoShift()

setAutoShift

public void setAutoShift(ShapeDirection autoShift)

getField

public Block[][] getField()

setField

public void setField(Block[][] field)

isGhosting

public boolean isGhosting()

setGhosting

public void setGhosting(boolean ghosting)

isUnpausable

public boolean isUnpausable()

setUnpausable

public void setUnpausable(boolean unpausable)

isPlaying

public boolean isPlaying()

isWinner

public boolean isWinner()

setWinner

public void setWinner(boolean winner)

isMultiplayer

public boolean isMultiplayer()

setMultiplayer

public void setMultiplayer(boolean multiplayer)

toString

public String toString()
Overrides:
toString in class Object

getScore

public double getScore()

setScore

public void setScore(double score)

getScoreFactor

public double getScoreFactor()

setScoreFactor

public void setScoreFactor(double scoreFactor)


Copyright © 2013. All Rights Reserved.