Tetris Software: The initial experience of C language application

Source: Internet
Author: User

C Language course with a class, the teacher provides a C language plane game let us feel, last semester C language course, mainly is the practice of various sentences, this time is to use the knowledge to feel a real system.

Install C-free First, and then run the program.

The game program seems simple, but in C language to achieve or the first time to see, it was very surprised.

Analysis of the program, the feeling is not too complicated, is the last semester to learn the combination of simple statements, but the use of very good. First look at the use of several statements:

1. First is the statement that appears on the screen printf

printf ("Tetris");
Gotoxy (HOUT,FRAMEX+2*FRAME_WIDTH+3,FRAMEY+7);
printf ("********** Next Block:");
Gotoxy (HOUT,FRAMEX+2*FRAME_WIDTH+3,FRAMEY+13);
printf ("**********");
Gotoxy (HOUT,FRAMEX+2*FRAME_WIDTH+3,FRAMEY+17);
printf ("↑ Key: Variant");
Gotoxy (hout,framex+2*frame_width+3,framey+19);
printf ("Space: Pause Game");
Gotoxy (HOUT,FRAMEX+2*FRAME_WIDTH+3,FRAMEY+15);
printf ("ESC: Exit Game");

2, another is the multi-conditional judgment switch--case

Switch (Tetris->flag)//A total of 6 categories, 19 types
{
Case 1://tin Word Box
{
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x+2][tetris->y-1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
Break
}
Case 2://Straight BLOCK:----
{
a[tetris->x-2][tetris->y]=b[1];
a[tetris->x+2][tetris->y]=b[2];
a[tetris->x+4][tetris->y]=b[3];
Break
}
Case 3://Straight BLOCK: |
{
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x][tetris->y-2]=b[2];
a[tetris->x][tetris->y+1]=b[3];
Break
}
Case 4://t Word box
{
a[tetris->x-2][tetris->y]=b[1];
a[tetris->x+2][tetris->y]=b[2];
a[tetris->x][tetris->y+1]=b[3];
Break
}
Case 5://t word clockwise 90-degree block
{
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x][tetris->y+1]=b[2];
a[tetris->x-2][tetris->y]=b[3];
Break
}
Case 6://t word clockwise 180-degree block
{
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x-2][tetris->y]=b[2];
a[tetris->x+2][tetris->y]=b[3];
Break
}
Case 7://t word clockwise 270-degree block
{
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x][tetris->y+1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
Break
}
Case 8://z Word Box
{
a[tetris->x][tetris->y+1]=b[1];
a[tetris->x-2][tetris->y]=b[2];
a[tetris->x+2][tetris->y+1]=b[3];
Break
}
Case 9://z word clockwise 90-degree block
{
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x-2][tetris->y]=b[2];
a[tetris->x-2][tetris->y+1]=b[3];
Break
}
Case://z word clockwise turn 180 degree block
{
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x-2][tetris->y-1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
Break
}
Case one://z word clockwise turn 270 degree block
{
a[tetris->x][tetris->y+1]=b[1];
a[tetris->x+2][tetris->y-1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
Break
}
Case 12://7 Word Box
{
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x][tetris->y+1]=b[2];
a[tetris->x-2][tetris->y-1]=b[3];
Break
}
Case 13://7 word clockwise 90-degree block
{
a[tetris->x-2][tetris->y]=b[1];
a[tetris->x-2][tetris->y+1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
Break
}
Case 14://7 word clockwise 180-degree block
{
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x][tetris->y+1]=b[2];
a[tetris->x+2][tetris->y+1]=b[3];
Break
}
Case 15://7 word clockwise 270-degree block
{
a[tetris->x-2][tetris->y]=b[1];
a[tetris->x+2][tetris->y-1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
Break
}
Case 16://pour 7 word blocks
{
a[tetris->x][tetris->y+1]=b[1];
a[tetris->x][tetris->y-1]=b[2];
a[tetris->x+2][tetris->y-1]=b[3];
Break
}
Case 17://Inverted 7-character clockwise to 90-degree block
{
a[tetris->x-2][tetris->y]=b[1];
a[tetris->x-2][tetris->y-1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
Break
}
Case 18://pour 7 words clockwise to 180 degree block
{
a[tetris->x][tetris->y-1]=b[1];
a[tetris->x][tetris->y+1]=b[2];
a[tetris->x-2][tetris->y+1]=b[3];
Break
}
Case 19://pour 7 words clockwise to 270 degree block
{
a[tetris->x-2][tetris->y]=b[1];
a[tetris->x+2][tetris->y+1]=b[2];
a[tetris->x+2][tetris->y]=b[3];
Break
}

3. Key function

Press the ← Key to move left, center axis minus 2

Press the → Key to move right, center axis plus 2

Press the ↑ key to change the current block clockwise to 90 degrees


4, sentiment

Through this class, I have a further understanding of C language, seemingly simple program, in fact, by hundreds of lines of code into. Find yourself in the programming aspect still have insufficient, make me know C language to be rigorous, step-by-steps to do, the procedure can make out.



Tetris Software: The initial experience of C language application

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.