You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
elsfk/俄罗斯方块.c

635 lines
15 KiB

6 years ago
/********ͷ<>ļ<EFBFBD>*********/
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
/********<2A><EFBFBD><EAB6A8>********/
#define FrameX 13
#define FrameY 3
#define Frame_height 20 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD>ڸ߶<DAB8>
#define Frame_width 18//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>
/********ȫ<>ֱ<EFBFBD><D6B1><EFBFBD>*********/
int i,j,Temp,Temp1,Temp2;
int a[80][80]={0};//a<><61><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2,1,0<>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߿򣬷<DFBF><F2A3ACB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
int b[4];//ÿ<>ַ<EFBFBD><D6B7><EFBFBD><E9B6BC><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>b<EFBFBD><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD>Թ<EFBFBD><D4B9><EFBFBD>ͼ<EFBFBD><CDBC>
struct Tetris
{
int x; //<2F><><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>x<EFBFBD><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int y; //<2F><><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int flag;//<2F><><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>
int next;//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>
int speed;//<2F><><EFBFBD><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
int number;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>
int score;//<2F><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
int level;//<2F><>Ϸ<EFBFBD>ȼ<EFBFBD>
};
HANDLE hOut;//<2F><><EFBFBD><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>
/******<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*******/
int color(int c);
static void gotoxy(int x, int y);//<2F>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
void DrawGameframe(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD>߿<EFBFBD>
void Flag(struct Tetris * );//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void MakeTetris(struct Tetris *);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD>
void PrintTetris(struct Tetris *);//<2F><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD>
void CleanTetris(struct Tetris *);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD><EFBFBD>ĺۼ<C4BA>
int ifMove(struct Tetris *);//<2F>ж<EFBFBD><D0B6>ܷ<EFBFBD><DCB7>ƶ<EFBFBD>
void Del_Fullline(struct Tetris *);//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
void GamePlay();//<2F><>ʼ<EFBFBD><CABC>Ϸ
void regulation();//<2F><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
void explation();//<2F><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>
void welcome();//<2F><>ӭ<EFBFBD><D3AD><EFBFBD><EFBFBD>
void Replay(struct Tetris *);//<2F><><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC>Ϸ
void title();//<2F><>ӭ<EFBFBD><D3AD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD>
void close();//<2F>ر<EFBFBD><D8B1><EFBFBD>Ϸ
/*****<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>******/
int color(int c){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
return 0;
}
/*****<2A><>ȡ<EFBFBD><C8A1>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>*******/
static void gotoxy(int x, int y){
COORD point = { x, y };//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>õ<EFBFBD>λ<EFBFBD><CEBB>x,y
HANDLE HOutput = GetStdHandle(STD_OUTPUT_HANDLE);//ʹ<><CAB9>GetStdHandle(STD_OUTPUT_HANDLE)<29><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>
SetConsoleCursorPosition(HOutput, point);//<2F><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>λ<EFBFBD><CEBB>
}
/*****<2A><>ӭ<EFBFBD><D3AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>********/
void title(){
color(15);
gotoxy(30,3);
printf("Ȥζ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
//<2F><><EFBFBD><EFBFBD>
color(11);
gotoxy(18,5);
printf("<EFBFBD><EFBFBD>");
gotoxy(18,6);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
gotoxy(18,7);
printf("<EFBFBD><EFBFBD>");
//T<>ַ<EFBFBD><D6B7><EFBFBD>
color(14);
gotoxy(26,6);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
gotoxy(28,7);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
//Z<>ַ<EFBFBD><D6B7><EFBFBD>
color(10);
gotoxy(36,6);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
gotoxy(36,7);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
//<2F><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
color(13);
gotoxy(45,5);
printf("<EFBFBD><EFBFBD>");
gotoxy(45,6);
printf("<EFBFBD><EFBFBD>");
gotoxy(45,7);
printf("<EFBFBD><EFBFBD>");
gotoxy(45,8);
printf("<EFBFBD><EFBFBD>");
//ֱ<>߷<EFBFBD><DFB7><EFBFBD>
color(12);
gotoxy(56,6);
printf("<EFBFBD><EFBFBD>");
gotoxy(52,7);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
//7<>ַ<EFBFBD><D6B7><EFBFBD>
}
/*******<2A>˵<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD>߿<EFBFBD>*******/
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("::");
}
}
/*******<2A>˵<EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>********/
color(12);
gotoxy(25,12);
printf("1.<2E><>ʼ<EFBFBD><CABC>Ϸ");
gotoxy(40,12);
printf("2.<2E><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>");
gotoxy(25,17);
printf("3.<2E><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>");
gotoxy(40,17);
printf("4.<2E>˳<EFBFBD>");
gotoxy(21,22);
printf("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>[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;
}
}
/*******<2A><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>*******/
void DrawGameframe()
{
/***********<2A><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>***********/
gotoxy(FrameX+Frame_width-7,FrameY-2);
color(11);
printf("Ȥζ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
/**********<2A><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>********/
gotoxy(FrameX+2*Frame_width+3,FrameY+7);
color(2);
printf("**********");
gotoxy(FrameX+2*Frame_width+13,FrameY+7);
color(3);
printf("<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>");
gotoxy(FrameX+2*Frame_width+3,FrameY+13);
color(2);
printf("**********");
/**********<2A><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>***********/
gotoxy(FrameX+2*Frame_width+3,FrameY+17);
color(14);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ת");
gotoxy(FrameX+2*Frame_width+3,FrameY+19);
printf("<EFBFBD>ո<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD>Ϸ");
gotoxy(FrameX+2*Frame_width+3,FrameY+15);
printf("Esc:<3A>˳<EFBFBD><CBB3><EFBFBD>Ϸ");
/*********<2A><>Ϸ<EFBFBD>߿<EFBFBD>***********/
gotoxy(FrameX,FrameY);
color(12);
printf("<EFBFBD>X");
gotoxy(FrameX+2*Frame_width-2,FrameY);
printf("<EFBFBD>[");
gotoxy(FrameX,FrameY+Frame_height);
printf("<EFBFBD>^");
gotoxy(FrameX+2*Frame_width-2,FrameY+Frame_height);
printf("<EFBFBD>a");
a[FrameX][FrameY+Frame_height]=2;
a[FrameX+2*Frame_width-2][FrameY+Frame_height]=2;//<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for(i=2;i<2*Frame_width-2;i+=2){
gotoxy(FrameX+i,FrameY);
printf("<EFBFBD>T");
}
for(i=2;i<Frame_width-2;i+=2){
gotoxy(FrameX+i,FrameY+Frame_height);
printf("<EFBFBD>T");
a[FrameX+i][FrameY+Frame_height]=2;
}
for(i=1;i<Frame_height;i++){
gotoxy(FrameX,FrameY+i);
printf("<EFBFBD>U");
a[FrameX][FrameY+i]=2;
}
for(i=1;i<Frame_height;i++){
gotoxy(FrameX+2*Frame_width-2,FrameY+i);
printf("<EFBFBD>U");
a[FrameX+2*Frame_width-2][FrameY+i]=2;
}
}
/********<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD>*********/
void MakeTetris(struct Tetris *tetris){
a[tetris->x][tetris->y]=b[0];//<2F><><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>״̬
switch(tetris->flag){
case 1: //<2F><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
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: //<2F><>ֱ<EFBFBD>߷<EFBFBD><DFB7><EFBFBD>
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: //<2F><>ֱ<EFBFBD>߷<EFBFBD><DFB7><EFBFBD>
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<>ַ<EFBFBD><D6B7><EFBFBD>
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: //˳ʱ<CBB3><CAB1>90<39><30>T<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
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: //˳ʱ<CBB3><CAB1>180<38><30>T<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
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: //˳ʱ<CBB3><CAB1>270<37><30>T<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
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<>ַ<EFBFBD><D6B7><EFBFBD>
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: //˳ʱ<CBB3><CAB1>Z<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
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: //<2F><>Z<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
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: //˳ʱ<CBB3>뷴Z<EBB7B4>ַ<EFBFBD><D6B7><EFBFBD>
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<>ַ<EFBFBD><D6B7><EFBFBD>
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: //˳ʱ<CBB3><CAB1>90<39><30>7<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
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: //˳ʱ<CBB3><CAB1>180<38><30>7<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
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: //˳ʱ<CBB3><CAB1>270<37><30>7<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
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: //<2F><>7<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
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: //˳ʱ<CBB3><CAB1>90<39>㷴7<E3B7B4>ַ<EFBFBD><D6B7><EFBFBD>
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: //˳ʱ<CBB3><CAB1>180<38>㷴7<E3B7B4>ַ<EFBFBD><D6B7><EFBFBD>
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: //˳ʱ<CBB3><CAB1>270<37>㷴7<E3B7B4>ַ<EFBFBD><D6B7><EFBFBD>
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;
}
}
/******<2A><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD>*******/
6 years ago
void PrintTetris(struct Tetris *tetris){
6 years ago
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("<EFBFBD><EFBFBD>");
}
}
}
//<2F><>ӡ<EFBFBD>˵<EFBFBD><CBB5><EFBFBD>Ϣ
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);
}
/******<2A>жϷ<D0B6><CFB7><EFBFBD><EFBFBD>ܷ<EFBFBD><DCB7>ƶ<EFBFBD>******/
int ifMove(struct Tetris *tetris)
{
6 years ago
if(a[tetris->x][tetris->y]!=0){
6 years ago
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;
}
/*******<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD><EFBFBD>ĺۼ<C4BA>********/
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(" ");
}
}
}
}
/*******<2A>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>********/
6 years ago
void Del_Fullline(struct Tetris *tetris){
6 years ago
int k,del_rows=0;
for(j=FrameY+Frame_height-1;j>=FrameY+1;j--){
k=0;
for(i=FrameX+2;i<FrameX+2*Frame_width-2;i+=2){
if(a[i][j]==1){
k++;
if(k==Frame_width-2){
for(k=FrameX+2;k<FrameX+2*Frame_width-2;k+=2){
a[k][j]=0;
gotoxy(k,j);
printf("");
}
for(k=j-1;k>FrameY;k--){
for(i=FrameX+2;i<FrameX+2*Frame_width-2;i+=2){
if(a[i][k]==1){
a[i][k]=0;
gotoxy(i,k);
printf(" ");
a[i][k+1]=1;
gotoxy(i,k+1);
printf("<EFBFBD><EFBFBD>");
}
}
}
j++;
del_rows++;
}
}
}
}
tetris->score+=100*del_rows;
if(del_rows>0&&(tetris->score%1000==0||tetris->score/1000>tetris->level-1)){
tetris->speed-+20;
tetris->level++;
}
}
/******<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>*******/
void Flag(struct Tetris *tetris){
tetris->number++;
srand(time(NULL));
if(tetris->number==1){
tetris->flag=rand()%19+1;
}
tetris->next=rand()%19+1;
}
6 years ago
/*******<2A><>ʼ<EFBFBD><CABC>Ϸ*******/
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;
/******<2A><>ȡ<EFBFBD><C8A1><EFBFBD>̰<EFBFBD><CCB0><EFBFBD>*******/
while(1){
label:PrintTetris(tetris);
Sleep(tetris->speed);//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
CleanTetris(tetris);
Temp1=tetris->x;
Temp2+tetris->flag;
if(kbhit()){
ch=getch();
if(ch==75){
tetris->x-=2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
if(ch==77) tetris->x+=2;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(ch==80){ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
}//ֱ<>߷<EFBFBD><DFB7><EFBFBD>
if(tetris->flag>=4&&tetris->flag<=7){
tetris->flag++;
tetris->flag%=4;
tetris->flag+=4;
}//T<>ַ<EFBFBD><D6B7><EFBFBD>
if(tetris->flag>=8&&tetris->flag<=11){
tetris->flag++;
tetris->flag%=4;
tetris->flag+=8;
}//Z<>ַ<EFBFBD><D6B7><EFBFBD>
if(tetris->flag>=12&&tetris->flag<=15){
tetris->flag++;
tetris->flag%=4;
tetris->flag+=12;
}// 7<>ַ<EFBFBD><D6B7><EFBFBD>
if(tetris->flag>=16&&tetris->flag<=19){
tetris->flag++;
tetris->flag%=4;
tetris->flag+=16;
}//<2F><>7<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
}
if(ch==32) //<2F>ո<EFBFBD><D5B8><EFBFBD>ͣ
{
PrintTetris(tetris);
while(1){
if(kbhit()){
ch=getch();
if(ch==32) goto label;
}
}
}
if(ch==27){ //ESC<53>˳<EFBFBD><CBB3><EFBFBD>Ϸ
system("cls");
memset(a,0,6400*sizeof(int));//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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;
}
}
//<2F><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
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<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD> \n");
printf("\t\t\t<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><> <20><> \n");
printf("\t\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><> <20><> <20><> \n");
printf("\t\t\t<EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><> <20><> \n");
printf("\t\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD> \n");
gotoxy(17,18);
color(14);
printf("<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>---------1");
gotoxy(44,18);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD>˳<EFBFBD>-----------2\n");
int n;
gotoxy(32,20);
printf("ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1/2<><32>");
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);
}
}
6 years ago
/*******<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*******/
int main(){
title();
welcome();
return 0;
}