I am trying to write a program which simply reads through a multidimensional array (using 'for' loops) and if it encounters a certain letter (like 'A'), it would draw a rectangular shape (im using canvas library and functions to draw the shapes).
I'm trying to actually draw a maze-like map using canvas. But for some odd reason, it is not coming out right. I'm assuming it's a problem with reading the array, which I don't know why.
the multidimensional array read input from a text file which looks like this (a sample): This is the layout of the maze map I am attempting to create using canvas.
1 2 3 4 5 6
|
AAAAAAAAAAAAAAAAAAAAA
A.........A.........A
A.........A.........A
A...............AAAAA
AAAAA...............A
AAAAAAAAAAAAAAAAAAAAA
|
of course the 'A' will be replaced with a filled rectangle to represent the wall
the '.' represents the path.
here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
void MazeGame::DrawMap(Canvas &canvas, char (&map)[20][26])
{
double drawx = 200;
double drawy = 200;
for(int i = 0; i < 20; i++)
{
for(int j = 0; j < 26; j++)
{
if(map[i][j] == 'A')
{
canvas.DrawFillRect(drawx+10, drawy, 10, 10);
}
}
}
}
|
i wrote this function in a class.
I initialized two 'double' variables, drawx and drawy, as 200. That is considered to be the x and y origin coordinate where the shape will be drawn. Of course as the array of chars is being read, the x & y coordinate has to move accordingly to how the maze layout is displayed in the text file or else, when the shape is drawn, it would simply draw over or overwrite the previously drawn shapes. I don't want that
I feel that this is so simple but the output is really confusing me. Any suggestions?