2021-01-22

练习的时候写的一个小游戏-开箱子在这里插入图片描述
#include
#include
#include<conio.h>
#include<unistd.h>
#include
using namespace std;
int jf(int a);
int jifen;
int xianjia;
class lei
{
private:
int a[20][20];
public:
lei()
{

  	for(int b=0;20>b;b++)
  	{
  		for(int c=0;20>c;c++)
  	    {
  	    	
  	    	a[b][c]=0;
  	    	
  	    	}
  		
  		}
  	a[0][0]=1;
  	}	
void dayin()
{
	system("cls");
	for(int d=0;20>d;d++)
	{
		for(int e=0;20>e;e++)
		{
			if(a[d][e]==0)
			{
				cout<<"▪ ";
				}
			else if(a[d][e]==1)
			{
				cout<<"▣ ";
				}
			else if(a[d][e]==2)
			{
				
				cout<<"🍌 ";
				}
			else if(a[d][e]==3)
			{
				
				cout<<"🍎 ";
				}
			else if(a[d][e]==4)
			{
				
				cout<<"🍉 ";
				}
			else if(a[d][e]==5)
			{
				
				cout<<"💣 ";
				}
			}
		cout<<endl;
		}
	cout<<"本次得分:"<<jf(xianjia)<<endl;
	cout<<"积分:"<<jifen<<endl;

/* if(jifen<0)
{
system(“cls”);
cout<<“你已输掉本局游戏”<<endl;
}*/
if(jifen>200)
{
system(“cls”);
cout<<“你已赢得本局比赛”<<endl;
}
}
void xieru(int y,int x,int shu)
{

	xianjia=shu;
	
	if(shu==5)
	{
		jifen-=50;
		}
	else if(shu==4)
	{
		jifen+=20;
		}
	else if(shu==3)
	{
		jifen+=5;
		}
	else if(shu==2)
	{
		jifen+=10;
		}
	
	a[y][x]=shu;
	
	}
int duqu(int yy,int xx)
{
	return a[yy][xx];
	}

};

int sjs(int a,int b);

int main()
{
int x=0,y=0;
lei api;
string ch;
api.dayin();
for(;😉
{
if(kbhit())
{
ch=getch();
if(ch==“2” && y!=0)
{
ch="";
y–;
if(api.duqu(y,x)<2)

			{
			api.xieru(y,x,1);
			if(api.duqu(y+1,x)==1)
			{
			api.xieru(y+1,x,0);
			}
			api.dayin();
			}
			else
			{
			if(api.duqu(y+1,x)==1)
			{
			api.xieru(y+1,x,0);
			}
				}
		}
		if(ch=="4" && x!=0)
		{
			
			ch="";
			
			x--;
			if(api.duqu(y,x)<2)
			{
			api.xieru(y,x,1);
			if(api.duqu(y,x+1)==1)
			{
			api.xieru(y,x+1,0);
			}
			api.dayin();
			}
			else
			{
			if(api.duqu(y,x+1)==1)
			{
			api.xieru(y,x+1,0);
			}
			}
		}
		if(ch=="6"  && x!=20)
		{
			ch="";

			x++;
			if(api.duqu(y,x)<2)
			{
			api.xieru(y,x,1);
			if(api.duqu(y,x-1)==1)
			{
			api.xieru(y,x-1,0);
			}
			api.dayin();
			}
	    	else
			{
			if(api.duqu(y,x-1)==1)
			{
			api.xieru(y,x-1,0);
			}
			}
		}
		if(ch=="8" && y!=20)
		{
			ch="";
			
			y++;
			if(api.duqu(y,x)<2)
			{
			api.xieru(y,x,1);
	    	if(api.duqu(y-1,x)==1)
			{
			api.xieru(y-1,x,0);
			}
		    api.dayin();
			}
			else
			{
		    if(api.duqu(y-1,x)==1)
		    {
			api.xieru(y-1,x,0);
		    }
			}
		}
		if(ch=="5" && api.duqu(y,x)==1)
		{
			ch="";
			api.xieru(y,x,sjs(2,5));
			api.dayin();
			}
		}
	}

}

int sjs(int a,int b)
{
srand((unsigned)time(NULL));
return a+(rand()%(b-a+1));

}

int jf(int a)
{
switch(a)
{
case 0:
return 0;
break;
case 1:
return 0;
break;
case 2:
return 10;
break;
case 3:
return 5;
break;
case 4:
return 20;
break;
case 5:
return -50;
break;

	}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值