Shell version of Tetris II: Program flow

Source: Internet
Author: User

first, the expression of the block

Because the shell can not define a two-dimensional array, so can only use one-dimensional array to represent the box, Tetris can be divided into 7 categories, each type of block is composed of four types of small squares, the method is as follows.

box= (X1,y1,x2,y2,x3,y3,x4,y4,x,y)

Xi, Yi is each small square in the Russian block represents the coordinates of the area, the last two, X, Y is when the box appears, the representation of the area relative to the coordinates of the chessboard, 7 types of blocks are shown as follows:


Definition of correlation function

1, two main functions

Runasdisplayer (), Runaskeyreceiver (), each of these functions has a dead loop, and the two functions run in different processes, so the two functions are always running during the game, where the process is displayed as a background process, The command receives the process as a foreground process. After the foreground process receives the command, it is sent by the KILL command to the display process, which shows the process performing the related action. The main commands that the foreground process sends to the display process are: Flip, move left, move right, move down, drop directly to the end, exit. After the current process receives the exit instruction, the display process is closed before shutting itself down, and the command receiving process is also closed before the process is closed.

2. Create a block function

Createbox () #创建方块, if this is the first time the creation is randomly generated, otherwise read the pre-generated block

Preparenextbox () #生成下一个方块, and pre-show

3. Drawing functions

Drawborder () #绘制边框及成绩等

Drawcurbox () #绘制当前方块

4. Instruction processing function

Boxrotate () #接收上方向键, for rotating blocks

Boxright () #右移

Boxleft () #左移

Boxdown () #下移, when you move down, if you want to, write the background and create a new square.

Boxalldown () #直接下移到最底部

5. Mobile Feasibility judgment function

Boxmove () #该函数包含两个表示目的地址的参数, returns 0 if it can be moved, otherwise returns 1

6. Write Background function

Box2map () #该函数用于把到底的方块写入到背景当中 and eliminate the lines that can be eliminated

7. Exit function

Myexitnosub () #用于恢复终端并退出指令接收进程

Myexit () #关闭两个进程, call the other two exit function implementations

Showexit () #关闭显示进程

Third, the system process


Shell version of Tetris II: Program flow

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.