Java代做编程辅导:CSE11 Tetris

做一个Tetris,也就是俄罗斯方块的游戏。游戏挺复古的,难度一般。

This is a double programming assignment. 

LE PHUONG撰写

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

×

现在提到了代写服务,肯定很多人都不会觉得陌生,就算是国内也是有着专业代写作业的服务行业的,能够为有需求的学生提供很多的帮助,不过其实代写机构在国外会更获得学生的支持,这是因为国外的学校对于平时的作业要求比较严格,为了获得更高的分数顺利毕业,不少留学生就会让代写机构帮忙完成作业,比较常见的作业代写类型,就是计算机专业了,因为对于留学生来说这个技术对于Machine Learning或者AI的代码编程要求更高,所以找代写机构完成作业会简单轻松很多,那么代写机构的水平,要怎么选择才会比较高?

1、代写机构正规专业

不论是在什么情况下,选择正规合法经营的机构肯定是首要的操作,这也是为了避免自己在找机构的时候,出现上当受骗的现象,造成自己的经济出现损失,带来的影响还是非常大的,所以需要注意很多细节才可以,所以在这样的情况下,代写机构的选择,也要选择在经营方面属于正规合法的类型,这样才可以保证服务进行的时候,不会出现各种问题,也可以减少损失的出现,而且正规合法也是代写机构的合格基础。

2、代写机构编程能力

作业的难度相信很多人都很熟悉,特别是对于AI深度学习或者是人工神经网络这种算法来说,因为要对SVM、Design Tree、线性回归以及编程有很高的要求,可以说作业的完成要求非常高,因此才会带动代写机构的发展,找专业的代写机构,一般都是会有专业的人员帮忙进行作业的完成,因为这类型的作业对专业要求比较高,因此代写机构也要具备专业能力才可以,否则很容易导致作业的完成出现问题,出现低分的评价。

3、代写机构收费情况

现在有非常多的留学生,都很在意作业的完成度,为了保证作业可以顺利的被完成,要进行的相关操作可是非常多的,代写机构也是因为如此才会延伸出来的,在现在发展也很迅速,现在选择代写机构的时候,一定要重视收费情况的合理性,因为代写作业还是比较费精力的,而且对于专业能力要求也高,所以价格方面一般会收取几千元至万元左右的价格,但是比较简单的也只需要几百元价格。

4、代写机构完成速度

大部分人都很在意代写机构的专业能力,也会很关心要具备什么能力,才可以展现出稳定的代写能力,其实专业的代写机构,对于作业完成度、作业完成时间、作业专业性等方面,都是要有一定的能力的,特别是在完成的时间上,一定要做到可以根据客户规定的时间内完成的操作,才可以作为合格专业的代写机构存在,大众在选择的时候,也可以重视完成时间这一点来。

现在找专业的CS代写机构帮忙完成作业的代写,完全不是奇怪的事情了,而且专业性越强的作业,需要代写机构帮忙的几率就会越高,代写就发展很好,需求量还是非常高的,这也可以很好的说明了,这个专业的难度以及专业性要求,才可以增加代写机构的存在。



It’s much more complex than any of your other programs but at the time of the assignment we have already covered the critical material. This assignment 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 assignments 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.


python岭回归、Lasso、随机森林、XGBoost、Keras神经网络、kmeans聚类链家租房数据地理可视化分析

阅读文章


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
    a. 1 row – 100
    b. 2 rows – 400
    c. 3 rows – 800
    d. 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 assignment 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

There are two less clear classes at this stage.

  • A ShapeMover that causes the current shape to move under program control
  • a coordinate class (basically row,column coordinates)

The TetrisShape Class (TetrisShape.java)

There can be several approaches to designing a Tetris Shape. But some of the capabilities that is must have are:

  • Must be able to create one of 7 specific shapes
  • Must be able to create a random shape
  • must be able to rotate clockwise
  • must be able to rotate counterclockwise
  • should be able to move it left/right (we’ll describe why this class is NOT the best place for this functionality.

What about displaying the Shape on the canvas? That’s a good design question. This assignment recommends that you do NOT make the TetrisShape class a graphics object, but instead represent shape as an array of four coordinates (See the Coord class below). Does a shape need to know the boundaries of the field? Perhaps, but it is a simpler design if the TetrisShape does not know where it is on the field.
The Shape as an array (row,column) coordinates.
A good approach is to think about a shape as a set of coordinates, with one of the blocks being at coordinate location (0,0). This make rotation, much simpler. All shapes can be rotated, except for the 2×2 square shape.

The T-shape could be represented as coordinates [(-1,0),(0,0),(0,1),(1,0)]
One of the Ell shapes could be represented as coordinates [(-2,0),(-1,0),(0,0),(0,1)]
and the other Ell shape as coordinates [(-2,0),(-1,0),(0,0),(0,-1)]
How to do rotation: You can look up Rotation matrices for graphics on the web, if you want the full
background. But our rotation is special (90 degrees).
If a coordinate is (r,c)

  • rotation in one direction makes the rotated coordinate (-c,r),
  • rotation in the other direction makes the rotated coordinate (c,-r)

If you want to rotate a shape, you apply the formula for all coordinates of the shape. For example, rotating one of Ells [(-2,0),(-1,0),(0,0),(0,1)] using the first rotation above yields new coordinates of [(0,-2),(0,-1),(0,0),(-1,0)] (draw dots to see that this should be counter clockwise rotation)
One of the reasons we don’t put where the shape is located on the board, is that rotation is MUCH easier.
I suggest that you create two “getters” for this class. One getter, returns the array of coordinates as they are stored. The other returns an array of coordinates with a given offset. For example for the first Ell shape, a getter with no arguments would return [(-2,0),(-1,0),(0,0),(0,1)]
but a getter with an offset of (3,4), would add three to the first dimension and four to the second and return [(1,4),(2,4),(3,4),(3,5)]
You should find the second form very convenient for placing a shape at a particular location on the board. External to this class, you keep track of where on the board to place the shape. The shape itself keeps track of its orientation (how it has been rotated).
Notice that Tetris shape is NOT a graphics object, it is simply a logical object.
Before going on, let’s talk about the Coord class

The Coord Class (Coord.java)

It is highly recommended that you create a Coord class where an instance of the class is an integer pair (r,c). You probably want to write an equals() method and a toString() method, but this is not essential. You can then represent a shape as an array of Coords. (r,c) are (row, column)
Note you could use the java.awt.Point. However, I find the Point.x, Point.y to be confusing in this case. A shape occupies a set of (row,column) logical coordinates. A TetrisGrid (below) is a 2D array of (rows high x columns wide).

The TetrisGrid Class (Grid.java)

The TetrisGrid is the bounded X,Y coordinate plane on which the shapes are placed. Think about it as “slots” that can be (a) empty, (b) occupied with blocks from previous pieces. (c) occupied by the current piece in play.
A TetrisShape doesn’t know about other shapes, It is on the TetrisGrid where Shapes interact with one another.
The Grid is also where rules of movement are enforced.

  1. The piece in play can’t be moved outside of the boundaries (you might want to ignore the top boundary for simplicity)
  2. a Shape can’t be rotated where one of its blocks would be outside the boundary
  3. a Shape can’t be rotated if the result of the rotation would move it into another occupied block
  4. a Shape cannot be moved (left, right, down) if that movement would put any part into an occupied block

Functionality of the TetrisGrid that will be needed

  • Constructor – builds a 10 wide x 20 high grid
  • Get an array (or list) of blocks that are occupied
  • Determine if a shape intersects any occupied block in the grid
  • Determine if a shape (at a particular offset) is completely in bounds
  • Add a shape to the grid
  • Remove a shape from the grid
  • Determine if after placing a shape, rows have been completed
  • Delete completed rows
  • Override toString() for Ascii Printing/debug

IMPORTANT: SO FAR, THE CLASSES THE HAVE BEEN DISCUSSED ARE ALL LOGICAL. Use Graph Paper as “TetrisGrid”, to place a TetrisShape on the Grid, add the same (row, column) offset to each one of the Shape’s Coords – this is where the shape would be actually be placed on the TetrisGrid. Please, please, please, do this by hand so that you understand how, logically, TetrisShapes are put on TetrisGrids

The GraphicsGrid (GraphicsGrid.java)

The TetrisGrid must be drawn . You are being given a fully-functional graphics program called GameGrid.java. You should study how it works and what it does. You will need to modify it somewhat for your purposes, but it’s a really good start on the graphics part.
It has a “mover” thread that moves a single block back and forth. You won’t use this mover thread, but you can model your final program on it’s logic. We’ll discuss this program in class, too.
The best way to think about GraphicsGrid, is that it is simply the display part of TetrisGrid.
ALL the logic of rotating pieces, completing rows, are enforced by invoking methods on TetrisGrid. GraphicsGrid simply displays in a nice way what’s stored on the TetrisGrid.
Some other moving parts that you need to think about.
Something will need to eventually tell the GUI when a move has been performed and when rows have been completed (for scoring).
Hint: When telling the GraphicsGrid that a piece has moved, I would remove all the blocks that should be drawn from GraphicsGrid, retrieve an array (or ArrayList) of occupied blocks from TetrisGrid, and then re-add all the occupied blocks to GraphicsGrid. This takes care of ALL cases of rotating pieces, moving pieces, collapsed rows, etc. Sometimes the simple solution is best.

The Game (Tetris.java)

This is the GUI interface for the game. It needs to display scores (high score) present buttons and a speed slider, and indicate when a game is over.
Hint: Each time a New Game is requested, create a new TetrisGrid

The ShapeMover (ShapeMover.java)

The ShapeMover must move the Current Piece downwards on a timed interval. It must also respond to keystroke commands from the user. In other words, it needs to respond to keyboard events and run on a clock (think Thread, you can copy the Mover class in the GameGrid starter code and then modify). Some more Detailed requirements of the game are given below
Some hints on ShapeMover
When trying to move/rotate the current shape

  1. Remove it from the TetrisGrid
  2. Logically move it, or rotate it to define its new position on the Grid
  3. Test if the new position is valid
    a. Test if the shape is inbounds
    b. Test if the shape intersects any of existing block
  4. If the new position is valid, then place it on the TetrisGrid
  5. If the new position is not valid
    a. Place the shape back at its original position/orientation
    b. If it was a downward move, then the shape can’t move anymore
    c. In this case, you then need to test if rows are now completed
  6. At the end of a valid move, the GraphicsGrid will need to be updated.
  7. When a shape stops moving, the game needs to be informed that a shape can’t be moved any more and that a new shape should be created.

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

关于分析师

在此对LE PHUONG对本文所作的贡献表示诚挚感谢,她在山东大学完成了计算机科学与技术专业的硕士学位,专注数据分析、数据可视化、数据采集等。擅长Python、SQL、C/C++、HTML、CSS、VSCode、Linux、Jupyter Notebook。

 
QQ在线咨询
售前咨询热线
15121130882
售后咨询热线
0571-63341498

关注有关新文章的微信公众号


永远不要错过任何见解。当新文章发表时,我们会通过微信公众号向您推送。

技术干货

最新洞察

This will close in 0 seconds