贪财虫(奇怪的游戏增加了)

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;
}

你说什么?康不懂?不阔能的

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值