main.cpp
#include <iostream>
#include <string>
using namespace std;#include "Ultraman.h"
#include "Monster.h"int main(){
cout<<"欢迎来到奥特曼的世界!在奥特曼的世界,打怪兽就是全部!"<<endl;
cout<<"现在人人都有机会成为奥特曼,加入到与怪兽无止境的战斗中。"<<endl;
cout<<"可惜,并非人人生来就是英雄,革命尚未成功,同志仍需努力啊。"<<endl;
cout<<"每一个奥特曼都要从零开始,辛勤劳动,打怪升级,最终才能成为举世瞩目的大英雄。"<<endl<<endl;
char ch1=' ',ch2=' ',ch3=' ';
Ultraman u(1,0,10,1,0); //生成奥特曼对象并初始化
while(ch1!='Y'&&ch1!='y'&&ch1!='N'&&ch1!='n'){
cout<<"输入Y,打怪升级!"<<endl;
cout<<"输入N,退出游戏!"<<endl;
cin>>ch1;
cout<<endl;
}
if(ch1=='N'||ch1=='n')
{
cout<<"游戏结束!"<<endl;
exit(0);
} Monster m; //生成怪兽对象
while(ch1=='y'||ch1=='Y'){
ch1=' ';
ch2=' ';
ch3=' ';
m.get(0,0,0,0,0); //怪兽对象属性初始化
while(ch2!='u'&&ch2!='U'&&ch2!='m'&&ch2!='M'&&ch2!='f'&&ch2!='F'&&ch2!='e'&&ch2!='E'){
cout<<"请选择:"<<endl;
cout<<"u:查看自身状态;";
cout<<"m:查看对手状态;";
cout<<"f:打怪兽;";
cout<<"e:逃跑(将损失一定的生命值)。"<<endl;
cin>>ch2;
cout<<endl;
if(ch2=='u'||ch2=='U') {
u.display(); //成员函数调用
ch2=' ';
}
else if(ch2=='m'||ch2=='M') {
m.display(); // 成员函数调用
ch2=' ';
}
else if(ch2=='e'||ch2=='E') {
u.escape(); // 成员函数调用
if(u.getu_hp()<=0){ //成员函数调用,注意调用形式
cout<<"您英雄的一生结束了!"<<endl;
exit(0);
}
}
else if(ch2=='f'||ch2=='F') {
u.u_attack(&m);
u.upgrade(); //奥特曼升级,成员函数调用
int z=rand()%3+1;
switch(z){ //做个小改变,打得不那么单调无聊
case 1:
cout<<"ultraman say: go to die!"<<endl;
cout<<"monster say: oh,shit!"<<endl;
break;
case 2:
cout<<"奥特曼说: 妖怪受死!"<<endl;
cout<<"怪兽说: 放屁!"<<endl;
break;
default:
cout<<"12345啊,上山打老虎啊!"<<endl;
cout<<"大圣饶命!"<<endl;
}
cout<<"乒 乒 乓 乓。。。"<<endl;
m.m_fightback(&u); //成员函数调用,怪兽和奥特曼均受到攻击
u.display();
m.display();
if(u.getu_hp()<=0) { //成员函数调用,注意调用形式
cout<<"您英雄的一生结束了!"<<endl;
exit(0);
}
if(m.getm_hp()<=0) { // 成员函数调用,注意调用形式
cout<<"可...恶...,我还会再来的......"<<endl<<endl;
cout<<"恭喜你,打败了怪兽!"<<endl;
u.win(&m); //奥特曼获胜,成员函数调用
}
else ch2=' ';
}
}
while(ch3!='u'&&ch3!='U'&&ch3!='y'&&ch3!='Y'&&ch3!='n'&&ch3!='N'){
cout<<"是否用钱补血?查看自身状态请输入U,补血请输入Y,否则请输入N。"<<endl;
cin>>ch3;
cout<<endl;
if(ch3=='u'||ch3=='U'){
u.display(); //成员函数调用
ch3=' ';
}
if(ch3=='y'||ch3=='Y'){
if(u.getu_money()<2)
cout<<"对不起,您钱不够,无法补血!"<<endl;
else
u.restore(); //成员函数调用;
break;
}
if(ch3=='n'||ch3=='N') break;
}
while(ch1!='y'&&ch1!='Y'&&ch1!='n'&&ch1!='N'){
cout<<"继续打怪升级请输入Y,退出游戏请输入N。"<<endl;
cin>>ch1;
cout<<endl;
}
if(ch1=='N'||ch1=='n') {
cout<<"游戏结束!"<<endl;
exit(0);
} }
}