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 booleanaboutToCollidestatic java.lang.StringbotTypestatic booleancanMovestatic booleancollidedstatic intcurPiecestatic intcurPieceRotationstatic int[]curPosstatic booleandownPressedstatic booleanenableBotstatic int[][]fieldstatic intfieldHeightstatic intfieldWidthstatic GameWrappergameWrapperstatic booleangmsdonestatic booleangostatic inthiddenRowsstatic intlastScorestatic booleanleftPressedstatic intnextPiecestatic intnextRotstatic java.util.Randomrandstatic booleanrightPressedstatic intscorestatic intseedstatic booleanspacePressedstatic booleanstartstatic int[][]tempFieldstatic java.util.Timertimerstatic booleantrainingstatic booleanupPressedstatic java.lang.ObjectwaitingObject -
Constructor Summary
Constructors Constructor Description Tetris() -
Method Summary
Modifier and Type Method Description static voidaddPiece()Method adding the current piece to the temporary field "tempField"static int[]arrayCopy(int[] old)Method for copying arraysstatic booleancheckCollision(int[] nextPos, int nextRot)Function checking if a collision is going to occurstatic int[][]copyField(int[][] f0)Method for copying fieldstatic intdropPiece(boolean tentative)Drops the current piece to the lowest level in current position xstatic voidgameOver()Method executed in case of gameOver, resetting all parametersstatic voidgetNewPiece()Method generating a new piecestatic voidinstantiateNewPiece(boolean tentative)Method instantiating a new piecestatic voidmain(java.lang.String[] args)static booleanmovePiece(boolean right)Method for moving piece left / rightstatic intmovePieceDown(boolean tentative)Method checking how many rows get cleared when moving the piece downstatic voidprintMatrix(int[][] m)Method printing matrix to command line for debuggingstatic voidrotatePiece(boolean cw)Method for rotating the current game piecestatic introwElimination(boolean tentative)Method eliminating all rows that are full and updating the score accordinglystatic voidrunBot()Starts the execution of the bot, if selected to be enabledstatic voidstep()Method performing steps of the gamestatic voidwipeField(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.IOExceptionjava.lang.InterruptedException
-