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 arrays
    static boolean checkCollision​(int[] nextPos, int nextRot)
    Function checking if a collision is going to occur
    static int[][] copyField​(int[][] f0)
    Method for copying field
    static int dropPiece​(boolean tentative)
    Drops the current piece to the lowest level in current position x
    static void gameOver()
    Method executed in case of gameOver, resetting all parameters
    static void getNewPiece()
    Method generating a new piece
    static void instantiateNewPiece​(boolean tentative)
    Method instantiating a new piece
    static void main​(java.lang.String[] args)  
    static boolean movePiece​(boolean right)
    Method for moving piece left / right
    static int movePieceDown​(boolean tentative)
    Method checking how many rows get cleared when moving the piece down
    static void printMatrix​(int[][] m)
    Method printing matrix to command line for debugging
    static void rotatePiece​(boolean cw)
    Method for rotating the current game piece
    static int rowElimination​(boolean tentative)
    Method eliminating all rows that are full and updating the score accordingly
    static void runBot()
    Starts the execution of the bot, if selected to be enabled
    static void step()
    Method performing steps of the game
    static void wipeField​(int[][] field)
    Method clearing out the field

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • step

      public static void step() throws java.io.IOException
      Method 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 piece
      nextRot - : 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.InterruptedException
      Starts 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