【发布时间】:2020-08-07 06:45:05
【问题描述】:
这里有点像一个完整的初学者。
我是从 C++ 开始,并且是一般编程,所以,我正在尝试为文本 RPG 格斗游戏制作一个粗略的菜单,以练习条件。
但是,这些值不会自行更新。代码如下:
int main() {
cout << "Wild Ogre attacked!" << endl << endl;
int ogreHP = 350;
int HP = 100;
int Stamina = 100;
int Magicka = 100;
while (ogreHP > 1) {
cout << "HP: " << HP << endl;
cout << "Stamina: " << Stamina << endl;
cout << "Magicka: " << Magicka << endl << endl;
cout << "Ogre HP: " << ogreHP << endl << endl;
cout << "What are you going to do? " << endl;
cout << "1.\tAttack." << endl;
cout << "2.\tMagicka." << endl;
cout << "3.\tTactics." << endl;
cout << "4.\tBag." << endl;
cout << "5.\tRun." << endl;
int menu_input;
cin >> menu_input;
switch (menu_input) {
case 1: {
cout << "1.\tLight Attack." << endl;
cout << "\t\tDeals 5 points of damage. No Stamina cost." << endl << endl;
cout << "2.\tHeavy Attack" << endl;
cout << "\t\tDeals 20 points of damage. Stamina Cost of 10 points." << endl << endl;
int att_input;
cin >> att_input;
switch (att_input) {
case 1: {
cout << "You dealt 5 points of damage!" << endl << endl;
ogreHP= - 5;
break;
}
case 2: {
cout << "You dealt 20 points of damage!" << endl << endl;
Stamina= - 10;
ogreHP= - 20;
break;
}
提前致谢!
【问题讨论】:
-
你知道调试器是什么吗?哪些值没有更新?请更具体,并尝试使用您的代码的较小示例,其中您的问题仍然存在。谢谢
-
您的代码似乎不完整,请指定未“更新”的值。
-
你关于减少健康和耐力的语法是错误的。您正在设置实际值而不是减少。当您想将变量减少一定数量时,请使用
-=
标签: c++ int switch-statement