-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)示例,該示例再現了您的問題,以及您在調試器。 –