|
|
|
@ -0,0 +1,273 @@
|
|
|
|
|
#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();//显示提示信息
|
|
|
|
|
void YourScore();
|
|
|
|
|
void GotoxyWithFullwidth(short x, short y);//全角
|
|
|
|
|
void Gameover();
|
|
|
|
|
void ShowMap(int id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GotoxyWithFullwidth(short x, short y)//【全角定位】
|
|
|
|
|
{
|
|
|
|
|
static COORD cd;//坐标定义
|
|
|
|
|
cd.X = (short)(x << 1);//左移
|
|
|
|
|
cd.Y = y;
|
|
|
|
|
HANDLE A_GConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
SetConsoleCursorPosition(A_GConsoleOutput, cd);
|
|
|
|
|
}
|
|
|
|
|
void PrintPrompting()//【显示提示信息 】
|
|
|
|
|
{
|
|
|
|
|
HANDLE A_GConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
SetConsoleTextAttribute(A_GConsoleOutput, 0xF);
|
|
|
|
|
GotoxyWithFullwidth(25, 12);
|
|
|
|
|
printf("□向左移动: ←");
|
|
|
|
|
GotoxyWithFullwidth(25, 13);
|
|
|
|
|
printf("□向右移动: →");
|
|
|
|
|
GotoxyWithFullwidth(25, 14);
|
|
|
|
|
printf("□向下移动: ↓");
|
|
|
|
|
GotoxyWithFullwidth(25, 15);
|
|
|
|
|
printf("□顺时针转: ↑");
|
|
|
|
|
GotoxyWithFullwidth(25, 16);
|
|
|
|
|
printf("□空格让悬停方块倒回");
|
|
|
|
|
GotoxyWithFullwidth(35, 12);
|
|
|
|
|
printf("|嘻嘻,欢迎来到 俄罗斯方块吃柠檬世界 ") ;
|
|
|
|
|
GotoxyWithFullwidth(35,13);
|
|
|
|
|
printf("|我以被课设逼疯的作者君之名命令你");
|
|
|
|
|
GotoxyWithFullwidth(35, 14);
|
|
|
|
|
printf("|变成世界上最可爱的妹子!!!") ;
|
|
|
|
|
GotoxyWithFullwidth(35, 15);
|
|
|
|
|
printf("|(呜呜呜人家才不是凑行数的老嘤比)");
|
|
|
|
|
GotoxyWithFullwidth(35, 16);
|
|
|
|
|
printf("|继续你的游戏叭~~啾咪~~~(喂喂,这一行也太明显了叭!)");
|
|
|
|
|
GotoxyWithFullwidth(36, 30);
|
|
|
|
|
printf("★By: 呜呜呜这是一只躲在角落没有名字的小菜鸡");
|
|
|
|
|
}
|
|
|
|
|
void Gameover()
|
|
|
|
|
{//游戏结束的判断
|
|
|
|
|
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("■");
|
|
|
|
|
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("■");
|
|
|
|
|
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("■");
|
|
|
|
|
else if(map[i][j]==0) printf(" ");
|
|
|
|
|
}
|
|
|
|
|
if(i==1)printf(" next:");
|
|
|
|
|
if(i==11)printf(" score : %d",score);
|
|
|
|
|
puts("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*对于 next 方块的处理,先擦除再画图*/
|
|
|
|
|
for(i=0;i<6;i=i+2)
|
|
|
|
|
{
|
|
|
|
|
GotoxyWithFullwidth(22+2*shape[id][i+1],6+shape[id][i]); printf(" ");
|
|
|
|
|
}
|
|
|
|
|
GotoxyWithFullwidth(22,6); printf("■");
|
|
|
|
|
for(i=0;i<6;i=i+2)
|
|
|
|
|
{
|
|
|
|
|
GotoxyWithFullwidth(22+2*shape[next][i+1],6+shape[next][i]); printf("■");
|
|
|
|
|
}
|
|
|
|
|
Sleep(Gamespeed);
|
|
|
|
|
}
|
|
|
|
|
void Init(int id)
|
|
|
|
|
{//初始化函数,cur_x,cur_y是全局变量,标记了移动方块的位置
|
|
|
|
|
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)
|
|
|
|
|
{//判断是否出界,或者说是否合法
|
|
|
|
|
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()
|
|
|
|
|
{//得分,消行还有图形的向下平移
|
|
|
|
|
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};//把光标匿得死死的!!!
|
|
|
|
|
GetStdHandle(STD_OUTPUT_HANDLE);//这是标准输出句柄
|
|
|
|
|
HANDLE A_GConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); //赋值标准输出句柄实例化
|
|
|
|
|
SetConsoleCursorInfo(A_GConsoleOutput, &cursorInfo);
|
|
|
|
|
SetConsoleTitleA("俄罗斯方块控制台版——By正在拯救银河系的天(并)才(不)少女QAQ");//菜鸡落泪qwq
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
PrintPrompting();//显示提示信息
|
|
|
|
|
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;}//空格键回去
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (1);
|
|
|
|
|
GotoxyWithFullwidth(0, 0);
|
|
|
|
|
CloseHandle(A_GConsoleOutput);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|