#include<iostream>
using namespace std;
#include<string>
#define MAX 6
//设计游戏角色结构体
struct Hero {string name;int gongji;int fangyu;int tili;int tianfu;
};
//设计仓库结构体
struct WareHouse {struct Hero array[MAX];int m_size;
};//1.添加全部游戏角色
void addHero(WareHouse*A526) {//判断仓库是否已满if (A526->m_size > MAX) {cout << "当前仓库游戏角色已满,请开通VIP进行扩容" << endl;}else {//添加游戏角色//姓名string name;cout << "请输入游戏角色名称:";cin >> name;A526->array[A526->m_size].name = name;cout << endl;//攻击int gongji;cout << "请输入游戏角色攻击力:";cin >> gongji;A526->array[A526->m_size].gongji = gongji;cout << endl;//防御int fangyu;cout << "请输入游戏角色防御力:";cin >> fangyu;A526->array[A526->m_size].fangyu = fangyu;cout << endl;//体力int tili;cout << "请输入游戏角色体力值:";cin >> tili;A526->array[A526->m_size].tili = tili;cout << endl;//天赋int tianfu;cout << "请输入游戏角色天赋值:";cin >> tianfu;A526->array[A526->m_size].tianfu = tianfu;cout << endl;}A526->m_size++;system("pause");system("cls");
}//判断英雄角色是否存在
int isExistHero(WareHouse* A526, string name) {for (int i = 0; i < A526->m_size; i++) {if ( A526->array[i].name == name) {return i;}}return -1;system("pause");system("cls");
}//2.显示所有游戏角色信息
void showHero(WareHouse* A526) {//判断游戏仓库是否为空if (A526->m_size == 0) {cout << "当前仓库为空" << endl;}else {for (int i = 0; i < A526->m_size; i++) {cout << "角色名称:" << A526->array[i].name << "\t";cout << "攻击值:" << A526->array[i].gongji << "\t";cout << "防御值:" << A526->array[i].fangyu << "\t";cout << "体力值:" << A526->array[i].tili << "\t";cout << "天赋值:" << A526->array[i].tianfu << endl;}}system("pause");system("cls");
}//3.修改游戏角色信息
void modifyHero(WareHouse* A526) {//判断游戏角色是否存在string name;cout << "请输入您要修改的角色信息" << endl;cin >> name;int ret = isExistHero(A526, name);if (ret != -1) {// 修改姓名string name;cout << "请输入游戏角色新名称:";cin >> name;A526->array[ret].name = name;cout << endl;//修改攻击int gongji;cout << "请输入游戏角色新攻击力:";cin >> gongji;A526->array[ret].gongji = gongji;cout << endl;//修改防御int fangyu;cout << "请输入游戏角色新防御力:";cin >> fangyu;A526->array[ret].fangyu = fangyu;cout << endl;//修改体力int tili;cout << "请输入游戏角色新体力值:";cin >> tili;A526->array[ret].tili = tili;cout << endl;//修改天赋int tianfu;cout << "请输入游戏角色新天赋值:";cin >> tianfu;A526->array[ret].tianfu = tianfu;cout << endl;}else {cout << "当前角色不存在,请重新输入:";}system("pause");system("cls");
}//4.查询游戏角色
void findHero(WareHouse* A526) {cout << "请输入您要查询的游戏角色:";string name;cin >> name;int ret = isExistHero(A526, name);if (ret != -1) {cout << "角色名称:" << A526->array[ret].name << "\t";cout << "攻击值:" << A526->array[ret].gongji << "\t";cout << "防御值:" << A526->array[ret].fangyu << "\t";cout << "体力值:" << A526->array[ret].tili << "\t";cout << "天赋值:" << A526->array[ret].tianfu << endl;}else {cout << "当前游戏角色不存在" << endl;}system("pause");system("cls");
}//5.删除游戏角色
void deleteHero(WareHouse* A526) {cout << "请输入您要删除的游戏角色:";string name;cin >> name;int ret = isExistHero(A526, name);if (ret != -1) {//删除操作for (int i = ret; i < A526->m_size; i++) {A526->array[i] = A526->array[i + 1];}//更新仓库英雄数量A526->m_size--;cout << "删除成功" << endl;}else {cout << "当前游戏角色不存在" << endl;}system("pause");system("cls");
}//主菜单
void showmenu() {cout << "--------------------------------" << endl;cout << "-------1.添加全部角色信息-------" << endl;cout << "-------2.查看游戏角色信息-------" << endl;cout << "-------3.修改游戏角色信息-------" << endl;cout << "-------4.查找游戏角色信息-------" << endl;cout << "-------5.删除游戏角色信息-------" << endl;cout << "-------6.退出游戏角色仓库-------" << endl;cout << "--------------------------------" << endl;
}int main() {//创建游戏角色仓库WareHouse A526;//初始化仓库游戏角色数量A526.m_size = 0;int select = 0;while (1) {showmenu();cout << "请输入您的选择:" << endl;cin >> select;switch (select) {//添加全部角色信息case 1: addHero(&A526);break;//查看游戏角色信息case 2: showHero(&A526);break;//修改游戏角色信息case 3: modifyHero(&A526);break;//查找游戏角色信息case 4: findHero(&A526);break;//删除游戏角色信息case 5: deleteHero(&A526);break;//退出游戏角色仓库case 6:cout << "主人,欢迎下次光临!" << endl;system("pause");return 0;break;default:system("pause");break;}}
}