写了一个走迷宫的小游戏
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int x=99,y=13;
int x1[10005],y2[10005];
void GotoXY(int x,int y){
HANDLE hout;
COORD coord={x,y};
hout=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hout,coord);
}
int head(){
cout<<"按w上升,按a向左,按d向右,按s向下"<<endl;
cout<<"碰到#死亡,碰到左边缘下一关"<<endl;
}
int za(){
for(int i=1;i<=500;i++){
x1[i]=rand()%100;
y2[i]=rand()%25;
}
for(int i=1;i<=500;i++){
GotoXY(x1[i],y2[i]);
cout<<"#";
}
}
int main(){
char a;
system("mode con cols=100 lines=25");
head();
Sleep(3000);
system("CLS");
GotoXY(99,13);
cout<<0;
za();
while(1){
GotoXY(0,24);
cin>>a;
if(a=='a')x--;
else if(a=='d')x++;
else if(a=='w')y--;
else if(a=='s')y++;
system("cls");
GotoXY(0,22);
if(x==0){
za();
x=99;
y=13;
}
for(int i=1;i<=500;i++){
if(x==x1[i]&&y==y2[i]){
cout<<"你死了!"<<endl;
system("pause");
}
}
for(int i=1;i<=500;i++){
GotoXY(x1[i],y2[i]);
cout<<"#";
}
GotoXY(x,y);
cout<<0;
}
}