Text-Galaga:连续文本游戏循环和控制角色

时间:2015-03-06 06:27:22

标签: c++ xcode macos loops text

只是为了好玩而且可能是我的计算机科学课程的一个项目,我正在制作一个基于文本的" Galaga"游戏。你的角色是">"并且敌人是"<"激光是"〜"或者" - ",点是,它非常简单。 600-700行代码。问题是,你必须输入一些东西让代码循环。我使用了系统(" stty raw"),因此我不必按Enter键,但当你停止按住按钮时游戏停止。我想让它成为一个真正的连续游戏,它只是由文本构成的。有什么方法可以实现这一点,同时还能够使用WASD动作正确控制角色的移动?我也在macbook上使用Xcode,如果有帮助的话。这只是主要功能的一部分,仅适用于某些环境:

int main()
{   
cout<<" ██████╗  █████╗ ██╗      █████╗  ██████╗  █████╗ "<<endl;
cout<<"██╔════╝ ██╔══██╗██║     ██╔══██╗██╔════╝ ██╔══██╗"<<endl;
cout<<"██║  ███╗███████║██║     ███████║██║  ███╗███████║"<<endl;
cout<<"██║   ██║██╔══██║██║     ██╔══██║██║   ██║██╔══██║"<<endl;
cout<<"╚██████╔╝██║  ██║███████╗██║  ██║╚██████╔╝██║  ██║"<<endl;
cout<<" ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═╝ "<<endl;

cout<<endl<<endl;

cout<<"Welcome to text-galaga!"<<endl;
cout<<"_________________________"<<endl;
cout<<"Use W to move forward,"<<endl;
cout<<"A to move left, S to move back,"<<endl;
cout<<"D to move right, and J to shoot"<<endl;
cout<<"_________________________"<<endl;

cout<<"Good luck!"<<endl<<endl;
cout<< "Enter any key to begin..."<<endl;
cin>>x;

// Set terminal to raw mode
system("stty raw");

char input ='c';
int height=10,wide=5;
int turns=0;
int num_destroyed=0;

// ACTUAL MAIN GAME OPERATIONS START HERE...

while((input!='Q'&& input!='q') && (num_destroyed<5) && dead==false)
{
    // Wait for single character
    input = getchar();
    int i=0;
    int j=0;

    get_inputs(i, j, bad);

    render(i, j, height, wide, input, destroyed, dead, bad, turns, shot,
           constant_height, constant_wide, shot_distance, next, num_destroyed);

    draw(height, wide, j, i, destroyed, dead, bad, shot_distance, shot,
         constant_height, constant_wide);

    if ((num_destroyed<5) && dead==false)
        cout<<endl<<endl;
    ++turns;
}

// Reset terminal to normal "cooked" mode
system("stty cooked");

// Game End Information
if (num_destroyed==5)
{
    cout<<"Congradulations! You win!"<<endl<<endl;
}
if (dead==true)
{
    cout<<"You died. Game Over."<<endl<<endl;
}
cout<<"Frames used: "<<turns<<endl;

return 0;
// AND END HERE...
}

无论如何,我知道我应该放&#34;而(真实)&#34;并取出&#34; getchar()&#34;一旦我把剩下的事情搞清楚了,但仅凭这一点似乎并没有让它成为一个充满文本的游戏。无论如何,抱歉长篇大论。谢谢你们。

0 个答案:

没有答案