(初学者C ++)代码无效

时间:2013-11-10 08:18:41

标签: c++

所以我有这段代码:http://pastebin.com/CSj5L1sM 我想要它做的是:每次我点击W,A,S或D英雄(“O”)在多维数组中相应移动。我不想动态修改它。只是用英雄字符串的更新位置打印一个新的。问题是我点击键(WASD)没有任何反应!它只在同一个地方用“O”打印出2d数组。请帮助我,我仍然是一个初学者,我不明白任何事情!

1 个答案:

答案 0 :(得分:0)

你的逻辑很混乱,你想要立刻做太多。分开你想要做的不同的事情。喜欢这个

void generator(){
    // set the whole area to "+"
    for(int rows=0; rows<10; rows++)
        for(int cols=0; cols<10;cols++)
            gameArea[rows][cols] = "+";
    // set the position of the hero
    gameArea[x][y] = hero;
    // print the area
    for(int rows=0; rows<10; rows++)
    {
        for(int cols=0; cols<10;cols++)
            cout << gameArea[rows][cols];
        cout << endl;
    }
}
相关问题