first commit

master
296289990@qq.com 6 years ago
parent 22d30d5073
commit 0ee18ed52c

@ -334,7 +334,7 @@ void MakeTetris(struct Tetris *tetris){
/******打印俄罗斯方块*******/ /******打印俄罗斯方块*******/
void PrintfTetris(struct Tetris *tetris){ void PrintTetris(struct Tetris *tetris){
for(i=0;i<4;i++) b[i]=1; for(i=0;i<4;i++) b[i]=1;
MakeTetris(tetris); MakeTetris(tetris);
for(i=tetris->x-2;i<=tetris->x+4;i+=2){ for(i=tetris->x-2;i<=tetris->x+4;i+=2){
@ -367,7 +367,7 @@ void PrintfTetris(struct Tetris *tetris){
/******判断方块能否移动******/ /******判断方块能否移动******/
int ifMove(struct Tetris *tetris) int ifMove(struct Tetris *tetris)
{ {
if(a[tetris->flag][tetris->y]!=0){ if(a[tetris->x][tetris->y]!=0){
return 0; return 0;
} }
else{ else{
@ -436,7 +436,7 @@ void CleanTetris(struct Tetris *tetris){
/*******判断是否满行********/ /*******判断是否满行********/
void Del_Fulline(struct Tetris *tetris){ void Del_Fullline(struct Tetris *tetris){
int k,del_rows=0; int k,del_rows=0;
for(j=FrameY+Frame_height-1;j>=FrameY+1;j--){ for(j=FrameY+Frame_height-1;j>=FrameY+1;j--){
k=0; k=0;
@ -486,6 +486,145 @@ void Flag(struct Tetris *tetris){
} }
/*******开始游戏*******/
void Gameplay(){
int n;
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;
tetris->y=FrameY+10;
tetris->flag=tetris->next;
PrintTetris(tetris);
tetris->x=FrameX+Frame_width;
tetris->y=FrameY-1;
tetris->flag=Temp;
/******获取键盘按键*******/
while(1){
label:PrintTetris(tetris);
Sleep(tetris->speed);//控制时间
CleanTetris(tetris);
Temp1=tetris->x;
Temp2+tetris->flag;
if(kbhit()){
ch=getch();
if(ch==75){
tetris->x-=2; //←键左移
}
if(ch==77) tetris->x+=2;//→键右移
if(ch==80){ //↓键加速下落
if(ifMove(tetris)!=0) tetris->y+=2;
else tetris->y=FrameY+Frame_height-2;
}
if(ch==72){
if(tetris->flag>=2&&tetris->flag<=3){
tetris->flag++;
tetris->flag%=2;
tetris->flag+=2;
}//直线方块
if(tetris->flag>=4&&tetris->flag<=7){
tetris->flag++;
tetris->flag%=4;
tetris->flag+=4;
}//T字方块
if(tetris->flag>=8&&tetris->flag<=11){
tetris->flag++;
tetris->flag%=4;
tetris->flag+=8;
}//Z字方块
if(tetris->flag>=12&&tetris->flag<=15){
tetris->flag++;
tetris->flag%=4;
tetris->flag+=12;
}// 7字方块
if(tetris->flag>=16&&tetris->flag<=19){
tetris->flag++;
tetris->flag%=4;
tetris->flag+=16;
}//反7字方块
}
if(ch==32) //空格暂停
{
PrintTetris(tetris);
while(1){
if(kbhit()){
ch=getch();
if(ch==32) goto label;
}
}
}
if(ch==27){ //ESC退出游戏
system("cls");
memset(a,0,6400*sizeof(int));//初始化数组
welcome();
}
if(ifMove(tetris)==0){
tetris->x=Temp1;
tetris->flag=Temp2;
}
else{
goto label;
}
}
tetris->y++;
if(ifMove(tetris)==0){
tetris->y--;
PrintTetris(tetris);
Del_Fullline(tetris);
break;
}
}
//游戏结束
for(i=tetris->y-2;i<tetris->y+2;i++){
if(i==FrameY){
system("cls");
gotoxy(29,7);
printf(" \n");
color(12);
printf("\t\t\t████ █ █ ██ \n");
printf("\t\t\t█ ██ █ █ █ \n");
printf("\t\t\t███ █ █ █ █ █ \n");
printf("\t\t\t█ █ ██ █ █ \n");
printf("\t\t\t████ █ █ ██ \n");
gotoxy(17,18);
color(14);
printf("我要重新玩一局---------1");
gotoxy(44,18);
printf("不玩了,退出-----------2\n");
int n;
gotoxy(32,20);
printf("选择【1/2】");
color(11);
scanf("%d",&n);
switch(n){
case 1:
system("cls");
Replay(tetris);
break;
case 2:
exit(0);
break;
}
}
}
tetris->flag=tetris->next;
tetris->x=FrameX+2*Frame_width+6;
tetris->y=FrameY+10;
CleanTetris(tetris);
}
}
/*******主函数*******/ /*******主函数*******/
int main(){ int main(){
title(); title();

Binary file not shown.
Loading…
Cancel
Save