Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone please write the java syntax for full implementation of the java code for the methods makeMove, and validateMove in class Tetrisgame and moveDown,

Can someone please write the java syntax for full implementation of the java code for the methods makeMove, and validateMove in class Tetrisgame and moveDown, moveUp method in class TetrisBrick based off description and uml.
TetrisGame methods:
The makeMove - Takes a char move code as argument. The move code should indicate which direction the falling brick
should move; down. The only move you need to account for is down. makeMove should
call the method validateMove after the move is made to
make sure it was valid. The move should be reversed if validateMove returns false.It should reverse the last
move (when brick hits the bottom and tries to move into the
border of the well). makeMove has no return value.
validateMove - checks the move just made to make sure
the brick is in bounds, returning true if all segments of the
brick are valid and false if any segment is not valid.It simply has to check that the brick is not below the
bottom of the well. As shown in the UML, this methods has
not arguments.
TetrisBrick methods:
moveDown()- This method adjusts the row element of
each segment to move the whole brick down one row of the
board. No arguments, no return values.
moveUp()- This method adjusts the row element of each
segment to move the whole brick up one row of the board.
This is used only when the move down method is invalid. It is not an allowed move for the player to select and as such will
not be associated with a key for the user to trigger.
.
code so far:
import java.util.*;
public class TetrisGame
{
private TetrisBrick fallingBrick;
private int rows =2;
private int cols =2;
private int numBrickTypes =7;
private Random randGen;
public TetrisGame(int rows, int cols)
{
this.rows = rows;
this.cols = cols;
this.fallingBrick = new TetrisBrick();
this.randGen = new Random();
spawnBrick();
}
private void spawnBrick()
{
int centerCol= this.cols/2;
randGen = new Random();
int brickType = randGen.nextInt(numBrickTypes);
switch(brickType)
{
case 0:
fallingBrick = new ElBrick(centerCol);
break;
case 1:
fallingBrick = new EssBrick(centerCol);
break;
case 2:
fallingBrick = new JayBrick(centerCol);
break;
case 3:
fallingBrick = new ZeeBrick(centerCol);
break;
case 4:
fallingBrick = new StackBrick(centerCol);
break;
case 5:
fallingBrick = new LongBrick(centerCol);
break;
case 6:
fallingBrick = new SquareBrick(centerCol);
break;
}
}
public void makeMove(char moveCode)
{
}
private boolean validateMove()
{
return false;
}
public int getFallingBrickColor()
{
return fallingBrick.getColorNumber();
}
public int getNumberSegs()
{
return fallingBrick.numSegments;
}
public int getSegRow(int segNumber)
{
return fallingBrick.position[segNumber][0];
}
public int getSegCol(int segNumber)
{
return fallingBrick.position[segNumber][1];
}
public int getRows(){
return rows;
}
public int getCols(){
return cols;
}
}
import java.awt.*;
public class TetrisBrick
{
protected int numSegments =4;
protected int[][] position = new int [numSegments][2];
protected Color[] color;
protected int colorNum;
public void TetrisBrick()
{
}
public void moveDown()
{
}
public void moveUp()
{
}
public int getColorNumber()
{
return colorNum;
}
public void initPosition(int center_column)
{
}
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

Students also viewed these Databases questions

Question

3. What are the important leadership virtues to you?

Answered: 1 week ago