diff --git a/俄罗斯方块.c b/俄罗斯方块.c index a889d85..664487d 100644 --- a/俄罗斯方块.c +++ b/俄罗斯方块.c @@ -27,13 +27,13 @@ HANDLE hOut; // /********/ int color(int c); //ɫ void gotoxy(int x,int y); //ȡĻλ -void welcome(); //ҳ void Game(); //Ϸ void play(); //ʼϷ void explation(); //˵ void rule(); //Ϸ -void MakeTetris(struct Tetris *); // -void PrintTetris(struct Tetris *); //ӡ +void Make(struct Tetris *); // +void Print(struct Tetris *); //ӡ +void Clean(struct Tetris *); //ۼ /** *ɫ */ @@ -54,18 +54,12 @@ void gotoxy(int x,int y) SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos); } -/** - * - */ -int main() -{ - welcome(); -} + /** *ҳ */ -void welcome() +void main() { /*ͼ*/ color(11); @@ -313,7 +307,7 @@ void Game() /** * */ -void MakeTetris(struct Tetris *tetris) +void Make(struct Tetris *tetris) { a[tetris->x][tetris->y]=b[0]; //ķλõͼ״̬ switch(tetris->flag) //7࣬19 @@ -494,13 +488,13 @@ void MakeTetris(struct Tetris *tetris) /** *ӡ */ - void PrintTetris(struct Tetris *tetris) + void Print(struct Tetris *tetris) { for(i=0;i<4;i++) //b[4]еÿΪ1 { b[i]=1; } - MakeTetris(tetris); + Make(tetris); for(i=tetris->x-2;i<=tetris->x+4;i+=2) { for(j=tetris->y-2;j<=tetris->y+1;j++) //ѭԿֵܳλ @@ -536,30 +530,30 @@ void MakeTetris(struct Tetris *tetris) void play() { int n; - struct Tetris t,*tetris=&t; //ṹָ벢ָṹ - char ch; //ռı - tetris->number=0; //ʼ˹Ϊ0 - tetris->speed=300; //ʼƶٶΪ300ms - tetris->score=0; //ʼϷķΪ0 - tetris->level=1; //ʼϷΪ1 - while(1) //ѭ飬ֱϷ + struct Tetris t,*tetris=&t; + char ch; + tetris->number=0; + tetris->speed=300; + tetris->score=0; + tetris->level=1; + while(1) { - Flag(tetris); //õ˹͵ - Temp=tetris->flag; //סǰ˹ - tetris->x=FrameX+2*Frame_width+6; //Ԥ淽x - tetris->y=FrameY+10; //Ԥ淽y - tetris->flag = tetris->next; //һ˹ - PrintTetris(tetris); //ôӡ˹鷽 - tetris->x=FrameX+Frame_width; //Ϸķx - tetris->y=FrameY-1; //Ϸķy + Flag(tetris); + Temp=tetris->flag; + tetris->x=FrameX+2*Frame_width+6; + tetris->y=FrameY+10; + tetris->flag = tetris->next; + Print(tetris); + tetris->x=FrameX+Frame_width; + tetris->y=FrameY-1; tetris->flag=Temp; // - while(1) //Ʒ鷽ֱ鲻 + while(1) { - label:PrintTetris(tetris); //ӡ˹ - Sleep(tetris->speed); //ӻʱ - CleanTetris(tetris); //ۼ - Temp1=tetris->x; //סķֵ + label:PrintTetris(tetris); + Sleep(tetris->speed); + CleanTetris(tetris); + Temp1=tetris->x; Temp2=tetris->flag; //סǰ˹ if(kbhit()) //жǷм룬ch { @@ -618,7 +612,7 @@ void play() } if(ch == 32) //ոͣ { - PrintTetris(tetris); + Print(tetris); while(1) { if(kbhit()) //ٰոϷ @@ -684,14 +678,41 @@ for(i=tetris->y-2;iy+2;i++) printf("|| || \n"); printf(" @============================================================================@ \n"); if(MessageBox(NULL,"Ϸ.\nҪһô?","Game Over",MB_YESNO|MB_ICONQUESTION)==IDYES) - Replay(tetris); + { + system("cls"); + memset(a,0,6400*sizeof(int)); + Game(); + play(); + } else exit(0); } } - tetris->flag = tetris->next; //һ˹ͼ(ұߴ) + tetris->flag = tetris->next; tetris->x=FrameX+2*Frame_width+6; tetris->y=FrameY+10; - CleanTetris(tetris); + Clean(tetris); + } +} +/** + * ۼ + */ +void Clean(struct Tetris *tetris) +{ + for(i=0;i<4;i++) //b[4]4Ԫأѭ4ԪأÿԪصֵΪ0 + { + b[i]=0; //b[4]ÿԪصֵΪ0 + } + Make(tetris); + for( i = tetris->x - 2;i <= tetris->x + 4; i+=2 ) // XΪķ + { + for(j = tetris->y-2;j <= tetris->y + 1;j++) + { + if( a[i][j] == 0 && j > FrameY ) //λûͼҴϷ浱 + { + gotoxy(i,j); + printf(" "); // + } + } } }