2016-12-16 3 views
-2

私はシンプルなC++のゲームに取り組んできました。ゲームを繰り返すのに問題があります。このようなことをしたいです:1.あなたがしたいことを入力してください2.Execute the choise 3.Display Results 4.Thenから繰り返します。私は未使用のクラス、関数、変数などがたくさんあることを知っていますが、それは完了していないためです。(コード::ブロックの使用)ループのトラブル.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; 
} 
+0

、このような問題を解決するための適切なツールは、あなたのデバッガです。スタックオーバーフローを尋ねる前に、コードを一行ずつ進める必要があります。詳しいヘルプは、[小さなプログラムをデバッグする方法(Eric Lippert)](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)を参照してください。最低限、問題を再現する[最小、完全、および検証可能](http://stackoverflow.com/help/mcve)の例と、その問題を再現するためのデバッガ。 –

答えて

0

メインでdo-whileループ、メニューのwhile(およびtest--)()?

do-whileあなたがメニューに少なくとも1時間を表示するループを終了することを選択できます)

関連する問題