The idea of tetris games in linux

Source: Internet
Author: User
Tags gtk
The idea of the Tetris game in linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. First, from the player's point of view, the Tetris game. The game is made up of several basic shapes of bricks, which are lowered to the bottom of the window at a certain speed. Bricks can be flipped and moved during the fall process. When there is a brick link at the bottom and occupies a whole row, it can be eliminated. Therefore, our implementation is divided into two parts: the background processing part and the user interface display part.

First look at the background processing section. The core data structure of the game is an m * n matrix. When a brick of each style appears, it occupies several positions in the matrix.

Based on these occupied locations, we set the corresponding position value of the Matrix to 1. Where there is no brick, the matrix value is 0. Similarly, the value of the matrix element occupied by the bottom brick is also set to 1. At a certain time, the timer times out, or the user enters a command, the top brick status will change. Move, flip, or drop. Whether the action succeeds depends on whether there are obstacles in the target position, that is, whether the target area of the brick is a matrix element that has been set to 1 or exceeds the matrix boundary. If there is no conflict, adjust the value of the matrix based on the actions of the bricks.

Let's look at the interface. Interface refresh is triggered by timer timeout and user input commands. Each time an event occurs, the element values of the corresponding matrix change. The interface is refreshed and the matrix value changes for whatever reason. It simply redraws the user interface based on the current matrix value. More optimized algorithms can be used to pass the modified matrix range to the interface refresh program when the timer times out or when a user command is available. In this way, the interface refresh program can update only the invalid Interface Area Based on this range, instead of updating the entire interface. Finally, let's look at the implementation tool. The background processing is the processing of simple data structures. It can be implemented in Standard C or other languages. The interface implementation part selects different implementation tools based on different platforms. For Windows, you can use the interface implementation tool provided by microsoft. For linux, you can select GTK or use the underlying xlib.

When I was on a business trip, I finally had time for a blockbuster. I was so confident that I had to write the Russian square under linux, which I thought for a long time, for a few days.

Although it is still rough, there is no motivation to write it down. Let's get to an end.

Originally want to put the source File compression, put up http://bigstone1998.googlepages.com/russiabrick.rar

Compile with the following command in Linux: gcc-g-o russia Russia. c 'pkg-config -- libs -- cflags gtk +-2.0'

Note that it is '(reverse), not' (quotation marks ).

Run./russia. The space changes the orientation, and the arrow moves.
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.