C++里的Getch()想必大家都不陌生,
char c=getch()
运用二位数组也可以创建地图
int Map[19][19];
再加上玩家的坐标和诸多变量
using namespace std;
struct crood
{
int x,y;
}player;
int money=0;
char c;
int temp,dir,mon=1,turn=0;
随机数&头文件
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
//...
int po;
//...
srand(time(NULL));
po=rand%21+1;
就组成了“贪财虫” [doge]
下方主程序↓
int main()
{
temp=rand()%21;
dir=rand()%21;
srand(time(NULL));
player.x=0;player.y=0;
while(1){
system("cls");
time_t now = time(0);
tm *ltm = localtime(&now);
cout << "金币:" << money << " 时间:" << ltm->tm_hour << ":"<<ltm->tm_min << ":"<<ltm->tm_sec << endl;
cout << "# # # # # # # # # # # # # # # # # # # # # ##"<<endl;
for(int i=0;i<21;i++){
cout << "#";
for(int j=0;j<21;j++)
{
if(i==player.x&&j==player.y)
{
if(temp==player.x&&dir==player.y)mon--;
cout << " @";
}
if(turn=1&&i==temp&&j==dir)cout << " $";
else if(mon==0)
{
temp=rand()%21;
dir=rand()%21;
if(i==temp&&j==dir)cout << " $";
mon++;
money++;
}
else cout << " ";
}
cout << "#";
cout << endl;
}
cout << "# # # # # # # # # # # # # # # # # # # # # ##"<<endl;
c=getch();
if(player.x>0)
{
if(c=='w')player.x--;
}
if(player.y>0)
{
if(c=='a')player.y--;
}
if(player.x<20)
{
if(c=='s')player.x++;
}
if(player.y<20)
{
if(c=='d')player.y++;
}
if(c=='p')
{
cout << "暂停";
getch();
}
turn++;
}
return 0;
}
你说什么?康不懂?不阔能的