我一直在做一个简单的c ++游戏。我在制作游戏重复功能时遇到了麻烦。我想让它做这样的事情:1。输入你想做的事情2.执行选择3。显示结果4.然后从1.重复我也知道我有很多未使用的类,函数,变量等,但是因为它没有完成。(使用Code :: Blocks)
代码:
#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;
}
答案 0 :(得分:0)
主菜单中的do-while
循环,菜单()中没有while
(和test--
)?
(do-while
所以你可以选择结束显示菜单的循环至少一次)