-2
我一直在做一个简单的C++游戏。我在制作游戏重复函数时遇到了麻烦。我想让它做这样的事情:1.输入你想要做的事情2.执行选择3.显示结果4.然后重复1.也知道我有很多未使用的类,函数,变量等,但是因为它没有完成。(使用Code :: Blocks)麻烦循环.C++简单游戏
代码:
#include <iostream>
#include <conio.h>
using namespace std;
int main();
//variables
const int X = 0;
const int Y = 10;
const int Z = 0;
int X1 = X;
int Y1 = Y;
int Z1 = Z;
int Input;
int Input2;
int test = 1;
int Menu()
{
while (test == 1) {
test--;
cout << "Please type what you want to do." << endl;
cin >> Input;
}
return Input;
//deciding what they want to do.
}
int Calculating()
{
//Calculating Function(Unused)
}
class Player {
public:
void Movement()
{
//the loop that activates when the Input == 1
cout << "2 - Move" << endl;
do {
cin >> Input2;
int test = 1;
Menu();
} while (Input2 < 3 && Input2 > 1);
switch (Input2) {
case 1:
cout << "You moved" << endl;
}
}
void Attack()
{
//the loop that activates when the Input == 2
cout << "1 - Sword Dance" << endl;
do {
cin >> Input2;
int test = 1;
Menu();
} while (Input2 < 3 && Input2 > 1);
switch (Input2) {
case 1:
cout << "DMG" << endl;
break;
}
}
};
class Enemy {
//Enemy class(Unused)
};
int main()
{
Input = Menu();
Player Pl;
//if the chosen number was 1 it will make the Player move.
//if the chosen number was 2 it will make the Player attack.
if (Input == 1) {
Pl.Movement();
}
else if (Input == 2) {
Pl.Attack();
}
Menu();
//calling the Menu function
return 0;
}
解决这类问题是你的调试器的工具。在*堆栈溢出问题之前,您应该逐行执行您的代码。如需更多帮助,请阅读[如何调试小程序(由Eric Lippert撰写)](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。至少,您应该\编辑您的问题,以包含一个[最小,完整和可验证](http://stackoverflow.com/help/mcve)示例,该示例再现了您的问题,以及您在调试器。 –