Question: Could someone please fix my isItOutOfBounds method so that it shows a game over message and exits the program. Currently it seems not to work

Could someone please fix my isItOutOfBounds method so that it shows a "game over" message and exits the program. Currently it seems not to work im calling it in my validateMove() method.
public class TetrisGame
{
private TetrisBrick fallingBrick;
private int rows =2;
private int cols =2;
private int numBrickTypes =7;
private Random randomGen;
private int[][] background;
private int state;
private int score;
public TetrisGame(int rows, int cols)
{
this.rows = rows;
this.cols = cols;
initBoard();
this.randomGen = new Random();
spawnBrick();
}
public void makeMove(char moveCode)
{
if (moveCode =='D')
{
fallingBrick.moveDown();
if(validateMove()==false)
{
fallingBrick.moveUp();
while(true)
{
if(isBlockOutOfBounds())
{
JOptionPane.showMessageDialog(null,"Game Over");
break;
}
transferColor();
copyAllRows();
spawnBrick();
}
}
else if(moveCode =='L')
{
fallingBrick.moveLeft();
if(validateMove()==false)
{
fallingBrick.moveRight();
}
}
else if(moveCode =='R')
{
fallingBrick.moveRight();
if(validateMove()==false)
{
fallingBrick.moveLeft();
}
}
else if(moveCode =='U')
{
fallingBrick.rotate();
if(validateMove()== false)
{
fallingBrick.unrotate();
}
}
else if(moveCode=='N')
{
newGame();
}
else if(moveCode=='S')
{
saveToFile();
}
}
}
private boolean isBlockOutOfBounds()
{
//int blockHeight = rows;
if(fallingBrick.position[0][0]0)
{
return true;
}
return false;
}
Could someone please fix my isItOutOfBounds

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!