From b03576000a1287f487b2d2a1ffc0786659262024 Mon Sep 17 00:00:00 2001 From: "18408000638@stu.hut.edu.cn" <18408000638@stu.hut.edu.cn> Date: Wed, 2 Jan 2019 15:29:55 +0800 Subject: [PATCH] first commit --- 俄罗斯方块.c | 387 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 387 insertions(+) create mode 100644 俄罗斯方块.c diff --git a/俄罗斯方块.c b/俄罗斯方块.c new file mode 100644 index 0000000..cfee48e --- /dev/null +++ b/俄罗斯方块.c @@ -0,0 +1,387 @@ +/****ͷļ****/ +#include //׼/(scanfprintf) +#include //DOS(ȡ̨λáɫ +#include //ܼ/(kbhitgetch) +#include //ڻ +/****궨****/ +#define FrameX 13 //ϷϽǵXΪ13 +#define FrameY 3 //ϷϽǵYΪ3 +#define Frame_height 20 //Ϸڵĸ߶Ϊ20 +#define Frame_width 18 //ϷڵĿΪ18 +/****ȫֱ****/ +int i,j,Temp,Temp1,Temp2; //Temp,Temp1,Temp2ڼסתֵ +int a[80][80]={0}; //ϷĻͼ2,1,0 ֱʾλΪϷ߿򡢷顢ͼʼΪͼ +int b[4]; //˹Ľṹ +struct Tetris +{ + int x; //ķx + int y; //ķy + int flag; //Ƿ͵ + int next; //һ˹͵ + int speed; //˹ƶٶ + int number; //˹ĸ + int score; //Ϸķ + int level; //Ϸĵȼ +} ; +HANDLE hOut; //̨ +/********/ +int color(int c); //ɫ +void gotoxy(int x,int y); //ȡĻλ +void Game(); //Ϸ +void play(); //ʼϷ +void explation(); //˵ +void rule(); //Ϸ +void MakeTetris(struct Tetris *tetris); // + /** + *ɫ + */ +int color(int c) +{ + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c); + return 0; +} + +/** + *ȡĻλ + */ +void gotoxy(int x,int y) +{ + COORD pos; + pos.X=x; // + pos.Y=y; // + SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos); +} + +/** + *ҳ + */ +void main() +{ + /*ͼ*/ + color(11); + gotoxy(20,3); + printf(" ˹ "); + gotoxy(15,6); + printf(" "); + gotoxy(15,7); + printf(""); + + color(14); + gotoxy(26,6); + printf(""); + gotoxy(26,7); + printf(" "); + + color(13); + gotoxy(40,5); + printf(""); + gotoxy(40,6); + printf(""); + gotoxy(40,7); + printf(""); + gotoxy(40,8); + printf(""); + + color(10); + gotoxy(50,6); + printf(""); + gotoxy(50,7); + printf(""); + + color(12); + gotoxy(60,6); + printf(" "); + gotoxy(60,7); + printf(""); + + color(9); + gotoxy(75,5); + printf(" ") ; + gotoxy(75,6); + printf(" "); + gotoxy(75,7); + printf(" "); + gotoxy(75,8); + printf(" "); + gotoxy(75,9); + printf(" "); + color(3); + gotoxy(75,12); + printf(" ҵ ѧ"); + gotoxy(75,14); + printf(" ҵ"); + color(6); + gotoxy(75,16); + printf(" 1806"); + gotoxy(75,17); + printf(" 18408000638"); + gotoxy(75,18); + printf(" "); + gotoxy(75,19); + printf(" 20181227"); + + /**/ + int n; + int i,j=1; + color(6); + for(i=9;i<=20;i++) + { + for(j=15;j<=65;j++) + { + gotoxy(j,i); + if(i==9||i==20) + { + printf("="); + } + else if(j==15||j==64) + { + printf("||"); + } + } + } + /* */ + color(12); + gotoxy(25,12); + printf("1.ʼϷ"); + gotoxy(45,12); + printf("2.˵"); + gotoxy(25,17); + printf("3.Ϸ"); + gotoxy(45,17); + printf("4.˳"); + gotoxy(21,22); + color(3); + printf("ѡ[1 2 3 4]:[ ]\b\b"); + scanf("%d",&n); + + switch(n) + { + case 1: + system("cls"); + Game(); + //play(); + break; + case 2: + explation(); + break; + case 3: + rule(); + break; + case 4: + break; + } +} + +/** + *˵ + */ +void explation() +{ + int i,j = 1; + system("cls"); + color(6); + gotoxy(30,3); + printf(" ˵ "); + for (i = 6; i <= 18; i++) + { + for (j = 12; j <= 70; j++) + { + gotoxy(j, i); + if (i == 6 || i == 18) printf("="); + else if (j == 12 || j == 69) printf("||"); + } + } + color(12); + gotoxy(16,9); + printf("1/ͨ ƶ"); + gotoxy(16,11); + printf("2/ͨ ʹת"); + gotoxy(16,13); + printf("3/ͨ ٷ"); + gotoxy(16,15); + printf("4/ͨոͣϷ"); + getch(); // + system("cls"); + main(); +} + +/** + *Ϸ + */ +void rule() +{ + int i,j = 1; + system("cls"); + color(6); + gotoxy(30,3); + printf(" Ϸ "); + for (i = 6; i <= 18; i++) + { + for (j = 12; j <= 70; j++) + { + gotoxy(j, i); + if (i == 6 || i == 18) printf("="); + else if (j == 12 || j == 69) printf("||"); + } + } + color(12); + gotoxy(16,7); + printf("1/ͬ״СĻϷ£ͨ"); + gotoxy(16,9); + printf(" λúͷʹĻײƴ"); + gotoxy(16,11); + printf(" һл"); + color(14); + gotoxy(16,13); + printf("2/ÿһУ100"); + color(11); + gotoxy(16,15); + printf("3/ÿۼ1000֣һȼ"); + color(10); + gotoxy(16,17); + printf("4/ȼʹٶȼӿ죬ϷѶȼӴ"); + getch(); // + system("cls"); + main(); +} + +/** + *Ϸ + */ +void Game() +{ + gotoxy(FrameX+Frame_width-7,FrameY-2); + color(11); + printf("Ȥζ˹"); + gotoxy(FrameX+2*Frame_width+3,FrameY+7); + color(2); + printf("***********"); + gotoxy(FrameX+2*Frame_width+3,FrameY+6); + color(3); + printf("һַ飺"); + gotoxy(FrameX+2*Frame_width+3,FrameY+13); + color(2); + printf("***********"); + gotoxy(FrameX+2*Frame_width+3,FrameY+17); + color(14); + printf(" ƶ ת"); + gotoxy(FrameX+2*Frame_width+3,FrameY+19); + printf("ոͣϷ"); + gotoxy(FrameX+2*Frame_width+3,FrameY+15); + printf("Esc:˳Ϸ"); + gotoxy(FrameX,FrameY); //ӡ + color(6); + printf(""); + gotoxy(FrameX+2*Frame_width-2,FrameY); + printf(""); + gotoxy(FrameX,FrameY+Frame_height); + printf(""); + gotoxy(FrameX+2*Frame_width-2,FrameY+Frame_height); + printf(""); + for(i=2;i<2*Frame_width-2;i+=2) + { + gotoxy(FrameX+i,FrameY); + printf(""); //ӡϺ + } + for(i=2;i<2*Frame_width-2;i+=2) + { + gotoxy(FrameX+i,FrameY+Frame_height); + printf(""); //ӡº + a[FrameX+i][FrameY+Frame_height]=2; //ºΪϷ߿򣬷ֹ + } + for(i=1;ix][tetris->y]=b[0]; + switch(tetris->flag) + { + case 1: // + { + color(10); + 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: //һ + { + color(4); + 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: //1 + { + color(13); + a[tetris->x][tetris->y-1]=b[1]; + a[tetris->x][tetris->y+1]=b[2]; + a[tetris->x][tetris->y+2]=b[3]; + break; + } + + case 4: //T + { + color(8); + 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: //˳90 T + { + color(8); + a[tetris->x-2][tetris->y]=b[1]; + a[tetris->x][tetris->y-1]=b[2]; + a[tetris->x][tetris->y+1]=b[3]; + break; + } + + case 6: //˳180T + { + color(11); + 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 7: //˳270 T + { + color(9); + 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 8: //Z + { + color(14); + a[tetris->x-2][tetris->y]=b[1]; + a[tetris->x+2][tetris->y+1]=b[2]; + a[tetris->x][tetris->y+1]=b[3]; + break; + } + } +}