Package Phase2
Class Tetris
java.lang.Object
Phase2.Tetris
public class Tetris
extends java.lang.Object
Main class used for running the Tetris (Pentris) environment.
-
Field Summary
Fields Modifier and Type Field Description static boolean
aboutToCollide
static java.lang.String
botType
static boolean
canMove
static boolean
collided
static int
curPiece
static int
curPieceRotation
static int[]
curPos
static boolean
downPressed
static boolean
enableBot
static int[][]
field
static int
fieldHeight
static int
fieldWidth
static GameWrapper
gameWrapper
static boolean
gmsdone
static boolean
go
static int
hiddenRows
static int
lastScore
static boolean
leftPressed
static int
nextPiece
static int
nextRot
static java.util.Random
rand
static boolean
rightPressed
static int
score
static int
seed
static boolean
spacePressed
static boolean
start
static int[][]
tempField
static java.util.Timer
timer
static boolean
training
static boolean
upPressed
static java.lang.Object
waitingObject
-
Constructor Summary
Constructors Constructor Description Tetris()
-
Method Summary
Modifier and Type Method Description static void
addPiece()
Method adding the current piece to the temporary field "tempField"static int[]
arrayCopy(int[] old)
Method for copying arraysstatic boolean
checkCollision(int[] nextPos, int nextRot)
Function checking if a collision is going to occurstatic int[][]
copyField(int[][] f0)
Method for copying fieldstatic int
dropPiece(boolean tentative)
Drops the current piece to the lowest level in current position xstatic void
gameOver()
Method executed in case of gameOver, resetting all parametersstatic void
getNewPiece()
Method generating a new piecestatic void
instantiateNewPiece(boolean tentative)
Method instantiating a new piecestatic void
main(java.lang.String[] args)
static boolean
movePiece(boolean right)
Method for moving piece left / rightstatic int
movePieceDown(boolean tentative)
Method checking how many rows get cleared when moving the piece downstatic void
printMatrix(int[][] m)
Method printing matrix to command line for debuggingstatic void
rotatePiece(boolean cw)
Method for rotating the current game piecestatic int
rowElimination(boolean tentative)
Method eliminating all rows that are full and updating the score accordinglystatic void
runBot()
Starts the execution of the bot, if selected to be enabledstatic void
step()
Method performing steps of the gamestatic void
wipeField(int[][] field)
Method clearing out the field
-
Field Details
-
enableBot
public static boolean enableBot -
botType
public static java.lang.String botType -
fieldWidth
public static int fieldWidth -
fieldHeight
public static int fieldHeight -
public static final int hiddenRows
- See Also:
- Constant Field Values
-
field
public static int[][] field -
tempField
public static int[][] tempField -
curPiece
public static int curPiece -
curPieceRotation
public static int curPieceRotation -
curPos
public static int[] curPos -
gameWrapper
-
canMove
public static boolean canMove -
upPressed
public static boolean upPressed -
downPressed
public static boolean downPressed -
rightPressed
public static boolean rightPressed -
leftPressed
public static boolean leftPressed -
spacePressed
public static boolean spacePressed -
go
public static boolean go -
score
public static int score -
lastScore
public static int lastScore -
seed
public static int seed -
rand
public static java.util.Random rand -
nextPiece
public static int nextPiece -
nextRot
public static int nextRot -
start
public static boolean start -
aboutToCollide
public static boolean aboutToCollide -
collided
public static boolean collided -
timer
public static java.util.Timer timer -
training
public static boolean training -
gmsdone
public static boolean gmsdone -
waitingObject
public static final java.lang.Object waitingObject
-
-
Constructor Details
-
Tetris
public Tetris()
-
-
Method Details
-
step
public static void step() throws java.io.IOExceptionMethod performing steps of the game- Throws:
java.io.IOException
-
wipeField
public static void wipeField(int[][] field)Method clearing out the field- Parameters:
field
- : field to be wiped (all field values reassigned to -1)
-
instantiateNewPiece
public static void instantiateNewPiece(boolean tentative)Method instantiating a new piece- Parameters:
tentative
- : parameter defining if the action is performed tentatively
-
addPiece
public static void addPiece()Method adding the current piece to the temporary field "tempField" -
printMatrix
public static void printMatrix(int[][] m)Method printing matrix to command line for debugging- Parameters:
m
- : matrix to be printed to command line
-
getNewPiece
public static void getNewPiece()Method generating a new piece -
gameOver
public static void gameOver()Method executed in case of gameOver, resetting all parameters -
rotatePiece
public static void rotatePiece(boolean cw)Method for rotating the current game piece- Parameters:
cw
- : parameter true when rotating clockwise and false when rotating counter-clockwise
-
movePiece
public static boolean movePiece(boolean right)Method for moving piece left / right- Parameters:
right
- : true when moving right, false when moving left- Returns:
- true if piece was moved, false otherwise
-
checkCollision
public static boolean checkCollision(int[] nextPos, int nextRot)Function checking if a collision is going to occur- Parameters:
nextPos
- : next position of current piecenextRot
- : next rotation of current piece- Returns:
- true if collision occurs, else false
-
dropPiece
public static int dropPiece(boolean tentative)Drops the current piece to the lowest level in current position x -
arrayCopy
public static int[] arrayCopy(int[] old)Method for copying arrays- Parameters:
old
- : old array- Returns:
- new copy of the old array
-
movePieceDown
public static int movePieceDown(boolean tentative)Method checking how many rows get cleared when moving the piece down- Parameters:
tentative
- : true when piece moved down tentatively (without UI updates), false otherwise- Returns:
- number of consecutively removed rows
-
rowElimination
public static int rowElimination(boolean tentative)Method eliminating all rows that are full and updating the score accordingly- Parameters:
tentative
- : true when row eliminated tentatively, false otherwise- Returns:
- number of consecutively removed rows
-
copyField
public static int[][] copyField(int[][] f0)Method for copying field- Parameters:
f0
- : field to be copied- Returns:
- a copy of field f0
-
runBot
public static void runBot() throws java.lang.InterruptedExceptionStarts the execution of the bot, if selected to be enabled- Throws:
java.lang.InterruptedException
-
main
public static void main(java.lang.String[] args) throws java.io.IOException, java.lang.InterruptedException- Throws:
java.io.IOException
java.lang.InterruptedException
-