Question: package controllers; import models.Square; import models.StraightLine; import models.Tetronimo; import models.Z; import views.TetrisBoard; import models.L; import java.util.Random; public class TetrisController { private final TetrisBoard TETRIS _

package controllers;
import models.Square;
import models.StraightLine;
import models.Tetronimo;
import models.Z;
import views.TetrisBoard;
import models.L;
import java.util.Random;
public class TetrisController
{
private final TetrisBoard TETRIS_BOARD;
public TetrisController( TetrisBoard tetrisBoard )
{
this.TETRIS_BOARD = tetrisBoard;
}
/**
* Randomly chooses the next tetronimo and returns it (INCOMPLETE)
*
* @return The next tetronimo to be played
*/
public Tetronimo getNextTetromino(){
Tetronimo tetronimo;
// Create a Random instance
Random random = new Random();
// Randomly select a Tetronimo type
int randomType = random.nextInt(4); // Generates a number between 0 and 3
switch (randomType){
case 0:
tetronimo = new Square();
break;
case 1:
tetronimo = new StraightLine();
break;
case 2:
tetronimo = new Z();
break;
case 3:
tetronimo = new L();
break;
default:
throw new IllegalStateException("Unexpected value: "+ randomType);
}
// Set the location of the Tetronimo
tetronimo.setLocation(40+(5* Tetronimo.SIZE),0);
return tetronimo;
}
/**
* Method to determine if the tetronimo has landed (INCOMPLETE)
*
* @param tetronimo The tetronimo to evaluate
* @return True if the tetronimo has landed (on the bottom of the board or another tetronimo), false if it has not
*/
public boolean tetronimoLanded( Tetronimo tetronimo )
{
int nextY = tetronimo.getYLocation()+ tetronimo.getHeight()+ Tetronimo.SIZE;
return nextY <=480;
}
}package models;
import wheelsunh.users.Animator;
import wheelsunh.users.Rectangle;
import wheelsunh.users.ShapeGroup;
import java.awt.*;
public abstract class Tetronimo extends ShapeGroup
{
/**
* Constant to represent the size of the tetronimo
*/
public static final int SIZE=20;
protected Rectangle r1;
protected Rectangle r2;
protected Rectangle r3;
protected Rectangle r4;
protected Rectangle r5;
protected int curRotation =1;
/**
* Generates the four rectangles for the tetronino and puts them on the screen, they are at the default coordinates
* to start
*/
public Tetronimo()
{
super();
this.r1= new Rectangle();
this.r1.setSize( Tetronimo.SIZE, Tetronimo.SIZE );
this.r1.setFrameColor( Color.BLACK );
this.r2= new Rectangle();
this.r2.setSize( Tetronimo.SIZE, Tetronimo.SIZE );
this.r2.setFrameColor( Color.BLACK );
this.r3= new Rectangle();
this.r3.setSize( Tetronimo.SIZE, Tetronimo.SIZE );
this.r3.setFrameColor( Color.BLACK );
this.r4= new Rectangle();
this.r4.setSize( Tetronimo.SIZE, Tetronimo.SIZE );
this.r4.setFrameColor( Color.BLACK );
}
/**
* Increments the rotation of the tetronimo, other classes need to override this to provide the full functionality
*/
public void rotate()
{
this.curRotation++;
}
/**
* Shifts the tetronimo left one row
*/
public void shiftLeft()
{
super.setLocation( super.getXLocation()- Tetronimo.SIZE, super.getYLocation());
}
/**
* Shifts the tetronimo right one row
*/
public void shiftRight()
{
super.setLocation( super.getXLocation()+ Tetronimo.SIZE, super.getYLocation());
}
} I already have all of my shapes and am able to randomize them. But I am having a lot of trouble with Instructions (Views)
This package is simply going to contain the GUI for the game. You are going to need to add to my GUI a place for the score and also a preview of the next block to be dropped.The controllers package is where you need to implement the logic for the game. You can break up the logic into as many or as few classes as you see fit, but your package must handle the following:
Detecting when a row (or rows) have been filled and shifting down the blocks from the rows above
Scoring the game
Detecting when the game is over
Randomly choosing the next piece to drop
Detecting when a piece has fallen as far as it possibly can (I have started this for you, you will need to finish it) Thank you

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!