"Original" only learn the two-dimensional array and structure, not linked list can also write a C snake? A

Source: Internet
Author: User

Let's start with some gossip.

Often non-trained programming enthusiasts, C as an introductory language, often ask: "I learned this xx, what can be done?" ”

In fact, with Google, basically anything can be done.

You don't even need a list, you can write a gluttonous snake game:)

This series will be divided into 4 parts, so that any one will only be two-dimensional combination of the structure of beginners to write their own bulimia snake

Go to the chase. Let's analyze the problem first and determine the next four parts.

0. Analyze the nature of the game and the form of representation in the console

1. Analysis of the basic structure of snake game

2. Determine the implementation plan

3. All source code

What is the nature of a game, or video game?

0, the essence of the game is the program

For the game, you need to get the user input and process it for the input, and then the feedback output

Simply put, the conversion is similar to the following:

Get user Input---> process a variety of data based on user input---> draw new images based on new data (output)

Although this is a bit of crap, it is good for us to analyze the basic structure of the snake.

1, the essence of the game is the set of rules between frames and frames

The so-called frame, can be simply understood as (moments, pictures) of the two-tuple, a specific frame has a relative to the start of the program to determine the time and picture. When the program is in a frame, it determines the picture content of the frame at the next unit moment, based on the input of the user accepted at the moment of the current frame.

For example, we control a fixed character moving forward in a grid, during which a two-frame conversion occurred: (moment 1, the character is located in the current lattice image)---> (moment 2, the character is located in the image after a lattice), and the aforementioned relationship can be understood as the rules of change between frames. Accepting a corresponding action, or based on a specific condition, activates the rule of change between a frame, showing the movement of the character, the attack, the score, and so on.

2, the game needs to pause to let the user feel the environment change

The program is fast.

Suppose in a game, the game character walk 1 steps need 1 times frame conversion, then walk 10 steps, need 10 times frame conversion. However, due to the speed of the program running, 1 times the conversion of the frame and 10 times the conversion of the frame, the time interval between the ordinary people are difficult to feel, with the feeling is "swish" a sound on the past

Therefore, in order for the user to feel the change between the different frames, we need to "pause" the program to run. What do you mean? That is, each time we complete the conversion of the frame, we stop running the program for a period of time, and so on, and then the next frame conversion. Use pseudo-code to represent:

while (1)

{

Game.getuserinput ();

Game.drawpic ();

Game.sleep (1000); Unit is MS

}

adjourned

"Original" only learn the two-dimensional array and structure, not linked list can also write a C snake? A

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.