编程介的小学生 2019-09-02 10:28 采纳率: 20.5%
浏览 201

Tetris 俄罗斯方块的程序怎么写

Problem Description
Tetris is a famous puzzle video game.A random sequence of tetrominoes —shapes composed of four square blocks each—fall down the playing field (a rectangular vertical well). The object of the game is to manipulate these tetrominoes, by moving each one sideways and rotating it by 90 degree units, with the aim of creating a horizontal line of blocks without gaps. When such a line is created, it disappears, and any block above the deleted line will fall. As the game progresses, the tetrominoes fall, and the game ends when the stack of tetrominoes reaches the top of the playing field and no new tetrominoes are able to enter. Here we consider only a simple variation of tetris. The playing field consists of 20 rows and 10 columns. There’re 7 kinds of tetrominoes:

Each kind of tetrominoes may have 4 kind of rotation,ie, rotating by 0,90,180,270 degrees.Here is a sample rotation of type 2 Tetromino:

We define the initial position of a tetromino in the falling sequences as the leftmost occupied column of the tetromino after rotation. For example,for a type 2 tetromino with 180 degree rotation and a initial position of 3 is just like:

After one move down, it will look likes:

You will be given a sequence of tetrominoes with their rotation degrees and their initial position.And in this game there is no player manipulating tetrominoes. Once their rotation degree and initial position are determined,the ending of the game is unique. You just simulate as the original Tetris and are required to output the playing field right before the end of game(if the game ends before the end of sequences,you should output the the playing field right before its ends.).Note if there are some horizontal line that are fully covered by blocks,we should first delete such lines then judging the end of game.

Input
Input contains multiple cases.Test cases are separated by several blank lines.
Each test case starts with a integer M(1<=N<=300) ,indicating that there are M tetrominoes in the input sequence.Follow by M lines,each line contains three integers id,degree,pos(1<=id<=7,degree∈{0,90,180,270},1<=pos<=10),as described before.It guarantees that their inputs are legal.

Output
For each test case, output the playing field right before the end of game.ie,the playing field right before entering the last tetromino.For output,you should add a boarder to the playing field and output the rows in decreasing order,ie first output Row 20, then Row 19 and so on.If a block is occupied ,output “[]”,otherwise you should ouput '..' . Output a blank line after each Case.You may refer to the sample output for more details.

Sample Input
10
3 90 1
6 270 2
5 90 1
4 90 1
7 90 5
1 0 7
1 0 7
1 0 7
3 90 4
2 90 3

Sample Output
+--------------------+
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|....................|
|[][]................|
|[][][][]............|
|[]..[][]............|
|[][][][]............|
|[][][]..[][][][][][]|
|[][][]..[]..[][][][]|
+--------------------+

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 一道python难题2
    • ¥15 一道python难题
    • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备