发布一个抢金币小游戏~~
这是我朋友想编的
他和我讲了想法以后
被我写出来了[偷笑]
下面是代码:
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int x=1,y=21,x3,y3;
int x1[10005],y2[10005];
int xy[10010][10010];
int coo=0;
int head(){
cout<<"w向上,a向左,d向右,控制'0'"<<endl;
cout<<"碰到'o'(金币),金币+1"<<endl;
cout<<"碰到上方'=',结束游戏"<<endl;
}
void GotoXY(int x,int y){
HANDLE hout;
COORD coord={x,y};
hout=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hout,coord);
}
int za(){
for(int i=1;i<=50;i++){
x1[i]=rand()%98+3;
y2[i]=rand()%20+1;
if(x1[i]==x3&&y2[i]==y3){
x1[i]++;
y2[i]++;
}
}
for(int i=1;i<=100;i++){
GotoXY(x1[i],y2[i]);
cout<<"=";
}
}
int main(){
char a;
system("mode con cols=100 lines=25");
head();
Sleep(3000);
system("CLS");
x3=rand()%98+3;
y3=rand()%20+1;
GotoXY(1,21);
cout<<0;
int z=100;
GotoXY(0,22);
while(z--){
cout<<"=";
}
GotoXY(x3,y3);
cout<<"o";
za();
while(1){
GotoXY(0,23);
cin>>a;
if(a=='a')x--;
else if(a=='d')x++;
else if(a=='w'){
y-=6;
}
system("cls");
GotoXY(0,22);
z=100;
while(z--){
cout<<"=";
}
if(y>=22){
y=21;
}
else if(y<21)y+=1;
if(y<1)y=1;
if(x==0)x++;
else if(x==100)x--;
if(x==x3&&y==y3){
coo++;
x3=rand()%98+3;
y3=rand()%20+1;
za();
}
for(int i=1;i<=50;i++){
if(x==x1[i]&&y==y2[i]){
cout<<"你死了!"<<endl;
system("pause");
}
}
GotoXY(x,y);
cout<<0;
GotoXY(x3,y3);
cout<<"o";
GotoXY(0,50);
cout<<" 金币"<<coo;
for(int i=1;i<=100;i++){
GotoXY(x1[i],y2[i]);
cout<<"=";
}
}
}
如有bug
请多多指教!
🙏