贴上代码:
#include <unistd.h>
#include <windows.h>
#include <iostream>
using namespace std;
void sleep();
void cls();
void Loading();
void reast();
void game();
void sleep(int time){
usleep(time * 1000);
}
void Loading(int ci){
char loading[5]={'-','\\','|','/'};
cout<<'/';
for(int i=0;i<ci*4;i++){
cout<<"\b"<<loading[i%4];
Sleep(100);
}
}
void cls(){
system("cls");
}
void reast(){
cout<<"close System...";
Loading(38);
cout<<endl;
//bye bye dogheados!
}
void game(){
using namespace std;
char a[100][100]={"#########################################################",
"# ############################|######## o(^▽^)o ########",
"# ############################|##########################",
"# ############################|##########################",
"# ############################|# 这是一个迷宫游戏 #",
"# ############################|##########################",
"# ############################|##########################",
"# ############################|##########################",
"# ############################|##########################",
"# ############################|# W,S,A,D控制o的上下左右 #",
"# ############################|##########################",
"# ############################|##########################",
"# ############################|##########################",
"# ############################|$ 到达X即可胜利! $",
"# ############################|##########################",
"# ############################|##########################",
"# ############################|##########################",
"# ############################|##########################",
"# X#|# 玩得开心! #",
"#########################################################"};
cout<<"欢迎来走迷宫\(^o^)/~\n";
cout<<"按w往上,按a往左,按d往右,按s往下。到达X即可胜利!\n";
cout<<"知道后";
system("pause");
system("cls");
int x=1,y=1;
char t;
for(int i=0; i<=19; i++){
for(int j=1; j<=56; j++){
if(i==x&&j==y)
cout<<"o";
else cout<<a[i][j];
}
cout<<endl;
}
while(1){
t=getchar();
if(t=='w'&&a[x-1][y]!='#')
x--;
if(t=='a'&&a[x][y-1]!='#')
y--;
if(t=='d'&&a[x][y+1]!='#')
y++;
if(t=='s'&&a[x+1][y]!='#')
x++;
system("cls");
if(x==18&&y==28||x==41&&y==13){
cout<<"恭喜,你赢了";
return;
}
for(int i=0; i<=19; i++){
for(int j=1; j<=56; j++){
if(i==x&&j==y)
cout<<"o";
else cout<<a[i][j];
}
cout<<endl;
}
}
return;
}
int main(){
string name;
cout<<"Loading files...";
Loading(5);
cout<<endl;
cout<<"Downloading System...";
Loading(15);
cout<<endl;
cout<<"加载完毕!可以开始使用了!"<<endl;
Sleep(1000);
cls();
cout<<"让我们认识一下你:"<<endl<<"姓名:";
cin>>name;
cout<<name<<"?不错的名字!"<<endl;
Sleep(3000);
cls();
while (true){
cout<<"tree > Users > "<<name<<" > Desktop > Command.exe> ";
string command;
cin>>command;
if (command=="reboot"){
reast();
break;
}else if (command=="test"){
cout<<"正在测试程序稳定性......";
Loading(50);
cls();
cout<<"正在杀毒......";
Loading(50);
cout<<endl;
int randing=rand()%100;
if (randing>=50){
cout<<"你的电脑遇到问题了!需要重启......"<<endl;
Sleep(4*1000);
reast();
}
}else if (command=="game"){
game();cout<<endl;
}else if (command=="cls"||command=="clear"){
cls();
}else{
cout<<command<<" 不是任何可以执行的文件或命令。"<<endl;
}
}
return 0;
}