我正在尝试根据我的二维数组绘制一个迷宫。它只打印在窗口顶部,没有其他地方。
#include "SDL.h"
#include "SDL_gfxPrimitives.h"
#include <conio.h>
int main( int argc, char* args[] )
{
char caMaze[20][20] = { //the array for the maze
{"###################"},
{"#+##### # #"},
{"# ## ###########"},
{"## # ##### #"},
{"## ## ####### #####"},
{"## ## ####### #####"},
{"## ## # ##"},
{"## ## ## ####"},
{"########### ## ####"},
{"#### ## ####"},
{"#### ### ##### ####"},
{"# # ## #### ####"},
{"## ## ## ### #####"},
{"## ## ## #####"},
{"## ### #### #######"},
{"## # # ######"},
{"#### #### #########"},
{"######### =#"},
{"###################"},
};
int x1 = -40;
int x2 = 0;
int y1 = -40;
int y2 = 0;
SDL_Surface *screen = NULL;
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
int loop = 0;
for(int i = 0; i < 20; i++)
{
y1 += 40;
y2 += 40;
for(int j = 0; j< 20; j++)
{
x1 += 40;
x2 += 40;
if( caMaze[i][j] == '#')
{
boxRGBA(screen, x1, y1, x2, y2, 255, 0, 0, 255);
}
if( caMaze[i][j] == ' ')
{
boxRGBA(screen, x1, y1, x2, y2, 255, 0, 255, 255);
}
if(caMaze[i][j] == '+')
{
boxRGBA(screen, x1, y1, x2, y2, 0, 0, 255, 255);
}
if (caMaze[i][j] == '=')
{
boxRGBA(screen, x1, y1, x2, y2, 0, 255, 0, 255);
}
}
}
if(SDL_Flip(screen) == -1)
{
return 1;
}
getch();
SDL_Quit();
return 0;
}