//Console_Main.h
static int Way;//行走方向
static int Life;//生命
static int Ammo;//弹药
static int Armor;//护甲
void Set_Events(int);//行走事件
void Set_Chest(int);//箱子事件
//Console_Main.cpp
#include <iostream>
#include "Console_Main.h"
using namespace std;
//程序入口
int main()
{
Life=100;
Ammo=100;
Armor=100;
for (int ni=0;ni<100;ni++)
{
cout<<"生命:"<<Life<<" 弹药:"<<Ammo<<" 护甲:"<<Armor<<endl;
cout<<"您决定往哪个方向走?"<<endl;
cout<<"1、前 "<<"2、后 "<<"3、左 "<<"4、右"<<endl;
cin>>Way;
Set_Events(Way);
cin.get();
cin.get();
}
return 0;
}
//设置事件内容
void Set_Events(int ni)
{
switch(ni)
{
case 1:
cout<<"发现一些箱子"<<endl;
cout<<"您决定打开几号箱子?(1~7)";
int nChest;
cin>>nChest;
Set_Chest(nChest);
break;
case 2:
cout<<"什么都没有发现"<<endl;
break;
case 3:
cout<<"发现一条道路"<<endl;
break;
default:
cout<<"发现一个怪物"<<endl;
break;
}
}
//设置箱子内容
void Set_Chest(int ni)
{
switch(ni)
{
case 1:
cout<<"+10单位弹药"<<endl;
Ammo+=10;
break;
case 2:
cout<<"-10单位弹药"<<endl;
if (Ammo>0)
{
Ammo-=10;
}
break;
case 3:
cout<<"+10单位护甲"<<endl;
Armor+=10;
break;
case 4:
cout<<"-10单位护甲"<<endl;
if (Armor>0)
{
Armor-=10;
}
break;
case 5:
cout<<"+10单位生命"<<endl;
Life+=10;
break;
case 6:
cout<<"-10单位生命"<<endl;
if (Life>0)
{
Life-=10;
}
break;
default:
cout<<"里面竟然是空的!"<<endl;
break;
}
}
可以走100步,开箱子得到或失去东西,这些都不太难。