Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7513405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:10:33+00:00 2026-05-30T00:10:33+00:00

public static final int SQUARE = 0, LINE = 1, S_FIGURE = 2, Z_FIGURE

  • 0
public static final int SQUARE = 0,
                        LINE  = 1,
                        S_FIGURE = 2,
                        Z_FIGURE = 3,
                        RIGHT_ANGLE_FIGURE = 4,
                        LEFT_ANGLE_FIGURE = 5,
                        TRIANGLE = 6;

Here above is my Tetris midlet/J2ME code for the block. But i don’t know how to explain these parameters. can anyone give me advice? Let me know if you need the full code to work.

this is my full code:

public class Block {
public static final int SQUARE = 0,
                        LINE  = 1,
                        S_FIGURE = 2,
                        Z_FIGURE = 3,
                        RIGHT_ANGLE_FIGURE = 4,
                        LEFT_ANGLE_FIGURE = 5,
                        TRIANGLE = 6;
public int kind;
public int color;
/**
 * The horizontal figure position on the board. This value has no
 * meaning when the figure is not attached to a square board.
 */
public int xPos = 0;

/**
 * The vertical figure position on the board. This value has no
 * meaning when the figure is not attached to a square board.
 */
public int yPos = 0;

/**
 * The figure orientation (or rotation). This value is normally
 * between 0 and 3, but must also be less than the maxOrientation
 * value.
 *
 * @see #maxOrientation
 */
private int orientation = 0;

public int maxOrientation;

public int[] shapeX, shapeY;

private GameCanvas board = null;

public Block(int k) {
    shapeX = new int[4];
    shapeY = new int[4];
    initialize(k);
    this.kind = k;
}

private void initialize(int kind) {
    switch (kind) {
        case SQUARE :
            maxOrientation = 1;
            color = 0x0000ff; // blau
            shapeX[0] = -1;
            shapeY[0] = 0;
            shapeX[1] = 0;
            shapeY[1] = 0;
            shapeX[2] = -1;
            shapeY[2] = 1;
            shapeX[3] = 0;
            shapeY[3] = 1;
            break;
        case LINE :
            maxOrientation = 2;
            color = 0xff0000; // rot
            shapeX[0] = -2;
            shapeY[0] = 0;
            shapeX[1] = -1;
            shapeY[1] = 0;
            shapeX[2] = 0;
            shapeY[2] = 0;
            shapeX[3] = 1;
            shapeY[3] = 0;
            break;
        case S_FIGURE :
            maxOrientation = 2;
            color = 0xff00ff; // lila
            shapeX[0] = 0;
            shapeY[0] = 0;
            shapeX[1] = 1;
            shapeY[1] = 0;
            shapeX[2] = -1;
            shapeY[2] = 1;
            shapeX[3] = 0;
            shapeY[3] = 1;
            break;
        case Z_FIGURE :
            maxOrientation = 2;
            color = 0x008000; // grün
            shapeX[0] = -1;
            shapeY[0] = 0;
            shapeX[1] = 0;
            shapeY[1] = 0;
            shapeX[2] = 0;
            shapeY[2] = 1;
            shapeX[3] = 1;
            shapeY[3] = 1;
            break;
        case RIGHT_ANGLE_FIGURE :
            maxOrientation = 4;
            color = 0x800080; // violett
            shapeX[0] = -1;
            shapeY[0] = 0;
            shapeX[1] = 0;
            shapeY[1] = 0;
            shapeX[2] = 1;
            shapeY[2] = 0;
            shapeX[3] = 1;
            shapeY[3] = 1;
            break;
        case LEFT_ANGLE_FIGURE :
            maxOrientation = 4;
            color = 0x000000; // schwarz
            shapeX[0] = -1;
            shapeY[0] = 0;
            shapeX[1] = 0;
            shapeY[1] = 0;
            shapeX[2] = 1;
            shapeY[2] = 0;
            shapeX[3] = -1;
            shapeY[3] = 1;
            break;
        case TRIANGLE :
            maxOrientation = 4; // gelb
            color = 0xCECE00;
            shapeX[0] = -1;
            shapeY[0] = 0;
            shapeX[1] = 0;
            shapeY[1] = 0;
            shapeX[2] = 1;
            shapeY[2] = 0;
            shapeX[3] = 0;
            shapeY[3] = 1;
            break;
    }
}

/**
 * Checks if this figure is attached to a square board.
 *
 * @return true if the figure is already attached, or
 *         false otherwise
 */
public boolean isAttached() {
    return board != null;
}

public boolean attach(GameCanvas board, boolean center) {
    int  newX;
    int  newY;
    int  i;

    // Check for previous attachment
    if (isAttached()) {
        detach();
    }

    // Reset position (for correct controls)
    xPos = 0;
    yPos = 0;

    // Calculate position
    newX = board.getBoardWidth() / 2;
    if (center) {
        newY = board.getBoardHeight() / 2;
    } else {
        newY = 0;
        for (i = 0; i < shapeX.length; i++) {
            if (getRelativeY(i, orientation) < 0 && getRelativeY(i, orientation)<newY) {
                newY = Math.abs(getRelativeY(i, orientation))+1;
            }
        }

    }

    // Check position
    this.board = board;
    if (!canMoveTo(newX, newY, orientation)) {
        this.board = null;
        return false;
    }

    // Draw figure
    xPos = newX;
    yPos = newY;
    paint(color);
    board.repaint();

    return true;
}

/**
 * Checks if the figure is fully visible on the square board. If
 * the figure isn't attached to a board, false will be returned.
 *
 * @return true if the figure is fully visible, or
 *         false otherwise
 */
public boolean isAllVisible() {
    if (!isAttached()) {
        return false;
    }
    for (int i = 0; i < shapeX.length; i++) {
        if (yPos + getRelativeY(i, orientation) < 0) {
            return false;
        }
    }
    return true;
}

/**
 * Detaches this figure from its square board. The figure will not
 * be removed from the board by this operation, resulting in the
 * figure being left intact.
 */
public void detach() {
    board = null;
}

/**
 * Checks if the figure has landed. If this method returns true,
 * the moveDown() or the moveAllWayDown() methods should have no
 * effect. If no square board is attached, this method will return
 * true.
 *
 * @return true if the figure has landed, or false otherwise
 */
public boolean hasLanded() {
    return !isAttached() || !canMoveTo(xPos, yPos + 1, orientation);
}

/**
 * Moves the figure one step to the left. If such a move is not
 * possible with respect to the square board, nothing is done. The
 * square board will be changed as the figure moves, clearing the
 * previous cells. If no square board is attached, nothing is
 * done.
 */
public void moveLeft() {
    if (isAttached() && canMoveTo(xPos - 1, yPos, orientation)) {
        paint(-1);
        xPos--;
        paint(color);
        board.repaint();
    }
}

/**
 * Moves the figure one step to the right. If such a move is not
 * possible with respect to the square board, nothing is done. The
 * square board will be changed as the figure moves, clearing the
 * previous cells. If no square board is attached, nothing is
 * done.
 */
public void moveRight() {
    if (isAttached() && canMoveTo(xPos + 1, yPos, orientation)) {
        paint(-1);
        xPos++;
        paint(color);
        board.repaint();
    }
}

/**
 * Moves the figure one step down. If such a move is not possible
 * with respect to the square board, nothing is done. The square
 * board will be changed as the figure moves, clearing the
 * previous cells. If no square board is attached, nothing is
 * done.
 */
public void moveDown() {
    if (isAttached() && canMoveTo(xPos, yPos + 1, orientation)) {
        paint(-1);
        yPos++;
        paint(color);
        board.repaint();
    }
}

/**
 * Moves the figure all the way down. The limits of the move are
 * either the square board bottom, or squares not being empty. If
 * no move is possible with respect to the square board, nothing
 * is done. The square board will be changed as the figure moves,
 * clearing the previous cells. If no square board is attached,
 * nothing is done.
 */
public void moveAllWayDown() {
    int y = yPos;

    // Check for board
    if (!isAttached()) {
        return;
    }

    // Find lowest position
    while (canMoveTo(xPos, y + 1, orientation)) {
        y++;
    }

    // Update
    if (y != yPos) {
        paint(-1);
        yPos = y;
        paint(color);
        board.repaint();
    }
}

/**
 * Returns the current figure rotation (orientation).
 *
 * @return the current figure rotation
 */
public int getRotation() {
    return orientation;
}

/**
 * Sets the figure rotation (orientation). If the desired rotation
 * is not possible with respect to the square board, nothing is
 * done. The square board will be changed as the figure moves,
 * clearing the previous cells. If no square board is attached,
 * the rotation is performed directly.
 *
 * @param rotation  the new figure orientation
 */
public void setRotation(int rotation) {
    int newOrientation;

    // Set new orientation
    newOrientation = rotation % maxOrientation;

    // Check new position
    if (!isAttached()) {
        orientation = newOrientation;
    } else if (canMoveTo(xPos, yPos, newOrientation)) {
        paint(-1);
        orientation = newOrientation;
        paint(color);
        board.repaint();
    }
}

/**
 * Rotates the figure clockwise. If such a rotation is not
 * possible with respect to the square board, nothing is done.
 * The square board will be changed as the figure moves,
 * clearing the previous cells. If no square board is attached,
 * the rotation is performed directly.
 */
public void rotateClockwise() {
    if (maxOrientation == 1) {
        return;
    } else {
        setRotation((orientation + 1) % maxOrientation);
    }
}

/**
 * Rotates the figure counter-clockwise. If such a rotation
 * is not possible with respect to the square board, nothing
 * is done. The square board will be changed as the figure
 * moves, clearing the previous cells. If no square board is
 * attached, the rotation is performed directly.
 */
public void rotateCounterClockwise() {
    if (maxOrientation == 1) {
        return;
    } else {
        setRotation((orientation + 3) % 4);
    }
}

/**
 * Checks if a specified pair of (square) coordinates are inside
 * the figure, or not.
 *
 * @param x         the horizontal position
 * @param y         the vertical position
 *
 * @return true if the coordinates are inside the figure, or
 *         false otherwise
 */
private boolean isInside(int x, int y) {
    for (int i = 0; i < shapeX.length; i++) {
        if (x == xPos + getRelativeX(i, orientation)
                && y == yPos + getRelativeY(i, orientation)) {

            return true;
        }
    }
    return false;
}

/**
 * Checks if the figure can move to a new position. The current
 * figure position is taken into account when checking for
 * collisions. If a collision is detected, this method will return
 * false.
 *
 * @param newX            the new horizontal position
 * @param newY            the new vertical position
 * @param newOrientation  the new orientation (rotation)
 *
 * @return true if the figure can be moved, or
 *         false otherwise
 */
private boolean canMoveTo(int newX, int newY, int newOrientation) {
    int  x;
    int  y;

    for (int i = 0; i < 4; i++) {
        x = newX + getRelativeX(i, newOrientation);
        y = newY + getRelativeY(i, newOrientation);
        if (!isInside(x, y) && !board.isSquareEmpty(x, y)) {
            return false;
        }
    }
    return true;
}

/**
 * Returns the relative horizontal position of a specified square.
 * The square will be rotated according to the specified
 * orientation.
 *
 * @param square       the square to rotate (0-3)
 * @param orientation  the orientation to use (0-3)
 *
 * @return the rotated relative horizontal position
 */
public int getRelativeX(int square, int orientation) {
    switch (orientation % 4) {
        case 0 :
            return shapeX[square];
        case 1 :
            return -shapeY[square];
        case 2 :
            return -shapeX[square];
        case 3 :
            return shapeY[square];
        default:
            return 0; // Should never occur
    }
}

/**
 * Rotates the relative vertical position of a specified square.
 * The square will be rotated according to the specified
 * orientation.
 *
 * @param square       the square to rotate (0-3)
 * @param orientation  the orientation to use (0-3)
 *
 * @return the rotated relative vertical position
 */
public int getRelativeY(int square, int orientation) {
    switch (orientation % 4) {
        case 0 :
            return shapeY[square];
        case 1 :
            return shapeX[square];
        case 2 :
            return -shapeY[square];
        case 3 :
            return -shapeX[square];
        default:
            return 0; // Should never occur
    }
}

/**
 * Paints the figure on the board with the specified color.
 *
 * @param color     the color to paint with, or -1 for clearing
 */
private void paint(int color) {
    int x, y;

    for (int i = 0; i < shapeX.length; i++) {
        x = xPos + getRelativeX(i, orientation);
        y = yPos + getRelativeY(i, orientation);
        board.setSquareColor(x, y, color);
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:10:35+00:00Added an answer on May 30, 2026 at 12:10 am

    First of all, I think what you’re looking for is an enum:

    public enum Tetrimonos{
        SQUARE , LINE, S_FIGURE, Z_FIGURE ,
        RIGHT_ANGLE_FIGURE, LEFT_ANGLE_FIGURE , TRIANGLE 
    }
    

    Using constants is a bad idea, relic from old languages.

    Secondly, what do you mean ‘explain these parameters’? Explain the tetris structure of each thing you named? In this case you should go to the relevant literature: a tetris piece is called tetrimono, and each one is called by a letter. Take a look here:
    http://en.wikipedia.org/wiki/Tetris#Gameplay

    You might like to link to this in your documentation as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code: class Fibonacci { static final int MIN_INDEX = 1; public
Here is the code: class Fibonacci { static final int MIN_INDEX = 1; public
Here's my code: class Ramka extends JFrame { public static final int SZEROKOSC =
I've seen examples like this: public class MaxSeconds { public static final int MAX_SECONDS
Say I have a class: public class R { public static final int _1st
Here are my constants //Encryption fields /** Algorithm=RSA Mode=ECB Padding=PKCS1Padding*/ public static final String
public class test { public static final int nThreads = 2; public static void
I have a base class ActivityA that has some dialogs: public static final int
BACKGROUND: The Android documentation states: Constants public static final int FILL_PARENT Special value for
public class Maze { public static final int ACTIVE = 0; public static final

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.