ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

c++自制小游戏(不完美)

2022-03-21 11:32:34  阅读:177  来源: 互联网

标签:10 cout int 自制 hard c++ else 小游戏 type


我做的一个挖矿小游戏,后面会改进一些读入与输出,有建议的话记得评论区留言。

上代码:

#include <bits/stdc++.h>
using namespace std;
struct block{
    int type,hard;
};
int xx=7,yy=0,hunger=100,money=0,strong=1;
int price[100]={1,5,8,8,10,12,30,60,100,170,130,170,300,180,220,400,20};
int bprice[100]={20};
int upgradeprice=20;
block g[101][301]={{0}};
int backpack[100]={0};
void out(int i,int j){
    block x=g[i][j];
    if(i==yy&&j==xx)
    {
        cout<<" 你  ";
        return ;
    }
    switch (x.type)
    {
        case -1:cout<<"     ";break;
        case 0:cout<<"石头 ";break;
        case 1:cout<<"煤炭 ";break;
        case 2:cout<<"铁矿 ";break;
        case 3:cout<<"铝矿 ";break;
        case 4:cout<<"铜矿 ";break;
        case 5:cout<<"锡矿 ";break;
        case 6:cout<<"银矿 ";break;
        case 7:cout<<"金矿 ";break;
        case 8:cout<<"祖绿 ";break;
        case 9:cout<<"水晶 ";break;
        case 10:cout<<"石油 ";break;
        case 11:cout<<"钻石 ";break;
        case 12:cout<<"合金 ";break;
        case 13:cout<<"电石 ";break;
        case 14:cout<<"气石 ";break;
        case 15:cout<<"明铁 ";break;
    }
}
void print(){
    cout<<"控制键:wasd上左下右,m卖东西(ad切换卖的东西,y确认,s全卖),e刷新地图"<<endl;
    cout<<"b买东西(ad切换买的东西,y确认,最后输入买的个数),c吃面包,u升级"<<endl;
    cout<<"钱:"<<money<<"  "<<"饥饿:"<<hunger<<" 强度:"<<strong<<" 升级花费:"<<upgradeprice<<endl;
    cout<<"石"<<backpack[0]<<" ";
    cout<<"煤"<<backpack[1]<<" ";
    cout<<"铁"<<backpack[2]<<" ";
    cout<<"铝"<<backpack[3]<<" ";
    cout<<"铜"<<backpack[4]<<" ";
    cout<<"锡"<<backpack[5]<<" ";
    cout<<"银"<<backpack[6]<<" ";
    cout<<"金"<<backpack[7]<<" ";
    cout<<"绿"<<backpack[8]<<" ";
    cout<<"晶"<<backpack[9]<<" ";
    cout<<"油"<<backpack[10]<<" ";
    cout<<"钻"<<backpack[11]<<" ";
    cout<<"合"<<backpack[12]<<" ";
    cout<<"电"<<backpack[13]<<" ";
    cout<<"气"<<backpack[14]<<" ";
    cout<<"明"<<backpack[15]<<" ";
    cout<<"面包"<<backpack[16]<<endl;
    for(int i=1;i<=max(9-yy,0);i++)
    {
        cout<<endl;
    }
    cout<<"    ";
    for(int i=max(xx-10,1);i<=min(xx+10,100);i++)
    {
        if(yy==0&&xx==i)
        {
            cout<<" 你  ";
        }
        else
        {
            cout<<"     ";
        }
    }
    cout<<endl;
    for(int i=max(yy-4,1);i<=yy+6;i++)
    {
        if(i<10)
        {
            cout<<"  "<<i<<":";
        }
        else if(i<100)
        {
            cout<<" "<<i<<":";
        }
        else if(i<1000)
        {
            cout<<i<<":";
        }
        for(int j=max(xx-10,1);j<=min(xx+10,100);j++)
        {
            out(i,j);
        }
        cout<<endl;
        
        if(i<10)
        {
            cout<<"  "<<i<<":";
        }
        else if(i<100)
        {
            cout<<" "<<i<<":";
        }
        else if(i<1000)
        {
            cout<<i<<":";
        }
        for(int j=max(xx-10,1);j<=min(xx+10,100);j++)
        {
            out(i,j);
        }
        cout<<endl;
    }
}
void sellprint(int x){
    if(x==0){
        cout<<"选择石头 ";
    }
    else cout<<"石"<<backpack[0]<<" ";
    if(x==1){
        cout<<"选择煤炭 ";
    }
    else cout<<"煤"<<backpack[1]<<" ";
    if(x==2){
        cout<<"选择铁矿 ";
    }
    else cout<<"铁"<<backpack[2]<<" ";
    if(x==3){
        cout<<"选择铝矿 ";
    }
    else cout<<"铝"<<backpack[3]<<" ";
    if(x==4){
        cout<<"选择铜矿 ";
    }
    else cout<<"铜"<<backpack[4]<<" ";
    if(x==5){
        cout<<"选择锡矿 ";
    }
    else cout<<"锡"<<backpack[5]<<" ";
    if(x==6){
        cout<<"选择银矿 ";
    }
    else cout<<"银"<<backpack[6]<<" ";
    if(x==7){
        cout<<"选择金矿 ";
    }
    else cout<<"金"<<backpack[7]<<" ";
    if(x==8){
        cout<<"选择祖绿 ";
    }
    else cout<<"绿"<<backpack[8]<<" ";
    if(x==9){
        cout<<"选择水晶 ";
    }
    else cout<<"晶"<<backpack[9]<<" ";
    if(x==10){
        cout<<"选择石油 ";
    }
    else cout<<"油"<<backpack[10]<<" ";
    if(x==11){
        cout<<"选择钻石 ";
    }
    else cout<<"钻"<<backpack[11]<<" ";
    if(x==12){
        cout<<"选择合金 ";
    }
    else cout<<"合"<<backpack[12]<<" ";
    if(x==13){
        cout<<"选择电石 ";
    }
    else cout<<"电"<<backpack[13]<<" ";
    if(x==14){
        cout<<"选择气石 ";
    }
    else cout<<"气"<<backpack[14]<<" ";
    if(x==15){
        cout<<"选择明铁 ";
    }
    else cout<<"明"<<backpack[15]<<endl;
}
void sell(){
    char c;
    int ch=1;
    sellprint(ch);
    cin>>c;
    while(c!='y')
    {
        switch(c)
        {
            case 'a':if(ch!=0){ch--;}break;
            case 'd':if(ch!=15){ch++;}break;
            case 's':for(int i=0;i<=15;i++){money+=backpack[i]*price[i],backpack[i]=0;}cout<<"兑换成功"<<endl;return ;
        }
        sellprint(ch);
        cin>>c;
    }
    cout<<"兑换成功"<<endl;
    money+=backpack[ch]*price[ch];
    backpack[ch]=0;
}
void buyprint(int x){
    if(x==0)
    {
        cout<<"选择面包 ";
    }
    else
    {
        cout<<"面包"<<bprice[0];
    }
    cout<<endl;
}
void buy(){
    char c;
    int ch=0;
    buyprint(ch);
    cin>>c;
    while(c!='y')
    {
        switch(c)
        {
            case 'a':if(ch!=0){ch--;}break;
            case 'd':if(ch!=0){ch++;}break;
        }
        buyprint(ch);
        cin>>c;
    }
    int num;
    cin>>num;
    if(money>=num*bprice[ch])
    {
        money-=num*bprice[ch];
        backpack[ch+16]+=num;
        cout<<"购买成功"<<endl;
        return ;
    }
    else
    {
        cout<<"余额不足"<<endl;
        return ;
    }
}
void make(){
    
    for(int i=0;i<=13;i++){
        for(int j=1;j<=10;j++){
            for(int k=1;k<=100;k++){
                if(i==0){
                    int x=rand()%1000;
                    if(x<100)
                    {
                        g[i*10+j][k].type=1;
                        g[i*10+j][k].hard=4;
                    }
                    else if(x<130)
                    {
                        g[i*10+j][k].type=2;
                        g[i*10+j][k].hard=6;
                    }
                    else if(x<140)
                    {
                        g[i*10+j][k].type=3;
                        g[i*10+j][k].hard=8;
                    }
                    else if(x<145)
                    {
                        g[i*10+j][k].type=4;
                        g[i*10+j][k].hard=10;
                    }
                    else if(x<147)
                    {
                        g[i*10+j][k].type=5;
                        g[i*10+j][k].hard=12;
                    }
                    else if(x<148)
                    {
                        g[i*10+j][k].type=6;
                        g[i*10+j][k].hard=14;
                    }
                    else if(x<149)
                    {
                        g[i*10+j][k].type=7;
                        g[i*10+j][k].hard=16;
                    }
                    else if(x<150)
                    {
                        g[i*10+j][k].type=8;
                        g[i*10+j][k].hard=18;
                    }
                    else
                    {
                        g[i*10+j][k].type=0;
                        g[i*10+j][k].hard=4;
                    }
                }
                if(i==1){
                    int x=rand()%1000;
                    if(x<100)
                    {
                        g[i*10+j][k].type=1;
                        g[i*10+j][k].hard=4;
                    }
                    else if(x<150)
                    {
                        g[i*10+j][k].type=2;
                        g[i*10+j][k].hard=6;
                    }
                    else if(x<180)
                    {
                        g[i*10+j][k].type=3;
                        g[i*10+j][k].hard=8;
                    }
                    else if(x<195)
                    {
                        g[i*10+j][k].type=4;
                        g[i*10+j][k].hard=10;
                    }
                    else if(x<205)
                    {
                        g[i*10+j][k].type=5;
                        g[i*10+j][k].hard=12;
                    }
                    else if(x<210)
                    {
                        g[i*10+j][k].type=6;
                        g[i*10+j][k].hard=14;
                    }
                    else if(x<211)
                    {
                        g[i*10+j][k].type=7;
                        g[i*10+j][k].hard=16;
                    }
                    else if(x<212)
                    {
                        g[i*10+j][k].type=8;
                        g[i*10+j][k].hard=18;
                    }
                    else if(x<213)
                    {
                        g[i*10+j][k].type=9;
                        g[i*10+j][k].hard=20;
                    }
                    else
                    {
                        g[i*10+j][k].type=0;
                        g[i*10+j][k].hard=4;
                    }
                }
                if(i==2){
                    int x=rand()%1000;
                    if(x<100)
                    {
                        g[i*10+j][k].type=1;
                        g[i*10+j][k].hard=4;
                    }
                    else if(x<150)
                    {
                        g[i*10+j][k].type=2;
                        g[i*10+j][k].hard=6;
                    }
                    else if(x<200)
                    {
                        g[i*10+j][k].type=3;
                        g[i*10+j][k].hard=8;
                    }
                    else if(x<230)
                    {
                        g[i*10+j][k].type=4;
                        g[i*10+j][k].hard=10;
                    }
                    else if(x<250)
                    {
                        g[i*10+j][k].type=5;
                        g[i*10+j][k].hard=12;
                    }
                    else if(x<260)
                    {
                        g[i*10+j][k].type=6;
                        g[i*10+j][k].hard=14;
                    }
                    else if(x<265)
                    {
                        g[i*10+j][k].type=7;
                        g[i*10+j][k].hard=16;
                    }
                    else if(x<266)
                    {
                        g[i*10+j][k].type=8;
                        g[i*10+j][k].hard=18;
                    }
                    else if(x<267)
                    {
                        g[i*10+j][k].type=9;
                        g[i*10+j][k].hard=20;
                    }
                    else if(x<268)
                    {
                        g[i*10+j][k].type=10;
                        g[i*10+j][k].hard=22;
                    }
                    else
                    {
                        g[i*10+j][k].type=0;
                        g[i*10+j][k].hard=4;
                    }
                }
                if(i==3){
                    int x=rand()%1000;
                    if(x<100)
                    {
                        g[i*10+j][k].type=1;
                        g[i*10+j][k].hard=4;
                    }
                    else if(x<150)
                    {
                        g[i*10+j][k].type=2;
                        g[i*10+j][k].hard=6;
                    }
                    else if(x<190)
                    {
                        g[i*10+j][k].type=3;
                        g[i*10+j][k].hard=8;
                    }
                    else if(x<230)
                    {
                        g[i*10+j][k].type=4;
                        g[i*10+j][k].hard=10;
                    }
                    else if(x<260)
                    {
                        g[i*10+j][k].type=5;
                        g[i*10+j][k].hard=12;
                    }
                    else if(x<280)
                    {
                        g[i*10+j][k].type=6;
                        g[i*10+j][k].hard=14;
                    }
                    else if(x<300)
                    {
                        g[i*10+j][k].type=7;
                        g[i*10+j][k].hard=16;
                    }
                    else if(x<310)
                    {
                        g[i*10+j][k].type=8;
                        g[i*10+j][k].hard=18;
                    }
                    else if(x<315)
                    {
                        g[i*10+j][k].type=9;
                        g[i*10+j][k].hard=20;
                    }
                    else if(x<316)
                    {
                        g[i*10+j][k].type=10;
                        g[i*10+j][k].hard=22;
                    }
                    else if(x<317)
                    {
                        g[i*10+j][k].type=11;
                        g[i*10+j][k].hard=24;
                    }
                    else
                    {
                        g[i*10+j][k].type=0;
                        g[i*10+j][k].hard=4;
                    }
                }
                if(i==4){
                    int x=rand()%1000;
                    if(x<80){
                        g[i*10+j][k].type=1;
                        g[i*10+j][k].hard=4;
                    }
                    else if(x<130){
                        g[i*10+j][k].type=2;
                        g[i*10+j][k].hard=6;
                    }
                    else if(x<170){
                        g[i*10+j][k].type=3;
                        g[i*10+j][k].hard=8;
                    }
                    else if(x<210){
                        g[i*10+j][k].type=4;
                        g[i*10+j][k].hard=10;
                    }
                    else if(x<250){
                        g[i*10+j][k].type=5;
                        g[i*10+j][k].hard=12;
                    }
                    else if(x<270){
                        g[i*10+j][k].type=6;
                        g[i*10+j][k].hard=14;
                    }
                    else if(x<290){
                        g[i*10+j][k].type=7;
                        g[i*10+j][k].hard=16;
                    }
                    else if(x<310){
                        g[i*10+j][k].type=8;
                        g[i*10+j][k].hard=18;
                    }
                    else if(x<320){
                        g[i*10+j][k].type=9;
                        g[i*10+j][k].hard=20;
                    }
                    else if(x<325){
                        g[i*10+j][k].type=10;
                        g[i*10+j][k].hard=22;
                    }
                    else if(x<330){
                        g[i*10+j][k].type=11;
                        g[i*10+j][k].hard=24;
                    }
                    else if(x<331){
                        g[i*10+j][k].type=12;
                        g[i*10+j][k].hard=26;
                    }
                    else
                    {
                        g[i*10+j][k].type=0;
                        g[i*10+j][k].hard=4;
                    }
                }
                if(i==5){
                    int x=rand()%1000;
                    if(x<50){
                        g[i*10+j][k].type=1;
                        g[i*10+j][k].hard=4;
                    }
                    else if(x<80){
                        g[i*10+j][k].type=2;
                        g[i*10+j][k].hard=6;
                    }
                    else if(x<110){
                        g[i*10+j][k].type=3;
                        g[i*10+j][k].hard=8;
                    }
                    else if(x<140){
                        g[i*10+j][k].type=4;
                        g[i*10+j][k].hard=10;
                    }
                    else if(x<170){
                        g[i*10+j][k].type=5;
                        g[i*10+j][k].hard=12;
                    }
                    else if(x<200){
                        g[i*10+j][k].type=6;
                        g[i*10+j][k].hard=14;
                    }
                    else if(x<230){
                        g[i*10+j][k].type=7;
                        g[i*10+j][k].hard=16;
                    }
                    else if(x<260){
                        g[i*10+j][k].type=8;
                        g[i*10+j][k].hard=18;
                    }
                    else if(x<280){
                        g[i*10+j][k].type=9;
                        g[i*10+j][k].hard=20;
                    }
                    else if(x<295){
                        g[i*10+j][k].type=10;
                        g[i*10+j][k].hard=22;
                    }
                    else if(x<310){
                        g[i*10+j][k].type=11;
                        g[i*10+j][k].hard=24;
                    }
                    else if(x<315){
                        g[i*10+j][k].type=12;
                        g[i*10+j][k].hard=26;
                    }
                    else
                    {
                        g[i*10+j][k].type=0;
                        g[i*10+j][k].hard=4;
                    }
                }
            }
        }
    }
}
int main()
{
    srand(time(NULL));
    make();
    print();
    for(int i=1;i<=100;i++)
    {
        g[0][i].type=-1;
        g[0][i].hard=0;
    }
    while(1)
    {
        char c;
        cin>>c;
        switch(c)
        {
            case 'w':if(yy!=0){
                if(g[yy-1][xx].hard<=strong){
                    yy--;
                    backpack[g[yy][xx].type]++;
                    g[yy][xx].type=-1;
                    g[yy][xx].hard=0;
                    hunger--;
                }
                else
                {
                    g[yy-1][xx].hard-=strong;
                    hunger--;
                }
                if(yy==0){
                    hunger=100;
                }
            }
            break;
            case 's':
                if(g[yy+1][xx].hard<=strong){
                    yy++;
                    backpack[g[yy][xx].type]++;
                    g[yy][xx].type=-1;
                    g[yy][xx].hard=0;
                    hunger--;
                }
                else
                {
                    g[yy+1][xx].hard-=strong;
                    hunger--;
                }
            if(yy==0){
                hunger=100;
                
            }
            break;
            case 'a':if(xx!=0){
                
                if(g[yy][xx-1].hard<=strong){
                    xx--;
                    backpack[g[yy][xx].type]++;
                    g[yy][xx].type=-1;
                    g[yy][xx].hard=0;
                    hunger--;
                }
                else
                {
                    g[yy][xx-1].hard-=strong;
                    hunger--;
                }
                if(yy==0){
                    hunger=100;
                }
                
            }
            break;
            case 'd':
                if(g[yy][xx+1].hard<=strong){
                    xx++;
                    backpack[g[yy][xx].type]++;
                    g[yy][xx].type=-1;
                    g[yy][xx].hard=0;
                    hunger--;
                }
                else
                {
                    g[yy][xx+1].hard-=strong;
                    hunger--;
                }
                if(yy==0){
                    hunger=100;
                }
                break;
            case 'm':sell();break;
            case 'e':make(),g[yy][xx].type=-1,g[yy][xx].hard=0,hunger-=20;break;
            case 'b':buy();break;
            case 'c':if(backpack[16]!=0){hunger+=25;backpack[16]--;}break;
            case 'u':if(money>=upgradeprice){money-=upgradeprice;strong++;upgradeprice*=2;}break;
        }
        if(hunger<=0)
        {
            cout<<"你死了";
            return 0;
        }
        print();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
struct block{
	int type,hard;
};
int xx=7,yy=0,hunger=100,money=0,strong=1;
int price[100]={1,5,8,8,10,12,30,60,100,170,130,170,300,180,220,400,20};
int bprice[100]={20};
int upgradeprice=20;
block g[101][301]={{0}};
int backpack[100]={0};
void out(int i,int j){
	block x=g[i][j];
	if(i==yy&&j==xx)
	{
		cout<<" 你  ";
		return ;
	}
	switch (x.type)
	{
		case -1:cout<<"     ";break;
		case 0:cout<<"石头 ";break;
		case 1:cout<<"煤炭 ";break;
		case 2:cout<<"铁矿 ";break;
		case 3:cout<<"铝矿 ";break;
		case 4:cout<<"铜矿 ";break;
		case 5:cout<<"锡矿 ";break;
		case 6:cout<<"银矿 ";break;
		case 7:cout<<"金矿 ";break;
		case 8:cout<<"祖绿 ";break;
		case 9:cout<<"水晶 ";break;
		case 10:cout<<"石油 ";break;
		case 11:cout<<"钻石 ";break;
		case 12:cout<<"合金 ";break;
		case 13:cout<<"电石 ";break;
		case 14:cout<<"气石 ";break;
		case 15:cout<<"明铁 ";break;
	}
}
void print(){
	cout<<"控制键:wasd上左下右,m卖东西(ad切换卖的东西,y确认,s全卖),e刷新地图"<<endl;
	cout<<"b买东西(ad切换买的东西,y确认,最后输入买的个数),c吃面包,u升级"<<endl;
	cout<<"钱:"<<money<<"  "<<"饥饿:"<<hunger<<" 强度:"<<strong<<" 升级花费:"<<upgradeprice<<endl;
	cout<<"石"<<backpack[0]<<" ";
	cout<<"煤"<<backpack[1]<<" ";
	cout<<"铁"<<backpack[2]<<" ";
	cout<<"铝"<<backpack[3]<<" ";
	cout<<"铜"<<backpack[4]<<" ";
	cout<<"锡"<<backpack[5]<<" ";
	cout<<"银"<<backpack[6]<<" ";
	cout<<"金"<<backpack[7]<<" ";
	cout<<"绿"<<backpack[8]<<" ";
	cout<<"晶"<<backpack[9]<<" ";
	cout<<"油"<<backpack[10]<<" ";
	cout<<"钻"<<backpack[11]<<" ";
	cout<<"合"<<backpack[12]<<" ";
	cout<<"电"<<backpack[13]<<" ";
	cout<<"气"<<backpack[14]<<" ";
	cout<<"明"<<backpack[15]<<" ";
	cout<<"面包"<<backpack[16]<<endl;
	for(int i=1;i<=max(9-yy,0);i++)
	{
		cout<<endl;
	}
	cout<<"    ";
	for(int i=max(xx-10,1);i<=min(xx+10,100);i++)
	{
		if(yy==0&&xx==i)
		{
			cout<<" 你  ";
		}
		else
		{
			cout<<"     ";
		}
	}
	cout<<endl;
	for(int i=max(yy-4,1);i<=yy+6;i++)
	{
		if(i<10)
		{
			cout<<"  "<<i<<":";
		}
		else if(i<100)
		{
			cout<<" "<<i<<":";
		}
		else if(i<1000)
		{
			cout<<i<<":";
		}
		for(int j=max(xx-10,1);j<=min(xx+10,100);j++)
		{
			out(i,j);
		}
		cout<<endl;
		
		if(i<10)
		{
			cout<<"  "<<i<<":";
		}
		else if(i<100)
		{
			cout<<" "<<i<<":";
		}
		else if(i<1000)
		{
			cout<<i<<":";
		}
		for(int j=max(xx-10,1);j<=min(xx+10,100);j++)
		{
			out(i,j);
		}
		cout<<endl;
	}
}
void sellprint(int x){
	if(x==0){
		cout<<"选择石头 ";
	}
	else cout<<"石"<<backpack[0]<<" ";
	if(x==1){
		cout<<"选择煤炭 ";
	}
	else cout<<"煤"<<backpack[1]<<" ";
	if(x==2){
		cout<<"选择铁矿 ";
	}
	else cout<<"铁"<<backpack[2]<<" ";
	if(x==3){
		cout<<"选择铝矿 ";
	}
	else cout<<"铝"<<backpack[3]<<" ";
	if(x==4){
		cout<<"选择铜矿 ";
	}
	else cout<<"铜"<<backpack[4]<<" ";
	if(x==5){
		cout<<"选择锡矿 ";
	}
	else cout<<"锡"<<backpack[5]<<" ";
	if(x==6){
		cout<<"选择银矿 ";
	}
	else cout<<"银"<<backpack[6]<<" ";
	if(x==7){
		cout<<"选择金矿 ";
	}
	else cout<<"金"<<backpack[7]<<" ";
	if(x==8){
		cout<<"选择祖绿 ";
	}
	else cout<<"绿"<<backpack[8]<<" ";
	if(x==9){
		cout<<"选择水晶 ";
	}
	else cout<<"晶"<<backpack[9]<<" ";
	if(x==10){
		cout<<"选择石油 ";
	}
	else cout<<"油"<<backpack[10]<<" ";
	if(x==11){
		cout<<"选择钻石 ";
	}
	else cout<<"钻"<<backpack[11]<<" ";
	if(x==12){
		cout<<"选择合金 ";
	}
	else cout<<"合"<<backpack[12]<<" ";
	if(x==13){
		cout<<"选择电石 ";
	}
	else cout<<"电"<<backpack[13]<<" ";
	if(x==14){
		cout<<"选择气石 ";
	}
	else cout<<"气"<<backpack[14]<<" ";
	if(x==15){
		cout<<"选择明铁 ";
	}
	else cout<<"明"<<backpack[15]<<endl;
}
void sell(){
	char c;
	int ch=1;
	sellprint(ch);
	cin>>c;
	while(c!='y')
	{
		switch(c)
		{
			case 'a':if(ch!=0){ch--;}break;
			case 'd':if(ch!=15){ch++;}break;
			case 's':for(int i=0;i<=15;i++){money+=backpack[i]*price[i],backpack[i]=0;}cout<<"兑换成功"<<endl;return ;
		}
		sellprint(ch);
		cin>>c;
	}
	cout<<"兑换成功"<<endl;
	money+=backpack[ch]*price[ch];
	backpack[ch]=0;
}
void buyprint(int x){
	if(x==0)
	{
		cout<<"选择面包 ";
	}
	else
	{
		cout<<"面包"<<bprice[0];
	}
	cout<<endl;
}
void buy(){
	char c;
	int ch=0;
	buyprint(ch);
	cin>>c;
	while(c!='y')
	{
		switch(c)
		{
			case 'a':if(ch!=0){ch--;}break;
			case 'd':if(ch!=0){ch++;}break;
		}
		buyprint(ch);
		cin>>c;
	}
	int num;
	cin>>num;
	if(money>=num*bprice[ch])
	{
		money-=num*bprice[ch];
		backpack[ch+16]+=num;
		cout<<"购买成功"<<endl;
		return ;
	}
	else
	{
		cout<<"余额不足"<<endl;
		return ;
	}
}
void make(){
	
	for(int i=0;i<=13;i++){
		for(int j=1;j<=10;j++){
			for(int k=1;k<=100;k++){
				if(i==0){
					int x=rand()%1000;
					if(x<100)
					{
						g[i*10+j][k].type=1;
						g[i*10+j][k].hard=4;
					}
					else if(x<130)
					{
						g[i*10+j][k].type=2;
						g[i*10+j][k].hard=6;
					}
					else if(x<140)
					{
						g[i*10+j][k].type=3;
						g[i*10+j][k].hard=8;
					}
					else if(x<145)
					{
						g[i*10+j][k].type=4;
						g[i*10+j][k].hard=10;
					}
					else if(x<147)
					{
						g[i*10+j][k].type=5;
						g[i*10+j][k].hard=12;
					}
					else if(x<148)
					{
						g[i*10+j][k].type=6;
						g[i*10+j][k].hard=14;
					}
					else if(x<149)
					{
						g[i*10+j][k].type=7;
						g[i*10+j][k].hard=16;
					}
					else if(x<150)
					{
						g[i*10+j][k].type=8;
						g[i*10+j][k].hard=18;
					}
					else
					{
						g[i*10+j][k].type=0;
						g[i*10+j][k].hard=4;
					}
				}
				if(i==1){
					int x=rand()%1000;
					if(x<100)
					{
						g[i*10+j][k].type=1;
						g[i*10+j][k].hard=4;
					}
					else if(x<150)
					{
						g[i*10+j][k].type=2;
						g[i*10+j][k].hard=6;
					}
					else if(x<180)
					{
						g[i*10+j][k].type=3;
						g[i*10+j][k].hard=8;
					}
					else if(x<195)
					{
						g[i*10+j][k].type=4;
						g[i*10+j][k].hard=10;
					}
					else if(x<205)
					{
						g[i*10+j][k].type=5;
						g[i*10+j][k].hard=12;
					}
					else if(x<210)
					{
						g[i*10+j][k].type=6;
						g[i*10+j][k].hard=14;
					}
					else if(x<211)
					{
						g[i*10+j][k].type=7;
						g[i*10+j][k].hard=16;
					}
					else if(x<212)
					{
						g[i*10+j][k].type=8;
						g[i*10+j][k].hard=18;
					}
					else if(x<213)
					{
						g[i*10+j][k].type=9;
						g[i*10+j][k].hard=20;
					}
					else
					{
						g[i*10+j][k].type=0;
						g[i*10+j][k].hard=4;
					}
				}
				if(i==2){
					int x=rand()%1000;
					if(x<100)
					{
						g[i*10+j][k].type=1;
						g[i*10+j][k].hard=4;
					}
					else if(x<150)
					{
						g[i*10+j][k].type=2;
						g[i*10+j][k].hard=6;
					}
					else if(x<200)
					{
						g[i*10+j][k].type=3;
						g[i*10+j][k].hard=8;
					}
					else if(x<230)
					{
						g[i*10+j][k].type=4;
						g[i*10+j][k].hard=10;
					}
					else if(x<250)
					{
						g[i*10+j][k].type=5;
						g[i*10+j][k].hard=12;
					}
					else if(x<260)
					{
						g[i*10+j][k].type=6;
						g[i*10+j][k].hard=14;
					}
					else if(x<265)
					{
						g[i*10+j][k].type=7;
						g[i*10+j][k].hard=16;
					}
					else if(x<266)
					{
						g[i*10+j][k].type=8;
						g[i*10+j][k].hard=18;
					}
					else if(x<267)
					{
						g[i*10+j][k].type=9;
						g[i*10+j][k].hard=20;
					}
					else if(x<268)
					{
						g[i*10+j][k].type=10;
						g[i*10+j][k].hard=22;
					}
					else
					{
						g[i*10+j][k].type=0;
						g[i*10+j][k].hard=4;
					}
				}
				if(i==3){
					int x=rand()%1000;
					if(x<100)
					{
						g[i*10+j][k].type=1;
						g[i*10+j][k].hard=4;
					}
					else if(x<150)
					{
						g[i*10+j][k].type=2;
						g[i*10+j][k].hard=6;
					}
					else if(x<190)
					{
						g[i*10+j][k].type=3;
						g[i*10+j][k].hard=8;
					}
					else if(x<230)
					{
						g[i*10+j][k].type=4;
						g[i*10+j][k].hard=10;
					}
					else if(x<260)
					{
						g[i*10+j][k].type=5;
						g[i*10+j][k].hard=12;
					}
					else if(x<280)
					{
						g[i*10+j][k].type=6;
						g[i*10+j][k].hard=14;
					}
					else if(x<300)
					{
						g[i*10+j][k].type=7;
						g[i*10+j][k].hard=16;
					}
					else if(x<310)
					{
						g[i*10+j][k].type=8;
						g[i*10+j][k].hard=18;
					}
					else if(x<315)
					{
						g[i*10+j][k].type=9;
						g[i*10+j][k].hard=20;
					}
					else if(x<316)
					{
						g[i*10+j][k].type=10;
						g[i*10+j][k].hard=22;
					}
					else if(x<317)
					{
						g[i*10+j][k].type=11;
						g[i*10+j][k].hard=24;
					}
					else
					{
						g[i*10+j][k].type=0;
						g[i*10+j][k].hard=4;
					}
				}
				if(i==4){
					int x=rand()%1000;
					if(x<80){
						g[i*10+j][k].type=1;
						g[i*10+j][k].hard=4;
					}
					else if(x<130){
						g[i*10+j][k].type=2;
						g[i*10+j][k].hard=6;
					}
					else if(x<170){
						g[i*10+j][k].type=3;
						g[i*10+j][k].hard=8;
					}
					else if(x<210){
						g[i*10+j][k].type=4;
						g[i*10+j][k].hard=10;
					}
					else if(x<250){
						g[i*10+j][k].type=5;
						g[i*10+j][k].hard=12;
					}
					else if(x<270){
						g[i*10+j][k].type=6;
						g[i*10+j][k].hard=14;
					}
					else if(x<290){
						g[i*10+j][k].type=7;
						g[i*10+j][k].hard=16;
					}
					else if(x<310){
						g[i*10+j][k].type=8;
						g[i*10+j][k].hard=18;
					}
					else if(x<320){
						g[i*10+j][k].type=9;
						g[i*10+j][k].hard=20;
					}
					else if(x<325){
						g[i*10+j][k].type=10;
						g[i*10+j][k].hard=22;
					}
					else if(x<330){
						g[i*10+j][k].type=11;
						g[i*10+j][k].hard=24;
					}
					else if(x<331){
						g[i*10+j][k].type=12;
						g[i*10+j][k].hard=26;
					}
					else
					{
						g[i*10+j][k].type=0;
						g[i*10+j][k].hard=4;
					}
				}
				if(i==5){
					int x=rand()%1000;
					if(x<50){
						g[i*10+j][k].type=1;
						g[i*10+j][k].hard=4;
					}
					else if(x<80){
						g[i*10+j][k].type=2;
						g[i*10+j][k].hard=6;
					}
					else if(x<110){
						g[i*10+j][k].type=3;
						g[i*10+j][k].hard=8;
					}
					else if(x<140){
						g[i*10+j][k].type=4;
						g[i*10+j][k].hard=10;
					}
					else if(x<170){
						g[i*10+j][k].type=5;
						g[i*10+j][k].hard=12;
					}
					else if(x<200){
						g[i*10+j][k].type=6;
						g[i*10+j][k].hard=14;
					}
					else if(x<230){
						g[i*10+j][k].type=7;
						g[i*10+j][k].hard=16;
					}
					else if(x<260){
						g[i*10+j][k].type=8;
						g[i*10+j][k].hard=18;
					}
					else if(x<280){
						g[i*10+j][k].type=9;
						g[i*10+j][k].hard=20;
					}
					else if(x<295){
						g[i*10+j][k].type=10;
						g[i*10+j][k].hard=22;
					}
					else if(x<310){
						g[i*10+j][k].type=11;
						g[i*10+j][k].hard=24;
					}
					else if(x<315){
						g[i*10+j][k].type=12;
						g[i*10+j][k].hard=26;
					}
					else
					{
						g[i*10+j][k].type=0;
						g[i*10+j][k].hard=4;
					}
				}
			}
		}
	}
}
int main()
{
	srand(time(NULL));
	make();
	print();
	for(int i=1;i<=100;i++)
	{
		g[0][i].type=-1;
		g[0][i].hard=0;
	}
	while(1)
	{
		char c;
		cin>>c;
		switch(c)
		{
			case 'w':if(yy!=0){
				if(g[yy-1][xx].hard<=strong){
					yy--;
					backpack[g[yy][xx].type]++;
					g[yy][xx].type=-1;
					g[yy][xx].hard=0;
					hunger--;
				}
				else
				{
					g[yy-1][xx].hard-=strong;
					hunger--;
				}
				if(yy==0){
					hunger=100;
				}
			}
			break;
			case 's':
				if(g[yy+1][xx].hard<=strong){
					yy++;
					backpack[g[yy][xx].type]++;
					g[yy][xx].type=-1;
					g[yy][xx].hard=0;
					hunger--;
				}
				else
				{
					g[yy+1][xx].hard-=strong;
					hunger--;
				}
			if(yy==0){
				hunger=100;
				
			}
			break;
			case 'a':if(xx!=0){
				
				if(g[yy][xx-1].hard<=strong){
					xx--;
					backpack[g[yy][xx].type]++;
					g[yy][xx].type=-1;
					g[yy][xx].hard=0;
					hunger--;
				}
				else
				{
					g[yy][xx-1].hard-=strong;
					hunger--;
				}
				if(yy==0){
					hunger=100;
				}
				
			}
			break;
			case 'd':
				if(g[yy][xx+1].hard<=strong){
					xx++;
					backpack[g[yy][xx].type]++;
					g[yy][xx].type=-1;
					g[yy][xx].hard=0;
					hunger--;
				}
				else
				{
					g[yy][xx+1].hard-=strong;
					hunger--;
				}
				if(yy==0){
					hunger=100;
				}
				break;
			case 'm':sell();break;
			case 'e':make(),g[yy][xx].type=-1,g[yy][xx].hard=0,hunger-=20;break;
			case 'b':buy();break;
			case 'c':if(backpack[16]!=0){hunger+=25;backpack[16]--;}break;
			case 'u':if(money>=upgradeprice){money-=upgradeprice;
                        strong++;upgradeprice*=2;}break;
		}
		if(hunger<=0)
		{
			cout<<"你死了";
			return 0;
		}
		print();
	}
	return 0;
}

标签:10,cout,int,自制,hard,c++,else,小游戏,type
来源: https://blog.csdn.net/weixin_60733069/article/details/123630506

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有