迷宫游戏c ++ 41 by 41阵列

时间:2017-07-18 00:02:11

标签: c++ arrays visual-studio-2017

有没有一种快速的方法来制作一个使用char的41 x 41的二维数组,似乎我花费更多的时间输入每一行并且花费很长时间然后像id一样。有什么建议。这是我到目前为止所得到的。

char board[41][41] = {
    {'+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+'},
    {'|','@','|',' ',' ',' ',' ',' ','|',' ',' ',' ','|',' ',' ',' ','|',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ',' ',' ','|',' ',' ',' ',' ',' ',' ',' ','|',' ','|'},
    {'+',' ','+','-','+','-','+',' ','+','-','+',' ','+',' ','+',' ','+',' ','+',' ','+','-','+','-','+','-','+',' ','+',' ','+',' ','+','-','+','-','+',' ','+',' ','+'},
    {'|'                                                                                                                                                        ,' ','|'},
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}                   
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}   
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'} 
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                            ,'|'}
    {'+'                                                                                                                                                            ,'+'}
    {'|'                                                                                                                                                        ,'x','|'}   
    {'+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+','-','+'}

1 个答案:

答案 0 :(得分:0)

是。肯定有更好的方法。检查for循环。

char board[40][40];
int rows = 40;
int cols = 40;

for(int r = 0; r < rows; r++) {
    for(int c = 0; c< cols; c++) {
        // Whatever logic you want to use to populate location r, c in your array
    }
}

有关迷宫生成算法的进一步阅读,请参阅https://en.wikipedia.org/wiki/Maze_generation_algorithm