libnds를 사용하여 C++에서 NDS를 코딩하고 있지만이 질문은 NDS 관련 사항이 아닙니다. 나는 현재 최상위 화면에 로고 만 표시하고 아래쪽 화면에서 게임하는 텍스트 기반 게임을 사용합니다.분할 화면 멀티 플레이어를 C++ 게임에 추가
그래서 한 명의 플레이어가 상단 화면에서 재생하고 다른 하나는 하단에서 재생하는 단일 DS 멀티 플레이어 유형을 추가하고 싶습니다. 두 화면 모두에서 텍스트 엔진을 설정하는 데 문제가 없습니다. 멀티 플레이어에서 효율적으로 코딩하는 방법을 찾아야합니다. 아래 나는 그것의 개요 또는 단순화 된 버전을 썼다.
참고 : consoleClear()는 화면을 지우고 게임이 멈추는 유일한 지점은 일시 중지 기능입니다.
//Headers
void display(int x,int y,const char* output))
{
printf("\x1b[%d;%dH%s", y, x,output);
}
void pause(KEYPAD_BITS key) //KEYPAD_BITS is an ENUM for a key on the NDS
{
scanKeys();
while (keysHeld() & key)
{
scanKeys();
swiWaitForVBlank();
}
while (!(keysHeld() & key))
{
scanKeys();
swiWaitForVBlank();
}
return;
}
void pause() //Only used to simplify coding
{
pause(KEY_A);
return;
}
int main(void)
{
//Initializations/Setup
while (1)
{
if (rand()%2==1) //Say Hello
{
if (rand()%3!=1) //To Friend (greater chance of friend than enemy)
{
display(6,7,"Hello Friend!");
display(6,8,"Good greetings to you.");
pause();
consoleClear(); //Clears text
display(6,7,"Would you like to come in?");
pause();
//Normally more complex complex code (such as interactions with inventories) would go here
}
else //To enemy
{
display(6,7,"Hello enemy!");
display(6,8,"I hate you!");
pause();
consoleClear();
display(6,7,"Leave my house right now!!!");
pause();
}
}
else //Say goodbye
{
if (rand()%4==1) //To Friend (lesser chance of friend than enemy)
{
display(6,7,"Goodbye Friend!");
display(6,8,"Good wishes to you.");
pause();
consoleClear();
display(6,7,"I'll see you tomorrow.");
pause();
consoleClear();
display(6,7,"Wait, I forgot to give you this present.");
pause();
}
else //To enemy
{
display(6,7,"Goodbye enemy!");
display(6,8,"I hate you!");
pause();
consoleClear();
display(6,7,"Never come back!!");
pause();
consoleClear();
display(6,7,"Good riddance!"); //I think I spelt that wrong...
pause();
}
}
}
}
나는 잡동사니가 혼란스럽고 나쁜 습관으로 여겨 질 수 있다는 것을 알고 있지만 더 좋은 방법은 없다고 생각합니다. 통합 멀티 플레이어의 내 버전 : 나쁜 관행 인이 방법에서 제외
//Headers and same functions
int game(int location)
{
switch (location)
{
case 1: goto one; break;
case 2: goto two; break;
case 3: goto three; break;
case 4: goto four; break;
case 5: goto five; break;
case 6: goto six; break;
case 7: goto seven; break;
case 8: goto eight; break;
case 9: goto nine; break;
case 10: goto ten; break;
default: break;
}
if (rand()%2==1) //Say Hello
{
if (rand()%3!=1) //To Friend (greater chance of friend than enemy)
{
display(6,7,"Hello Friend!");
display(6,8,"Good greetings to you.");
return 1;
one:;
consoleClear(); //Clears text
display(6,7,"Would you like to come in?");
return 2;
two:;
//Normally more complex complex code (such as interactions with inventories) would go here
}
else //To enemy
{
display(6,7,"Hello enemy!");
display(6,8,"I hate you!");
return 3;
three:;
consoleClear();
display(6,7,"Leave my house right now!!!");
return 4;
four:;
}
}
else //Say goodbye
{
if (rand()%4==1) //To Friend (lesser chance of friend than enemy)
{
display(6,7,"Goodbye Friend!");
display(6,8,"Good wishes to you.");
return 5;
five:;
consoleClear();
display(6,7,"I'll see you tomorrow.");
return 6;
six:;
consoleClear();
display(6,7,"Wait, I forgot to give you this present.");
return 7;
seven:;
}
else //To enemy
{
display(6,7,"Goodbye enemy!");
display(6,8,"I hate you!");
return 8;
eight:;
consoleClear();
display(6,7,"Never come back!!");
return 9;
nine:;
consoleClear();
display(6,7,"Good riddance!"); //I think I spelt that wrong...
return 10;
ten:;
}
return -1;
}
}
int main(void)
{
//Initializations/Setup
int location1 = -1, location2 = -1;
location1 = game(location1);
location2 = game(location2);
while (1)
{
scanKeys(); //Whenever checking key state this must be called
if (keysDown() & KEY_A) //A key is used to continue for player1
location1 = game(location1);
if (keysDown() & KEY_DOWN) //Down key is used to continue for player2
location2 = game(location2);
}
}
, 실제 소스 코드에서, 나는 너무 많은 시간이 소요 될 것이라고 추가해야 gotos의 수백이있다.
도움을 주시면 감사하겠습니다. 누군가 질문이나 대답이 조금이라도 있으면 질문/답장을하십시오.
편집 : 이렇게하는 것이 바람직하지 않지만 다른 사람에게 그렇게 할 방법이있는 경우 게임을 처음부터 다시 작성하려고합니다.
gotos에 대해서, 왜 기능에 공통 기능을두고, 필요할 때 전화하지? 경우처럼? * 및 *는 기본 경우입니다. –
멀티 플레이어 및 분할 화면의 문제에 관해서는 처음부터 게임을 디자인 한 경우 이러한 것들이 * 많은 * 효과가 있습니다. 예, 현재 솔루션을 손질하고 새로운 디자인으로 다시 시작하는 것이 좋습니다.이미 작동중인 솔루션에 그런 것들을 추가하는 것은 작동한다고해도 항상 나 빠질 것입니다. –
@Joachim Pileborg : 물론, 전체 게임을 처음부터 재 설계 할 의향이 있습니다. 그렇게 할 수있는 방법을 생각조차 모릅니다. 그렇게 할 수있는 방법을 찾으면 내 질문에 답할 것입니다. –