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.
arix_tetris_game/嘻嘻嘻俄罗斯方块吃柠檬.c

274 lines
6.4 KiB

6 years ago
#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<time.h>
#include<stdlib.h>
#include<conio.h>
#define N 20
#define M 16
int cur_x,cur_y;
int score,mark,next,map[N][M],Gamespeed=400;
int shape[28][6]=
{
{0,-1,0,-2,1,0}, {0,1,1,0,2,0}, {-1,0,0,1,0,2}, {0,-1,-1,0,-2,0},
{0,-1,0,1,-1,0}, {0,1,1,0,-1,0}, {1,0,0,-1,0,1}, {1,0,-1,0,0,-1},
{-1,1,0,1,1,0}, {0,-1,1,0,1,1}, {-1,0,0,-1,1,-1}, {-1,-1,-1,0,0,1},
{-1,0,0,1,1,1}, {0,1,1,-1,1,0}, {-1,0,0,1,1,1}, {0,1,1,-1,1,0},
{-1,0,0,-1,0,-2}, {-1,0,-2,0,0,1}, {0,1,0,2,1,0}, {0,-1,1,0,2,0},
{0,1,1,0,1,1}, {0,-1,1,0,1,-1}, {-1,0,0,-1,-1,-1}, {-1,0,-1,1,0,1},
{0,1,0,2,0,3}, {1,0,2,0,3,0}, {0,-1,0,-2,0,-3}, {-1,0,-2,0,-3,0}
};
void Init(int id);
void PrintPrompting();//<2F><>ʾ<EFBFBD><CABE>ʾ<EFBFBD><CABE>Ϣ
void YourScore();
void GotoxyWithFullwidth(short x, short y);//ȫ<><C8AB>
void Gameover();
void ShowMap(int id);
void GotoxyWithFullwidth(short x, short y)//<2F><>ȫ<EFBFBD>Ƕ<EFBFBD>λ<EFBFBD><CEBB>
{
static COORD cd;//<2F><><EFBFBD><EFBFBD><EAB6A8>
cd.X = (short)(x << 1);//<2F><><EFBFBD><EFBFBD>
cd.Y = y;
HANDLE A_GConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(A_GConsoleOutput, cd);
}
void PrintPrompting()//<2F><><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ʾ<EFBFBD><CABE>Ϣ <20><>
{
HANDLE A_GConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(A_GConsoleOutput, 0xF);
GotoxyWithFullwidth(25, 12);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><EFBFBD><EFBFBD> <20><>");
GotoxyWithFullwidth(25, 13);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><EFBFBD><EFBFBD> <20><>");
GotoxyWithFullwidth(25, 14);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><EFBFBD><EFBFBD> <20><>");
GotoxyWithFullwidth(25, 15);
printf("<EFBFBD><EFBFBD>˳ʱ<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD> <20><>");
GotoxyWithFullwidth(25, 16);
printf("<EFBFBD><EFBFBD><EFBFBD>ո<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
GotoxyWithFullwidth(35, 12);
printf("|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӭ<EFBFBD><D3AD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ") ;
GotoxyWithFullwidth(35,13);
printf("|<7C><><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߾<EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
GotoxyWithFullwidth(35, 14);
printf("|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɰ<EFBFBD><C9B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>") ;
GotoxyWithFullwidth(35, 15);
printf("|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˼ҲŲ<D2B2><C5B2>Ǵ<EFBFBD><C7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӱȣ<D3B1>");
GotoxyWithFullwidth(35, 16);
printf("|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7>~~<7E><><EFBFBD><EFBFBD>~~~<7E><>ιι<CEB9><CEB9><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ҳ̫<D2B2><CCAB><EFBFBD><EFBFBD><EFBFBD>˰ȣ<CBB0><C8A3><EFBFBD>");
GotoxyWithFullwidth(36, 30);
printf("<EFBFBD><EFBFBD>By: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һֻ<D2BB><D6BB><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>С<EFBFBD>˼<EFBFBD>");
}
void Gameover()
{//<2F><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
CONSOLE_CURSOR_INFO cursorInfo = { 1, FALSE};
int i,j,flag=0;
for(j=1;j<M-1;j++)
{
if(map[1][j]!=0)
{
flag=1;break;
}
}
if(flag==1)
{
system("cls");
GotoxyWithFullwidth(6,9);
printf("GAME OVER");
GotoxyWithFullwidth(1,N+1);
exit(0);
}
}
void ShowMap(int id)
{
CONSOLE_CURSOR_INFO cursorInfo = { 1, FALSE};
int i,j;
GotoxyWithFullwidth(0,0);
if(id!=-1)
{
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
if(i==0&&j==0 || i==0&&j==M-1 || j==0&&i==N-1 || j==M-1&&i==N-1)printf(" ");
else if( i==N-1)printf("==");
else if(j==0 || j==M-1)printf("|");
else if(map[i][j]==2) printf("<EFBFBD><EFBFBD>");
else if(i==cur_x+shape[id][0] && j==cur_y+shape[id][1] ||
i==cur_x+shape[id][2] && j==cur_y+shape[id][3] ||
i==cur_x+shape[id][4] && j==cur_y+shape[id][5] ||
i==cur_x && j==cur_y)
printf("<EFBFBD><EFBFBD>");
else if(map[i][j]==0) printf(" ");
}
if(i==1)printf(" next:");
if(i==11)printf(" score : %d",score);
if(i==19)printf(" speed : %d",score/100+1);
puts("");
}
}
else
{
mark=1;
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
if(i==0&&j==0 || i==0&&j==M-1 || j==0&&i==N-1 || j==M-1&&i==N-1)printf(" ");
else if(i==N+6)printf("==");
else if(j==0 || j==M-1)printf("|");
else if(map[i][j]==2) printf("<EFBFBD><EFBFBD>");
else if(map[i][j]==0) printf(" ");
}
if(i==1)printf(" next:");
if(i==11)printf(" score : %d",score);
puts("");
}
}
/*<2A><><EFBFBD><EFBFBD> next <20><><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD>ٻ<EFBFBD>ͼ*/
for(i=0;i<6;i=i+2)
{
GotoxyWithFullwidth(22+2*shape[id][i+1],6+shape[id][i]); printf(" ");
}
GotoxyWithFullwidth(22,6); printf("<EFBFBD><EFBFBD>");
for(i=0;i<6;i=i+2)
{
GotoxyWithFullwidth(22+2*shape[next][i+1],6+shape[next][i]); printf("<EFBFBD><EFBFBD>");
}
Sleep(Gamespeed);
}
void Init(int id)
{//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cur_x<5F><78>cur_y<5F><79>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
CONSOLE_CURSOR_INFO cursorInfo = { 1, FALSE};
int i,j;
memset(map,0,sizeof(map));
for( i=0;i<N;i++){
for( j=0;j<M;j++)
if(i==N-1 || j==0 || j==M-1)
map[i][j]=-1;
}
cur_x=0; cur_y=8;
ShowMap(id);
}
int judge_in(int x,int y,int id)
{//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><E7A3AC><EFBFBD><EFBFBD>˵<EFBFBD>Ƿ<EFBFBD><C7B7>Ϸ<EFBFBD>
CONSOLE_CURSOR_INFO cursorInfo = { 1, FALSE};
if(map[x][y]!=0)
return 0;
int i;
for( i=0;i<6;i=i+2)
{
if(map[ x+shape[id][i] ][ y+shape[id][i+1] ]!=0)
return 0;
}
return 1;
}
void YourScore()
{//<2F>÷֣<C3B7><D6A3><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD>ͼ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>
CONSOLE_CURSOR_INFO cursorInfo = { 1, FALSE};
int i,j,ii,jj;
for(i=1;i<N-1;i++)
{
int flag=0;
for( j=1;j<M-1;j++)
{
if(map[i][j]!=2)
{
flag=1;break;
}
}
if(flag==0)
{
int k=3;
while(k--)
{
GotoxyWithFullwidth(2,i+1);
for( ii=1;ii<M-1;ii++)
{
if(map[i][ii]==2)
{
if(k%2==1)
printf(" ");
}
}Sleep(10);
}
for( ii=i;ii>1;ii--
){
for( jj=1;jj<M-1;jj++)map[ii][jj]=map[ii-1][jj];
}
ShowMap(-1);
score+=10;
if(score%100==0 && score!=0)
Gamespeed-=50;
}
}
}
int main(void)
{
CONSOLE_CURSOR_INFO cursorInfo = { 1, FALSE};//<2F>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>
GetStdHandle(STD_OUTPUT_HANDLE);//<2F><><EFBFBD>DZ<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
HANDLE A_GConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); //<2F><>ֵ<EFBFBD><D6B5>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>
SetConsoleCursorInfo(A_GConsoleOutput, &cursorInfo);
SetConsoleTitleA("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˹<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨<EFBFBD><EFBFBD><EFBFBD>By<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŮQAQ");//<2F>˼<EFBFBD><CBBC><EFBFBD><EFBFBD><EFBFBD>qwq
do
{
PrintPrompting();//<2F><>ʾ<EFBFBD><CABE>ʾ<EFBFBD><CABE>Ϣ
YourScore();
int i,id,set=1;
srand(time(NULL));
id=rand()%28;
id=(id+28)%28;
next=rand()%28; next=(next+28)%28;
Init(id);
while(1)
{
Here: mark=0;
if(set==0)
{
id=next;
next=rand()%28; next=(next+28)%28;
cur_x=0;cur_y=6;
set=1;
}
while(!kbhit())
{
Gameover();
if(judge_in(cur_x+1,cur_y,id)==1) cur_x++;
else {
map[cur_x][cur_y]=2;
for(i=0;i<6;i=i+2)
map[ cur_x+shape[id][i] ][ cur_y+shape[id][i+1] ]=2;
YourScore();
set=0;
}
if(mark!=1)ShowMap(id);
goto Here;
}
char key;
key=getch();
if(key==72)
{
int tmp=id;
id++;
if( id%4==0 && id!=0 )id=id-4;
if(judge_in(cur_x,cur_y,id)!=1)id=tmp;
}
else if(key==80 && judge_in(cur_x+1,cur_y,id)==1)cur_x++;
else if(key==75 && judge_in(cur_x,cur_y-1,id)==1)cur_y--;
else if(key==77 && judge_in(cur_x,cur_y+1,id)==1)cur_y++;
else if(key==32 && judge_in(cur_x,cur_y,id)==1){cur_x=cur_x-1;}//<2F>ո<EFBFBD><D5B8><EFBFBD><EFBFBD><EFBFBD>ȥ
}
}
while (1);
GotoxyWithFullwidth(0, 0);
CloseHandle(A_GConsoleOutput);
return 0;
}