Create a global function called updatebucket

Assignment Help JAVA Programming
Reference no: EM131591496

If you need guidance, you will find some detailed instruction (below) to assist you. This is not the only approach that will work but it will present one possibility. The sample below uses Classes (a little Object oriented programming) but, if you prefer a different approach, you do not have to use classes in your project.

To represent the Tetris shapes, you can create a Class called "TetrisShape". In the class, declare a 2-D array of chars that is 4x4 in size (you could also use 4x2 but that would require different algorithm). Call the array "shapeArray". For convenience, declare it as public (but, it should not be your practice when you work in the software industry). You might need more dimensions for the array if you want to statically assign (hard code) all the shape rotations (3-d) for all the shapes (4-d). In this example, the rotation of the shapes is done by value swapping in the 4x4 array.

Now, populate or initialize the "shapeArray". There are three (3) options for doing this:

Option 1:Add a function in the class (call it "populateShapeArray(int shapeType)"), that will take an integer which will denote the type of shape.

Option 2:Use a non-default constructor. In this case, when you create an object, you will take an integer as the constructor argument, which will denote the type of shape, as shown below.

TetrisShape currentShape = new TetrisShape(shapeType);// shapeType is an int

Option 3: Use a setter "setShape(int shapeType)" function.

Regardless of which option you chose above, you would use a switch statement to assign the 4x4 array values for the specific shape. For example, for 'L', it can be something like the following:
shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = ' '; shapeArray[3][0] = ' ';
shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = ' '; shapeArray[3][1] = ' ';
shapeArray[0][2] = ' '; shapeArray[1][2] = 'X'; shapeArray[2][2] = 'X'; shapeArray[3][2] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';

Always keep record of the top left corner location (x,y dimensions) of the shape that is falling. This record will indicate where to draw the shape in the bucket after the shape moves. Initially, the location should be, (6, 0), which is the top middle of the bucket. Store the coordinates in the "TetrisShape" class asshapeTopLeftXandshapeTopLeftY. Note, x changes horizontally, and y changes vertically.
In this step you will generate one shape. To accomplish this, in themain()function, before the while loop (game loop), do the following:
Generate a random number from 0 to 6.

Use one of the options presented in step 2 above to create a TetrisShape object.

Create a global function called "updatebucket(TetrisShape localTetrisShape)" to populate the bucket with values of the "shapeArray". Here, you will use two nested for loops to go over theshapeArrayof 4x4. You need to provide theTetrisShapeobject (created in step '4b' above) to the function as an argument in order to access itsshapeArray. Inside the loop, you will do this.
bucket[i+shapeTopLeftX][j+shapeTopLeftY] = localTetrisShape.shapeArray[i][j];
You are actually imposing the shape values on to the bucket.
Call the"updatebucket(TetrisShape localTetrisShape)" function frommain()using the object created in step 4b.
Display the bucket.

Inside the while loop (game loop), as the shape falls, the value of y will increase. In order to accomplish this you will have "newShapeTopLeftY = shapeTopLeftY + 1;" so that the shape falls one cell below. Notice that you are storing the new y value in another variable because you need both the old and the new values. Clear (assign spaces to) the current position values of the shape in the bucket using the "old" shapeTopLeftXandshapeTopLeftY. This will ensure that you do not leave any trail of the shape. Call the "updatebucket(TetrisShape localTetrisShape)" function with the "new"shapeTopLeftXandshapeTopLeftYvalues. This will ensure the shape will be displayed in the new location (newShapeTopLeftX,newShapeTopLeftY). Display the bucket. The shape is displayed in the new location of the bucket. Store the newshapeTopLeftXandshapeTopLeftYvalues to the oldshapeTopLeftXandshapeTopLeftY values to get ready for the next loop. Sleep for a while to slow down the game.

Reference no: EM131591496

Questions Cloud

What will your monthly payment be : What will your monthly payment be?
Discuss local-rural communities and urban communities : Copy and paste yourPost your responses to the Discussion based on the course requirements. Your Discussion postings should be written in standard.
Lease will require monthly lease payments : Lease will require monthly lease payments
What is the likely outcome of the case : White claims breach of contract and threaten to sue. What is the likely outcome of the case? Why?
Create a global function called updatebucket : Create a global function called updatebucket(TetrisShape localTetrisShape)" to populate the bucket with values of the shapeArray
A restatement of your assigned position on sampling strategy : Post a restatement of your assigned position on sampling strategies. Defend your position with examples and support from the scholarly literature.
Standardized and localized strategy : Explain the differences between a standardized and localized strategy. Which are the advantages and disadvantages of each one?
Member conferences of the ncaa : Member conferences of the NCAA provide many benefits and services to their member institutions. Identify and describe these benefits and services.
Define how to win friends and influence people : Write an Executive Summary of our book How to Win Friends and Influence People. Further, you must write it so that it persuades top managers

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd