(Win32控制台应用程序)好的,所以我知道它有点看,但我添加了许多有用的评论,我可以想到,我是一些新的编码,所以如果这是一个快速解决我道歉你采取了时间,香港专业教育学院搜索高低,无法弄清楚这一点。因此,它会提示用户输入一个名称,然后用于竞赛,但是在显示功能下,它无法显示更新的统计数据(根据您选择的比赛进行更新)。虽然有时它会与hp / maxHP一起使用,但不适用于att和def。我不确定它是否与范围或什么有关,我尝试了所有我知道的:/感谢您的时间和帮助:)
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int stats[6] = {1, 10, 10, 1, 0, 0};//life(0), maxHp(1), hp(2), att(3), def(4), gold(5)
void shop();//goes to the shop
void fight();//goes to fighting area
void sleep();//refills hp
void welcome();//establishes name
void display();//hud
void whereTo();//travel selection
void doRace();//establishes name
void human();//race#1
void orc();//race#2
void dwarf();//race#3
string name;//variable for name
//Main
int main()
{
welcome();
doRace();
while(stats[0]==1)
{
whereTo();
cout << stats[1];
system("PAUSE");
}
cout << "If you are reading this, you have DIED!\n";
system("PAUSE");
return 0;
}
void shop()
{
display();
cout << "To-be shoping area.\n";
system("PAUSE");
}
void fight()
{
display();
cout << "To-be fighting area.\n";
system("PAUSE");
}
void sleep()
{
display();
cout << "You rest completely..." << endl;
stats[2] = stats[1];
system("PAUSE");
}
void whereTo()
{
display();
cout << "Where would you like to go?\n\n Shop(1)\n Fight(2)\n Sleep(3)\n";
int place;
cin >> place;
system("CLS");
if(place==1)
{
shop();
}
else if(place==2)
{
fight();
}
else if(place==3)
{
sleep();
}
else
{
cout << "Please enter 1, 2, or 3.";
system("PAUSE");
system("CLS");
whereTo();
}
}
void display()//Header to everything
{
system("CLS");
cout << name << " HP: " << stats[2] << "/" << stats[1] << " Att: " << stats[3] << " Def: " << stats[5] << " Gold:" << stats[5] << endl << endl;
}
void welcome()//runs once, establishes name in beginning
{
cout << "Welcome to my first RPG Program\n\n";
system("PAUSE");
system("CLS");
cout << "Enter your character's name\n\n";
cin >> name;
system("CLS");
}
void doRace()//choosing a race at the start
{
cout << "What Race would you like to be?\n\n\n 1)Human (More Attack and Defense)\n\n 2)Orc (More Hp and Attack)\n\n 3)Dwarf (More HP and Defense)\n\n";
int race;
cin >> race;
if(race==1)
{
human();
cout << "You chose Human!" << endl;
system("PAUSE");
}
else if(race==2)
{
orc();
cout << "You chose Orc!" << endl;
system("PAUSE");
}
else if(race==3)
{
dwarf();
cout << "You chose Dwarf!" << endl;
system("PAUSE");
}
else
{
cout << "Please enter 1, 2, or 3.";
system("pause");
system("CLS");
doRace();
}
}
void dwarf()//sets the initial stats of the character based off of race selection
{
stats[1] = stats[1] + 3;//maxHp
stats[2] = stats[2] + 3;//hp
stats[4] = stats[4] + 2;//def
}
void human()//sets the initial stats of the character based off of race selection
{
stats[3] = stats[3] + 2;//att
stats[4] = stats[4] + 2;//def
}
void orc()//sets the initial stats of the character based off of race selection
{
stats[1] = stats[1] + 3;//maxHp
stats[2] = stats[2] + 3;//hp
stats[3] = stats[3] + 2;//att
}
答案 0 :(得分:0)
你正在使用错误的def索引。它应该是4
Def: " << stats[5].