Create a global function called updatebucket

Assignment Help Computer Engineering
Reference no: EM131379793

Assignment: Tetris Continuation for FLOVODOH

You have already displayed the Tetris bucket in your previous project assignment. In this assignment, you will need to display and drop the shape. Add plenty of narrative comments. Your program must be compilable and executable.

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.

1. 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.

2. Now, populate or initialize the "shapeArray". There are three 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] = ' ';

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 as shapeTopLeftX and shapeTopLeftY. Note, x changes horizontally, and y changes vertically.

4. In this step you will generate one shape. To accomplish this, in the main() function, before the while loop (game loop), do the following:

1. Generate a random number from 0 to 6.
2. Use one of the options presented in step 2 above to create a TetrisShape object.
3. 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 the shapeArray of 4x4. You need to provide the TetrisShape object (created in step '4b' above) to the function as an argument in order to access its shapeArray. 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.

5. Call the "updatebucket(TetrisShape localTetrisShape)" function from main() using the object created in step 4b.

Display the bucket.

6. 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.

7. Clear (assign spaces to) the current position values of the shape in the bucket using the "old"shapeTopLeftX and shapeTopLeftY. This will ensure that you do not leave any trail of the shape.

8. Call the "updatebucket(TetrisShape localTetrisShape)" function with the "new" shapeTopLeftX and shapeTopLeftY values. This will ensure the shape will be displayed in the new location (newShapeTopLeftX, newShapeTopLeftY).

9. Display the bucket. The shape is displayed in the new location of the bucket.

10. Store the new shapeTopLeftX and shapeTopLeftY values to the old shapeTopLeftX and shapeTopLeftY values to get ready for the next loop.

11. Sleep for a while to slow down the game.

Remember, these are guidelines and are only intended to help you, if you need assistance. If you already know what you need to do, then do it your way.

Reference no: EM131379793

Questions Cloud

What are the fiduciary responsibilities of executives : What are the fiduciary responsibilities of executives and members of the board of directors to shareholders? How were these obligations violated in the HP case?
Why are government programs seldom terminated : Why are government programs seldom terminated? Provide at least three reasons in your response. Please present an example of a government program that should have been terminated and explain how it may have survived
On what do the weights in this weighted average depend : The boosting algorithm uses a weighted average of a series of classifiers. On what do the weights in this weighted average depend?
Prepare an outline of your paper using the thesis generator : Your company's vice president of human resources has approached your team for assistance in recruiting and developing your organization's future leaders. The vice president has asked your team to brainstorm, research, and prepare a written profile..
Create a global function called updatebucket : 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 the shapeArray of 4x4.
Kohlbergs model of moral development : Using Kohlberg's model of moral development, at what stage of ethical reasoning would you say Mr. ABC was at? Why?
Describe the relationship between discretion and fairness : Describe the relationship between discretion and fairness. Why are the two terms similar or different in the context of agency actions
What kind of variable is the researcher studying : Stress. A medical researcher measures the increase in heart rate of patients under a stress test. What kind of variable is the researcher studying?
Discuss about the employment tests and hiring : Using the e-Activity, choose two (2) of the following employment tests: drug tests, medical examinations, polygraphs or honesty tests, and scored test of ability. Next, analyze the manner in which the testing itself could be considered illegal whe..

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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