commit 22d30d5073b282d08cfbddbc8415436e905862b0 Author: 296289990@qq.com <296289990@qq.com> Date: Mon Jan 7 14:20:45 2019 +0800 first commit diff --git a/俄罗斯方块.c b/俄罗斯方块.c new file mode 100644 index 0000000..a0675c1 --- /dev/null +++ b/俄罗斯方块.c @@ -0,0 +1,495 @@ +/********ͷļ*********/ +#include +#include +#include +#include + + +/********궨********/ +#define FrameX 13 +#define FrameY 3 +#define Frame_height 20 //Ϸڸ߶ +#define Frame_width 18//Ϸڿ + + +/********ȫֱ*********/ +int i,j,Temp,Temp1,Temp2; +int a[80][80]={0};//a2,1,0ֱ߿򣬷ͼ +int b[4];//ÿַ鶼ĸɣbĸλԹͼ +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); +static void gotoxy(int x, int y);//ƶλ +void DrawGameframe(); //Ϸ߿ +void Flag(struct Tetris * );//˹ +void MakeTetris(struct Tetris *);//˹ +void PrintTetris(struct Tetris *);//ӡ˹ +void CleanTetris(struct Tetris *);//˹ĺۼ +int ifMove(struct Tetris *);//жܷƶ +void Del_Fullline(struct Tetris *);//жǷ +void GamePlay();//ʼϷ +void regulation();//Ϸ +void explation();//˵ +void welcome();//ӭ +void Replay(struct Tetris *);//¿ʼϷ +void title();//ӭϷ +void close();//رϷ + + +/*****ɫ******/ +int color(int c){ + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);//ɫ + return 0; +} + + +/*****ȡĻλ*******/ +static void gotoxy(int x, int y){ +COORD point = { x, y };//Ҫõλx,y +HANDLE HOutput = GetStdHandle(STD_OUTPUT_HANDLE);//ʹGetStdHandle(STD_OUTPUT_HANDLE)ȡ׼ľ +SetConsoleCursorPosition(HOutput, point);//ùλ +} + + + +/*****ӭ********/ +void title(){ + color(15); + gotoxy(30,3); + printf("Ȥζ˹\n"); + // + color(11); + gotoxy(18,5); + printf(""); + gotoxy(18,6); + printf(""); + gotoxy(18,7); + printf(""); + //Tַ + color(14); + gotoxy(26,6); + printf(""); + gotoxy(28,7); + printf(""); + //Zַ + color(10); + gotoxy(36,6); + printf(""); + gotoxy(36,7); + printf(""); + //ַ + color(13); + gotoxy(45,5); + printf(""); + gotoxy(45,6); + printf(""); + gotoxy(45,7); + printf(""); + gotoxy(45,8); + printf(""); + //ֱ߷ + color(12); + gotoxy(56,6); + printf(""); + gotoxy(52,7); + printf("\n"); + //7ַ +} + + +/*******˵ѡ߿*******/ +void welcome() +{ + int n; + int i,j=1; + color(14); + for(i=9;i<=20;i++){ + for(j=15;j<=60;j++){ + gotoxy(j,i); + if(i==9||i==20) printf("="); + else if(j==15||j==59) printf("::"); + } + } +/*******˵ѡ********/ + color(12); + gotoxy(25,12); + printf("1.ʼϷ"); + gotoxy(40,12); + printf("2.˵"); + gotoxy(25,17); + printf("3.Ϸ"); + gotoxy(40,17); + printf("4.˳"); + gotoxy(21,22); + printf("ѡ[1,2,3,4]:[ ]\b\b"); + scanf("%d",&n); + switch(n){ + case 1: + system("cls"); + DrawGameframe(); + break; + case 2: + break; + case 3: + break; + case 4: + break; + } +} + + +/*******Ϸ*******/ +void DrawGameframe() +{ + /***********Ϸ***********/ + 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+13,FrameY+7); + 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(12); + printf("X"); + gotoxy(FrameX+2*Frame_width-2,FrameY); + printf("["); + gotoxy(FrameX,FrameY+Frame_height); + printf("^"); + gotoxy(FrameX+2*Frame_width-2,FrameY+Frame_height); + printf("a"); + a[FrameX][FrameY+Frame_height]=2; + a[FrameX+2*Frame_width-2][FrameY+Frame_height]=2;//ֹ + for(i=2;i<2*Frame_width-2;i+=2){ + gotoxy(FrameX+i,FrameY); + printf("T"); + } + for(i=2;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(13); + 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: //ֱ߷ + color(13); + 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ַ + 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 5: //˳ʱ90Tַ + color(11); + a[tetris->x][tetris->y-1]=b[1]; + a[tetris->x-2][tetris->y]=b[2]; + a[tetris->x][tetris->y+1]=b[3]; + break; + case 6: //˳ʱ180Tַ + color(11); + 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: //˳ʱ270Tַ + color(11); + 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ַ + color(14); + a[tetris->x+2][tetris->y+1]=b[1]; + a[tetris->x][tetris->y+1]=b[2]; + a[tetris->x-2][tetris->y]=b[3]; + break; + case 9: //˳ʱZַ + color(14); + 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 10: //Zַ + color(14); + 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 11: //˳ʱ뷴Zַ + color(14); + 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ַ + color(12); + 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: //˳ʱ907ַ + color(12); + 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: //˳ʱ1807ַ + color(12); + 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: //˳ʱ2707ַ + color(12); + 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 16: //7ַ + color(12); + 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: //˳ʱ90㷴7ַ + color(12); + 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: //˳ʱ180㷴7ַ + color(12); + 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: //˳ʱ270㷴7ַ + color(12); + 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; + } +} + + + +/******ӡ˹*******/ +void PrintfTetris(struct Tetris *tetris){ + for(i=0;i<4;i++) b[i]=1; + MakeTetris(tetris); + for(i=tetris->x-2;i<=tetris->x+4;i+=2){ + for(j=tetris->y-1;j<=tetris->y+1;j++){ + if(a[i][j]==1&&j>FrameY){ + gotoxy(i,j); + printf(""); + } + } + } + //ӡ˵Ϣ + gotoxy(FrameX+2*Frame_width+3,FrameY+1); + color(4); + printf("level:"); + color(12); + printf("%d",tetris->level); + gotoxy(FrameX+2*Frame_width+3,FrameY+3); + color(4); + printf("score:"); + color(12); + printf("%d",tetris->score); + gotoxy(FrameX+2*Frame_width+3,FrameY+3); + color(4); + printf("speed"); + color(12); + printf("%dms",tetris->speed); +} + + +/******жϷܷƶ******/ +int ifMove(struct Tetris *tetris) +{ + if(a[tetris->flag][tetris->y]!=0){ + return 0; + } + else{ + if( + (tetris->flag==1&&(a[tetris->x][tetris->y-1]==0&& + a[tetris->x][tetris->y-1]==0&&a[tetris->x+2][tetris->y]==0))|| + (tetris->flag==2&&(a[tetris->x-2][tetris->y]==0&& + a[tetris->x+2][tetris->y]==0&&a[tetris->x+4][tetris->y]==0))|| + (tetris->flag==3&&(a[tetris->x][tetris->y-1]==0&& + a[tetris->x][tetris->y-2]==0&&a[tetris->x][tetris->y+1]==0))|| + (tetris->flag==4&&(a[tetris->x-2][tetris->y]==0&& + a[tetris->x+2][tetris->y]==0&&a[tetris->x][tetris->y+1]==0))|| + (tetris->flag==5&&(a[tetris->x][tetris->y-1]==0&& + a[tetris->x][tetris->y+1]==0&&a[tetris->x-2][tetris->y]==0))|| + (tetris->flag==6&&(a[tetris->x][tetris->y-1]==0&& + a[tetris->x-2][tetris->y]==0&&a[tetris->x+2][tetris->y]==0))|| + (tetris->flag==7&&(a[tetris->x][tetris->y-1]==0&& + a[tetris->x][tetris->y+1]==0&&a[tetris->x+2][tetris->y]==0))|| + (tetris->flag==8&&(a[tetris->x][tetris->y+1]==0&& + a[tetris->x-2][tetris->y]==0&&a[tetris->x+2][tetris->y+1]==0))|| + (tetris->flag==9&&(a[tetris->x][tetris->y-1]==0&& + a[tetris->x-2][tetris->y]==0&&a[tetris->x-2][tetris->y+1]==0))|| + (tetris->flag==10&&(a[tetris->x][tetris->y-1]==0&& + a[tetris->x-2][tetris->y-1]==0&&a[tetris->x+2][tetris->y]==0))|| + (tetris->flag==11&&(a[tetris->x][tetris->y+1]==0&& + a[tetris->x-2][tetris->y-1]==0&&a[tetris->x-2][tetris->y]==0))|| + (tetris->flag==12&&(a[tetris->x][tetris->y-1]==0&& + a[tetris->x][tetris->y+1]==0&&a[tetris->x-2][tetris->y-1]==0))|| + (tetris->flag==13&&(a[tetris->x-2][tetris->y]==0&& + a[tetris->x+2][tetris->y-1]==0&&a[tetris->x+2][tetris->y]==0))|| + (tetris->flag==14&&(a[tetris->x][tetris->y-1]==0&& + a[tetris->x][tetris->y+1]==0&&a[tetris->x+2][tetris->y+1]==0))|| + (tetris->flag==15&&(a[tetris->x-2][tetris->y]==0&& + a[tetris->x-2][tetris->y+1]==0&&a[tetris->x+2][tetris->y]==0))|| + (tetris->flag==16&&(a[tetris->x][tetris->y+1]==0&& + a[tetris->x][tetris->y-1]==0&&a[tetris->x+2][tetris->y-1]==0))|| + (tetris->flag==17&&(a[tetris->x-2][tetris->y]==0&& + a[tetris->x+2][tetris->y+1]==0&&a[tetris->x+2][tetris->y]==0))|| + (tetris->flag==18&&(a[tetris->x][tetris->y-1]==0&& + a[tetris->x][tetris->y+1]==0&&a[tetris->x-2][tetris->y+1]==0))|| + (tetris->flag==19&&(a[tetris->x-2][tetris->y]==0&& + a[tetris->x-2][tetris->y-1]==0&&a[tetris->x+2][tetris->y]==0))) + { + return 1; + } + } + return 0; +} + + +/*******˹ĺۼ********/ +void CleanTetris(struct Tetris *tetris){ + for(i=0;i<4;i++){ + b[i]=0; + } + MakeTetris(tetris); + for(i=tetris->x-2;i<=tetris->x+4;i+=2){ + for(tetris->y-2;i<=tetris->y+1;j++){ + if(a[i][j]==0&&j>FrameY){ + gotoxy(i,j); + printf(" "); + } + } + } +} + + +/*******жǷ********/ +void Del_Fulline(struct Tetris *tetris){ + int k,del_rows=0; + for(j=FrameY+Frame_height-1;j>=FrameY+1;j--){ + k=0; + for(i=FrameX+2;iFrameY;k--){ + for(i=FrameX+2;iscore+=100*del_rows; + if(del_rows>0&&(tetris->score%1000==0||tetris->score/1000>tetris->level-1)){ + tetris->speed-+20; + tetris->level++; + } +} + + +/******˹͵*******/ +void Flag(struct Tetris *tetris){ + tetris->number++; + srand(time(NULL)); + if(tetris->number==1){ + tetris->flag=rand()%19+1; + } + tetris->next=rand()%19+1; +} + + +/**************/ +int main(){ + title(); + welcome(); + return 0; +} + diff --git a/俄罗斯方块.o b/俄罗斯方块.o new file mode 100644 index 0000000..077897d Binary files /dev/null and b/俄罗斯方块.o differ