Java代写:CSE11-Tetris

The Program - Tetris

This is a double programming request. It is intended to NOT be doable in a single night. It’s long with a non-optimized solution taking about 700-800 lines of code and white space (not including comments). It’s much more complex than any of your other programs but at the time of the request we have already covered the critical material. This request synthesizes nearly everything covered so far in CSE11.

The goal is to create a Tetris game program that you play on your computer. To achieve this goal you will be using Arrays (or ArrayLists), rectangular arrays, Threads, graphical user interfaces with java Swing objects, for loops, while loops, Boolean expressions, and good program design.

This is a much more substantial program than your previous requests and you should expect it take you much more time. Begin early. Ask questions. Be Patient and develop in stages. You have several weeks. Use them!.
A full lecture will be devoted to questions and hints for this project.

If you do nothing on this program the first week, you will find it very difficult and frustrating. Start working the first week. Read the suggested development process. The program is quite doable, but NOT if you try to solve the entire problem at once, or in a single week.

What the Final Game looks like when initialized and after being played for awhile with default the default blocksize (20 pixels)

Basic rules/operation of the game

There are seven Tetris shapes (each happens to occupy four grid squares).

When a new game is begun and empty field/board that is 10 blocks wide, 20 blocks high is created. Then a Randomly-selected shape is created and begins moving downwards toward the bottom of the grid. The shape starts roughly at the center top row. A shape may be rotated clockwise or counter-clockwise by the user. A shape may be moved left or right. And the user may drop the shape into place.

A shape may not be moved out of bounds. It may not be rotated if the rotation would make it run into an existing block on the board. When shape can no longer move downwards (hits the bottom, or runs into existing blocks, a new shape is automatically created.

The game is over when a shape cannot fit onto the grid.

Movement

The player has five keys at his/her disposal to move the current Tetris shape

  1. h – moves the Tetris shape left
  2. l – moves the Tetris shape right
  3. j – rotates the Tetris shape counter clockwise
  4. k – rotates the Tetris shape clockwise
  5. spacebar – drops the shape downwards from its current position until it would stop

Scoring

  1. Every time a shape moves downwards, score should be incremented by 10.
  2. Rows completed when a single shape stops movement
    . 1 row – 100
    1. 2 rows – 400
    2. 3 rows – 800
    3. 4 rows – 1600

Automated Speedup

blocks should begin movement at 1 row/second. maximum speed should be 20 rows/second.

Block movement should speed up every 2000 points, until 40000 points are reached, and then maximum speed should be maintained
The Game is over when the next random piece will not fit. You may draw the final piece or not draw it (not drawn in the is diagram)

The Major Classes

When creating a larger program, one has to figure out how to break up the problem into smaller components. Since, this is likely the first big program you’ve ever created, this request guides you through some of this process. Let’s begin by looking at the most likely classes, and then expanding

  • Tetris Shapes
  • the grid (or field) over in which shapes are being placed
  • The graphical interface

Summary of Class Interactions

  1. A Shape is an array of logical coordinates. It knows nothing about graphics. It can be told to rotated and report information about itself.
  2. The TetrisGrid is the bounded X-Y playing field. It is the place where shapes interact with existing (placed) blocks. Hence it can enforce the rules of the game.
  3. The ShapeMover is the automated mechanism of forcing the current shape to move downwards. The ShapeMover will attempt to move/rotate the shape.
  4. Tetris is the Graphical interface that sets up the All components. It responds to some user input
  5. GraphicsGrid is the graphical representation of TetrisGrid.
  6. Coord is a “helper” class.
  7. You will need to decide exactly how information is communicated among the various classes to achieve your goals. Ask questions and think about this for a while. Understanding how your classes should interact will make your debugging much faster