first commit

master
18408000525 6 years ago
parent d78b7c8a77
commit c43047202f

@ -0,0 +1,265 @@
#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<stdlib.h>
#include<conio.h>
#include<time.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 now);
void PrintPrompting();
void YourScore();
void GotoxyWithFullwidth(short x, short y);//全角
void Gameover();
void ShowMap(int now);
void GotoxyWithFullwidth(short x, short y)//【全角定位】
{
static COORD cd;//坐标定义
cd.X = x;
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(50, 5);
printf("□向左移动: ←");
GotoxyWithFullwidth(50, 6);
printf("□向右移动: →");
GotoxyWithFullwidth(50, 7);
printf("□向下移动: ↓");
GotoxyWithFullwidth(50, 8);
printf("□顺时针转: ↑");
GotoxyWithFullwidth(50, 9);
printf("□空格让悬停方块倒回");
GotoxyWithFullwidth(50, 14);
printf("|嘻嘻,欢迎来到 俄罗斯方块吃柠檬世界 ") ;
GotoxyWithFullwidth(50,15);
printf("|我以被课设逼疯的作者君之名命令你");
GotoxyWithFullwidth(50, 16);
printf("|变成世界上最可爱的妹子!!!") ;
GotoxyWithFullwidth(50, 17);
printf("|(呜呜呜人家才不是凑行数的老嘤比)");
GotoxyWithFullwidth(50, 18);
printf("|继续你的游戏叭~~啾咪~~~(喂喂,这一行水得也太明显了叭!)");
GotoxyWithFullwidth(75, 28);
printf("★By: 呜呜呜这是一只躲在角落没有名字的小菜鸡");
}
void Gameover()//【判断游戏是否结束】
{
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(9,9);
printf("GAME OVER");
GotoxyWithFullwidth(1,N+1);
exit(0);
}
}
void ShowMap(int now)//【页面布局和方块的产生,擦除】
{
CONSOLE_CURSOR_INFO cursorInfo = { 1, FALSE};
int i,j;
GotoxyWithFullwidth(0,0);
if(now!=-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[now][0] && j==cur_y+shape[now][1] ||
i==cur_x+shape[now][2] && j==cur_y+shape[now][3] ||
i==cur_x+shape[now][4] && j==cur_y+shape[now][5] ||
i==cur_x && j==cur_y)
printf(""); //这五行是打印出当前方块
else if(map[i][j]==0) printf(" "); //擦出方块移动的痕迹
}
if(i==1)printf(" 下一个:");
if(i==11)printf(" 分数 : %d",score);
if(i==19)printf(" 当前速度 : %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-1)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(" 下一个:");
if(i==11)printf(" 分数 : %d",score);
if(i==19)printf(" 当前速度 : %d",score/100+1);
puts(" ");
}
}
for(i=0;i<6;i=i+2)//处理【下一个】的方块显示
{
GotoxyWithFullwidth(36+2*shape[now][i+1],6+shape[now][i]); printf(" ");
}
GotoxyWithFullwidth(36,6); printf("");
for(i=0;i<6;i=i+2)
{
GotoxyWithFullwidth(36+2*shape[next][i+1],6+shape[next][i]); printf("");
}
Sleep(Gamespeed);
}
void Init(int now)//【初始化】
{
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=5;
ShowMap(now);
}
int Judge(int x,int y,int now)
{
if(map[x][y]!=0)
return 0;
int i;
for( i=0;i<6;i=i+2)
{
if(map[ x+shape[now][i] ][ y+shape[now][i+1] ]!=0)
return 0;
}
return 1;
}
void YourScore()
{//得分,消行还有图形的向下平移
CONSOLE_CURSOR_INFO cursorInfo = { 1, FALSE};
int i,j,p,q;
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( p=1;p<M-1;p++)
{
if(map[i][p]==2)
{
if(k%2==1)
printf(" ");
}
}
Sleep(10);
}
for( p=i;p>1;p--)
{
for( q=1;q<M-1;q++) map[p][q]=map[p-1][q];
}
ShowMap(-1); score+=20;
if(score%100==0 && score!=0 && Gamespeed!=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,now,set=1;
srand(time(NULL));
now=rand()%28;
next=rand()%28;
Init(now);
while(1)
{
Here: mark=0;
if(set==0)
{
now=next;
next=rand()%28;
cur_x=0;cur_y=5;
set=1;
}
while(!kbhit())
{
Gameover();//游戏有没有结束先判断一波
if(Judge(cur_x+1,cur_y,now)==1) cur_x++;//处理返回值
else
{
map[cur_x][cur_y]=2;
for(i=0;i<6;i=i+2)
map[ cur_x+shape[now][i] ][ cur_y+shape[now][i+1] ]=2;
YourScore();//得分,消行还有图形的向下平移
set=0;
}
if(mark!=1) ShowMap(now);
goto Here;
}
char key;
key=getch();
if(key==72)
{
int temp=now;
now++;
if( now%4==0 && now!=0 )now=now-4;//保持同一个类型的方块
if(Judge(cur_x,cur_y,now)!=1)now=temp;
}//旋转
else if(key==80 && Judge(cur_x+1,cur_y,now)==1)cur_x++;//下
else if(key==75 && Judge(cur_x,cur_y-1,now)==1)cur_y--;//左
else if(key==77 && Judge(cur_x,cur_y+1,now)==1)cur_y++; //右
else if(key==32 && Judge(cur_x,cur_y,now)==1){cur_x=cur_x-1;}//空格键回去
else continue;
}
}
while (1);
GotoxyWithFullwidth(0, 0);
CloseHandle(A_GConsoleOutput);
return 0;
}
Loading…
Cancel
Save