#include<iostream>
#include <ctime>
#include <cstdlib>
#include<iomanip>
#include<conio.h>
#include<windows.h>
using namespace std;
enum things {
practice = 1, attck, ESC
}value;
char level_list[][20] = {
{"凡夫"},
{"斗之气"},
{"斗者"},
{"斗师"},
{"大斗师"},
{"斗灵"},
{"斗王"},
{"斗皇"},
{"斗宗"},
{"斗尊"},
{"九转斗尊"},
{"半圣"},
{"斗圣"},
{"斗帝"}
};
typedef class Person {
public:
//构建人物
Person() {
srand(time(NULL));
abiliity = rand() % 10 + 1;
HP = abiliity * 10.0;
MP = abiliity * 20;
AD = abiliity * 2;
EXP = 0;
level = abiliity % 2;
name[0] = '\0';
}
char name[20];
float HP;
float AD;
float MP;
int EXP;
short level;
int abiliity;//资质
void practice();//修炼
void attck();
void Infor_print() {
cout << "+--------------------------+" << endl;
cout << "|玩家:" << setw(26 - strlen("玩家:")) << left << name << "|" << endl;
cout << "+--------------------------+" << endl;
cout << "|等级:" << setw(26 - strlen("等级:")) << left << level_list[level] << "|" << endl;
cout << "+--------------------------+" << endl;
cout << "|生命值:" << setw(26 - strlen("生命值:")) << left << HP << "|" << endl;
cout << "+--------------------------+" << endl;
cout << "|拳脚攻击:" << setw(26 - strlen("拳脚攻击:")) << left << AD << "|" << endl;
cout << "+--------------------------+" << endl;
cout << "|斗气:" << setw(26 - strlen("斗气:")) << left << MP << "|" << endl;
cout << "+--------------------------+" << endl;
cout << "|经验:" << setw(26 - strlen("经验:")) << left << EXP << "|" << endl;
cout << "+--------------------------+" << endl;
}
float hurt_method(int low, int high);
}P;
class Monster {
public:
//构建怪物
Monster(int plevel) {
srand(time(NULL));
ability = rand() % 10 + 1;
HP = ability * 10 * plevel;
AD = ability * plevel * plevel;
}
float hurt_method(int low, int high);
float HP;
float AD;
int ability;
};
int choose_UI() {
cout << " 1.修炼 2.战斗 3.退出" << endl;
int ret;
ret = _getch();
return ret;
}
int main() {
cout << "---------------- 斗破苍穹 -----------------\n 按任意键开始游戏" << endl;
P p1;
system("PAUSE");
system("cls");
cout << "创建角色名称:";
cin.getline(p1.name, 17);
while (1)
{
system("cls");
p1.Infor_print();//打印任务信息
value = (things)(choose_UI() - '0');//打印选择界面
system("cls");
switch (value)//进行功能判断
{
case practice: p1.practice(); continue;
case attck: p1.attck(); continue;
case ESC:
default: break;
}
if (value == ESC)
break;
}
cout << "成功登出游戏" << endl;
return 0;
}
//修炼函数
void Person::practice() {
int time;
system("cls");
cout << "请输入修炼时间单位为月:";
cin >> time;
while (time--) {
EXP += abiliity * 2;
if (EXP && EXP >= (level * level * 10))
{
if (level < 13)
{
level++;
system("cls");
cout << "恭喜您突破:" << level_list[level] << endl;
Sleep(2000);
EXP = EXP % (level * level * 10);
HP += level * 10 * abiliity;
AD += level * abiliity * 10;
}
else
break;
}
if (HP + level * 10 <= level * 100)
HP += level * 10;
cout << level_list[level] << "(EXP):" << EXP << "/" << level * level * 10 << endl;
Sleep(10000 / abiliity);//资质决定修炼速度
system("cls");
}
cout << "修炼结束,当前阶级为" << level_list[level] << endl;
Sleep(3000);
}
//战斗函数
void Person::attck() {
Monster m1(level);
int flag = 0;
int tmp = 0;
system("cls");
while (HP > 0)
{
if (HP <= 0)
break;
if (m1.HP <= 0)
{
flag = 1;
break;
}
tmp = m1.hurt_method(1, m1.AD);//怪物计算伤害
HP -= tmp;
cout << "紫金翼狮王(幼崽):" << m1.HP << "生命" << endl;
tmp = hurt_method(1, AD);//角色计算伤害
m1.HP -= tmp;
cout << name << ":" << tmp << "生命"<< endl;
Sleep(2000);
system("cls");
}
if (flag)
{
cout << "你成功击败了对方" << endl;
EXP += m1.ability * level * 3;
}
else
{
cout << "你失败了" << endl;
HP = 1;
}
Sleep(3000);
}
float Person::hurt_method(int low, int high) {
srand(time(NULL));
int probability = rand() % high + low;
return AD + probability;
}
float Monster::hurt_method(int low, int high) {
srand(time(NULL));
int probability = rand() % high + low;
return AD + probability;
}
斗破苍穹游戏1.0
于 2024-12-21 10:34:42 首次发布