c++打怪小游戏

历经多天的整理,写出来了更加全面,内容舒服的小游戏;也许有很多未知的bug。。。希望可以帮助到你们【内容由拼音构成,简单易懂】

下面是源代码,利用vs写成。

#include<iostream>
using namespace std;
double shengmingli = 2000;
int gongjili = 150;
int fangyuli = 200;
int money = 20;
bool guoguan;
void wuqidian();
void yaodian();
void guaiwu1();
void guaiwu2();
int main(void)
{
    cout << "欢迎你来到游戏世界!\n";
    cout << "小镇\n";
    cout << "一个古老的小镇,周围有一条河,河的旁边有一片树林,里面有许多房子和人。\n有一家药店" << endl;
    cout << "还有一家武器店.\n";
    int xiaozhen;
    cout << "1.去武器店" << endl;
    cout << "2.去药品店" << endl;
    cout << "3.去打小怪物" << endl;
    cout << "4.去打大怪物" << endl;
    cout << "5.退出游戏" << endl;
    cout << "6.显示你的状态" << endl;
    cin >> xiaozhen;
    while (xiaozhen != 5)
    {
        if (shengmingli <= 0)
        {
            cout << "你死了!" << endl;
            break;
        }
        else  if (guoguan)
        {
            cout << "恭喜通关!" << endl;
            break;
        }

        else if (xiaozhen == 6)
        {
            cout << "你的生命力:" << shengmingli << endl;
            cout << "你的攻击力:" << gongjili << endl;
            cout << "你的防御力:" << fangyuli << endl;
            cout << "你的财富:" << money << endl;

        }

        else  switch (xiaozhen)
        {
        case 1:wuqidian(); break;
        case 2:yaodian();  break;
        case 3:guaiwu1();  break;
        case 4:guaiwu2();  break;
        default: cout << "请不要乱选!" << endl; break;
        }
        cin >> xiaozhen;
    }
    
        if (xiaozhen == 5)
        {
            cout << "正在退出游戏" << endl;
        }
        cin.get();
        cin.get();
        return 0;
         
}

void wuqidian()
{
    cout << "欢迎来到武器店!" << endl;
    cout << "1、买小刀(1M加2攻击力)" << endl;
    cout << "2、买短剑(2M加20攻击力)" << endl;
    cout << "3、买长剑(5M加40攻击力)" << endl;
    cout << "4、买砍刀(7M加60攻击力)" << endl;
    cout << "5、买盾牌(2M加30防御力)" << endl;
    cout << "6、买铠甲(5M加60防御力)" << endl;
    cout << "7、离开武器店" << endl;
    int wuqidian;
    cin >> wuqidian;
    while (wuqidian != 7)
    {
        switch (wuqidian)
        {
        case 1:if (money < 10)
        {
            cout << "你的钱不够" << endl;
            cout << "请从新选择!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            break;
        }
              else
        {
            cout << "购买成功!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            gongjili += 2;
            money -= 10;
            cout << "攻击力为" << gongjili << endl;
            cout << "还剩下" << money << "元" << endl;
            break;
        }
        case 2: if (money < 80)
        {
            cout << "你的钱不够" << endl;
            cout << "请从新选择!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            break;
        }
              else
        {
            cout << "购买成功!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            gongjili += 20;
            money -= 80;
            cout << "攻击力为" << gongjili << endl;
            cout << "还剩下" << money << "元" << endl;
            break;
        }
        case 3:if (money < 140)
        {
            cout << "你的钱不够" << endl;
            cout << "请从新选择!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            break;
        }
              else
        {
            cout << "购买成功!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            gongjili += 40;
            money -= 140;
            cout << "攻击力为" << gongjili << endl;
            cout << "还剩下" << money << "元" << endl;
            break;
        }
        case 4:if (money < 200)
        {
            cout << "你的钱不够" << endl;
            cout << "请从新选择!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            break;
        }
              else
        {
            cout << "购买成功!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            gongjili += 60;
            money -= 200;
            cout << "攻击力为" << gongjili << endl;
            cout << "还剩下" << money << "元" << endl;
            break;
        }
        case 5:if (money < 60)
        {
            cout << "你的钱不够" << endl;
            cout << "请从新选择!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            break;
        }
              else
        {
            cout << "购买成功!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            fangyuli += 30;
            money -= 60;
            cout << "防御力为" << fangyuli << endl;
            cout << "还剩下" << money << "元" << endl;
            break;
        }
        case 6:if (money < 100)
        {
            cout << "你的钱不够" << endl;
            cout << "请从新选择!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            break;
        }
              else
        {
            cout << "购买成功!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            fangyuli += 60;
            money -= 100;
            cout << "防御力为" << fangyuli << endl;
            cout << "还剩下" << money << "元" << endl;
            break;
        }
        default: cout << "不要调皮" << endl;
            cout << "请从新选择!" << endl;
            cout << "1、买小刀(1M加2攻击力)" << endl;
            cout << "2、买短剑(2M加20攻击力)" << endl;
            cout << "3、买长剑(5M加40攻击力)" << endl;
            cout << "4、买砍刀(7M加60攻击力)" << endl;
            cout << "5、买盾牌(2M加30防御力)" << endl;
            cout << "6、买铠甲(5M加60防御力)" << endl;
            cout << "7、离开武器店" << endl;
            break;
        }
        cin >> wuqidian;
    }
        if (wuqidian == 7)
        {
            cout << "欢迎下次再来!" << endl;
            cout << "欢迎你来到游戏世界!\n";
            cout << "小镇\n";
            cout << "一个古老的小镇,周围有一条河,河的旁边有一片树林,里面有许多房子和人。\n有一家药店" << endl;
            cout << "还有一家武器店.\n";
            cout << "1.去武器店" << endl;
            cout << "2.去药品店" << endl;
            cout << "3.去打小怪物" << endl;
            cout << "4.去打大怪物" << endl;
            cout << "5.退出游戏" << endl;
            cout << "6.显示你的状态" << endl;
        }
       
}
void yaodian()
{
    cout << "欢迎来到药品店!" << endl;
    cout << "1、小血包(10M加200生命力)" << endl;
    cout << "2、中血包(50M加1000攻击力)" << endl;
    cout << "3、大血包(100M加2200攻击力)" << endl;
    cout << "4、离开药品" << endl;
    int yaodian;
    cin >> yaodian;
    while (yaodian != 4)
    {
        switch (yaodian)
        {
        case 1:if (money < 10)
        {
            cout << "你的钱不够" << endl;
            cout << "请重新选择!" << endl;
            cout << "1、小血包(10M加200生命力)" << endl;
            cout << "2、中血包(50M加1000攻击力)" << endl;
            cout << "3、大血包(100M加2200攻击力)" << endl;
            cout << "4、离开药品" << endl;
            break;
        }
              else
        {
            cout << "购买成功!" << endl;
            cout << "1、小血包(10M加200生命力)" << endl;
            cout << "2、中血包(50M加1000生命力)" << endl;
            cout << "3、大血包(100M加2200生命力)" << endl;
            cout << "4、离开药品" << endl;
            shengmingli += 200;
            money -= 10;
            cout << "还剩下" << money << "元" << endl;
            break;
        }
        case 2: if (money < 50)
        {
            cout << "你的钱不够" << endl;
            cout << "请从新选择!" << endl;
            cout << "1、小血包(10M加200生命力)" << endl;
            cout << "2、中血包(50M加1000生命力)" << endl;
            cout << "3、大血包(100M加2200生命力)" << endl;
            cout << "4、离开药品" << endl;
        }
              else
        {
            cout << "购买成功!" << endl;
            cout << "1、小血包(10M加200生命力)" << endl;
            cout << "2、中血包(50M加1000生命力)" << endl;
            cout << "3、大血包(100M加2200生命力)" << endl;
            cout << "4、离开药品" << endl;
            shengmingli += 1000;
            money -= 50;
            cout << "还剩下" << money << "元" << endl;
            break;
        }
        case 3:if (money < 100)
        {
            cout << "你的钱不够" << endl;
            cout << "请重新选择" << endl;
            cout << "1、小血包(10M加200生命力)" << endl;
            cout << "2、中血包(50M加1000生命力)" << endl;
            cout << "3、大血包(100M加2200生命力)" << endl;
            cout << "4、离开药品" << endl;
        }
              else
        {
            cout << "购买成功!" << endl;
            cout << "1、小血包(10M加200生命力)" << endl;
            cout << "2、中血包(50M加1000生命力)" << endl;
            cout << "3、大血包(100M加2200生命力)" << endl;
            cout << "4、离开药品" << endl;
            shengmingli += 2200;
            money -= 100;
            cout << "还剩下" << money << "元" << endl;
            break;
        }
        default:cout << " " << endl;
            break;
        }
        cin >> yaodian;
    }
    if (yaodian == 4)
    {
        cout << "欢迎下次再来!" << endl;
        cout << "欢迎你来到游戏世界!\n";
        cout << "小镇\n";
        cout << "一个古老的小镇,周围有一条河,河的旁边有一片树林,里面有许多房子和人。\n有一家药店" << endl;
        cout << "还有一家武器店.\n";
        cout << "1.去武器店" << endl;
        cout << "2.去药品店" << endl;
        cout << "3.去打小怪物" << endl;
        cout << "4.去打大怪物" << endl;
        cout << "5.退出游戏" << endl;
        cout << "6.显示你的状态" << endl;
    }
}
void guaiwu1()
{
    cout << "开始与小怪物战斗!!!" << endl;
    double* g_shengmingli = new double;
    int* g_gongjili = new int;
    int* g_fangyuli = new int;
    int* g_money = new int;
    *g_shengmingli = 100;
    *g_gongjili = 5;
    *g_fangyuli = 3;
    *g_money = 5;
    double* gongji1 = new double;
    double* gongji2 = new double;
    *gongji1 = 0;
    *gongji2 = 0;
    int* huihe = new int;
    *huihe = 1;
    cout << "你开始对小怪物进行攻击!" << endl;
    int* xuanze = new int;

    while ((*g_shengmingli) > 0 && shengmingli > 0 && (*xuanze) != 2)
    {
        cout << "现在是" << "第" << *huihe << "回合" << endl;
        cout << "请选择你的动作:\n";
        cout << "1、攻击\n2、逃跑\n";
        cin >> *xuanze;
        switch ((*xuanze))
        {
        case 1:cout << "你对小怪物发起了进攻!" << endl;
            *g_shengmingli-=  (gongjili * 2) - (*g_fangyuli);
            *gongji1 = (gongjili * 2) - (*g_fangyuli);
            cout << "你打掉了怪物1:" << *gongji1 << "的生命" << endl;
            cout << "怪物1还剩" << *g_shengmingli << "的生命" << endl;
            shengmingli = shengmingli - ((*g_gongjili * 2) - fangyuli);
            *gongji2 = (*g_gongjili * 2) - fangyuli;
            if ((*g_shengmingli <= 0))
            {
                cout << "太棒了!你打败了小怪物!"; break;
            }
            else
            {
                cout << "小怪物对你发起了进攻!" << endl;
                cout << "小怪物打掉你" << *gongji2 << "的生命" << endl;
                cout << "你还剩" << shengmingli << "的生命" << endl;
                continue;
            }
        case 2:cout << "你决定逃跑" << endl;
            cout << "逃跑成功!" << endl; continue;
        default: cout << "不要乱来!" << endl;
        }
        if(*xuanze==1)
        { 
            if (*g_shengmingli <= 0)
            {
                cout << " \n" << endl;
            }
            else
            { 
              (*huihe)++;
               cout << "第"<<( * huihe) << "回合" << endl;
            }
        }
    }
    if ((*g_shengmingli) <= 0)
    {
        
        money += (*g_money);
        cout << "你拥有\n" << money << "的金币" << endl;
        cout << "欢迎你来到游戏世界!\n";
        cout << "小镇\n";
        cout << "一个古老的小镇,周围有一条河,河的旁边有一片树林,里面有许多房子和人。\n有一家药店" << endl;
        cout << "还有一家武器店.\n";
        cout << "1.去武器店" << endl;
        cout << "2.去药品店" << endl;
        cout << "3.去打小怪物" << endl;
        cout << "4.去打大怪物" << endl;
        cout << "5.退出游戏" << endl;
        cout << "6.显示你的状态" << endl;
    }
    else if (shengmingli <= 0)
    {
        cout << "你被怪物杀死了!" << endl;
    }
    else if ((*xuanze) == 2)
    {
        cout << "逃跑成功!" << endl;
        cout << "欢迎你来到游戏世界!\n";
        cout << "小镇\n";
        cout << "一个古老的小镇,周围有一条河,河的旁边有一片树林,里面有许多房子和人。\n有一家药店" << endl;
        cout << "还有一家武器店.\n";
        cout << "1.去武器店" << endl;
        cout << "2.去药品店" << endl;
        cout << "3.去打小怪物" << endl;
        cout << "4.去打大怪物" << endl;
        cout << "5.退出游戏" << endl;
        cout << "6.显示你的状态" << endl;
    }
    delete g_shengmingli;
    delete g_gongjili;
    delete g_fangyuli;
    delete g_money;
    delete gongji1;
    delete gongji2;
}
void guaiwu2()
{
    cout << "开始与大怪物战斗!!!" << endl;
    double* g_shengmingli = new double;
    int* g_gongjili = new int;
    int* g_fangyuli = new int;
    int* g_money = new int;
    *g_shengmingli = 3600;
    *g_gongjili = 50;
    *g_fangyuli = 30;
    *g_money = 50;
    double* gongji1 = new double;
    double* gongji2 = new double;
    *gongji1 = 0;
    *gongji2 = 0;
    int* huihe = new int;
    *huihe = 1;
    cout << "你开始对大怪物进行攻击!" << endl;
    int* xuanze = new int;

    while ((*g_shengmingli) > 0 && shengmingli > 0 && (*xuanze) != 2)
    {
        cout << "现在是" << "第" << *huihe << "回合" << endl;
        cout << "请选择你的动作:\n";
        cout << "1、攻击\n2、逃跑\n";
        cin >> *xuanze;
        switch ((*xuanze))
        {
        case 1:cout << "你对大怪物发起了进攻!" << endl;
            *g_shengmingli-= (gongjili * 2 )- (*g_fangyuli);
            *gongji1 = (gongjili * 2) - (*g_fangyuli);
            cout << "你打掉了大怪物" << *gongji1 << "的生命" << endl;
            cout << "怪物还剩" << *g_shengmingli << "的生命" << endl;
            shengmingli-= ((*g_gongjili * 2) - fangyuli);
            *gongji2 = (*g_gongjili * 2) - fangyuli;
            if ((*g_shengmingli <= 0))
            {
                cout << "太棒了!你打败了小怪物!"; break;
            }
            else
            {
                cout << "大怪物对你发起了进攻!" << endl;
                cout << "大怪物打掉你" << ( * gongji2) << "的生命" << endl;
                cout << "你还剩" << shengmingli << "的生命" << endl;
                continue;
            }
        case 2:cout << "你决定逃跑" << endl;
            cout << "逃跑成功!" << endl; continue;
        default: cout << "不要乱来!" << endl; continue;
        }
        if (*xuanze == 1)
        {
            if (*g_shengmingli <= 0)
            {
                cout << " \n" << endl;
            }
            else
            {
                (*huihe++);
                cout << "第" << (*huihe) << "回合" << endl;
            }
        }
    }
    if ((*g_shengmingli) <= 0)
    {
        money +=( * g_money);
        cout << "太棒了,你打败了敌人!" << endl;
        cout << "你拥有\n" << money << "的金币" << endl;
        guoguan = true;
        cout << "欢迎你来到游戏世界!\n";
        cout << "小镇\n";
        cout << "一个古老的小镇,周围有一条河,河的旁边有一片树林,里面有许多房子和人。\n有一家药店" << endl;
        cout << "还有一家武器店.\n";
        cout << "1.去武器店" << endl;
        cout << "2.去药品店" << endl;
        cout << "3.去打小怪物" << endl;
        cout << "4.去打大怪物" << endl;
        cout << "5.退出游戏" << endl;
        cout << "6.显示你的状态" << endl;
    }
    else if (shengmingli <= 0)
    {
        cout << "你被怪物杀死了!" << endl;
    }
    else if ((*xuanze) == 2)
    {
        cout << "逃跑成功!" << endl;
        cout << "欢迎你来到游戏世界!\n";
        cout << "小镇\n";
        cout << "一个古老的小镇,周围有一条河,河的旁边有一片树林,里面有许多房子和人。\n有一家药店" << endl;
        cout << "还有一家武器店.\n";
        cout << "1.去武器店" << endl;
        cout << "2.去药品店" << endl;
        cout << "3.去打小怪物" << endl;
        cout << "4.去打大怪物" << endl;
        cout << "5.退出游戏" << endl;
        cout << "6.显示你的状态" << endl;
    }
    delete g_shengmingli;
    delete g_gongjili;
    delete g_fangyuli;
    delete g_money;
    delete gongji1;
    delete gongji2;
}




  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

slime _

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值