2013-10-27 1 views
0

안녕하세요. 저는 텍스트 기반 RPG 게임을 만드는 방법을 배우고 있으며 오류가 발생했습니다. 그래서 문제는 그 단지 기능 titleFunc();하지 if (playerLocation == 1) 문을 시작합니다 나는 playerLocation 2 가서 내가 다시 playerLocation 1에 가고 싶어 할 때의 말을하자입니다C++ 내 게임 영역을 전환하는 데 낀다

#include <iostream> 
using namespace std; 

void newGameFunc(); 
void titleFunc(); 
int userInput = 0; 
int playerInfo[2]; 
int playerLocation = 0; 


bool running = 1; 

int main() { 
    while (running) { 
     titleFunc(); 
     if (playerLocation == 1) { 
      cout << "You are standing in the middle of a forest. A path veers off to the East and to the West.\n"; 
      cout << " 1: Go East\n 2: Go West\n"; 
      cin >> userInput; 

      if (userInput == 1) playerLocation = 2; //East 
      else if (userInput == 2) playerLocation = 3; //West 
     } 
     if (playerLocation == 2) { 
      cout << "You are in the Eastern edge of the forest. It's heavilly forested and it's almost imposible to navigate through. You do find 2 flags though.\n"; 
      cout << " 1: Turn Back\n 2: Pick the FLAG.\n"; 
      cin >> userInput; 

      if (userInput == 1) playerLocation = 1; //Start 
      if (userInput == 2) running = 0; 
     } 
     if (playerLocation == 3) { 
      cout << "There is a passage way that leads to a town in the seemingly distant town. There are two guards with shining metal chainmail which scales look as magistic as reptilian scales. Their logo resembles a black dragon spewing a string of fire. They tell you that in order to pass you must give them their lost flags.\n"; 
      cout << " 1: Give the flags to both guards.\n 2: Turn around.\n 3: Bribe them--NOT AVAILABLE.)\n"; 
     } 
    } 
    return 0; 
} 

void titleFunc() { 
    cout << "\t\t\t\t---Fantasee---\n\n\n"; 
    cout << "\t\t\t\t 1: Play\n"; 
    cin >> userInput; 

    if (userInput == 1) { 
     newGameFunc(); 
    } 
    else { 
     running = 0; 
    } 
    return; 
} 

void newGameFunc() { 
    cout << "Welcome to Fantasee, a world of adventure and danger.\n"; 
    cout << "Since you are a new hero, why don't you tell me a little about yourself?\n"; 
    cout << "For starters, are you a boy or a girl?\n 1: Boy\n 2: Girl\n"; 
    cin >> userInput; 
    playerInfo[0] = userInput; 

    cout << "And what kind of person are you?\n 1: Warrior\n 2: Archer\n 3: All-rounder\n"; 
    cin >> userInput; 
    playerInfo[1] = userInput; 
    playerLocation = 1; 
    system("cls"); 
    return; 
} 

: 그래서 먼저 여기 내 코드입니다.

int main() { 
    while (running) { 
     titleFunc(); 
     ... 

로 :

int main() { 
    titleFunc(); 
    while (running) { 
     ... 

방법 당신이 지금 그 일을하는 당신의 모든 반복에 titleFunc()을 계속 실행

+0

언제'titleFunc()'를 호출해야하는지 설명해야합니다. – SJuan76

+0

@ SJuan76 그럼 한번만 실행해야한다고 설명하려면 어떻게해야합니까? 게임을 처음로드 할 때. –

+1

루프 밖 (** while 문)에 넣으십시오. – SJuan76

답변

2

당신은 아마 while 루프 전에 titleFunc()을 넣고 싶을 것이다 루프를 사용하여 게임을 리셋하십시오.

+0

왜 나는 그것을 알아 채지 못할 정도로 어리 석 었는가? 감사. –

관련 문제