Misplaced Squares

I am trying to have a collection of numbers transfer from a text file into a map inside of the program.

I am assigning the color green to the number 0. The text file looks as follows:

7777777
7000007
7000007
7770777
7000007
7000007
7777777


As you can see, theoretically, the inside should be filled with green, but what is actually displaying onto the screen look like this:

7777777
7000077
7000077
7000077
7777777
7777777
7777777


I have no idea why, but here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
    for (int j = 0; j < rows; j++) { //Sorts through the map vector to assign the correct values to it from the text file.
        fgets(Line, 50, Import);
        for (int i = 0; i < columns; i++) {
            MapArr[i][j] = Line[i];
            if (MapArr[i][j] == 48) { // If the current vector position contains the number '0', create a green rectangle at that spot on the map and put it in a vector.
                Rect = sf::Shape::Rectangle(i*50, j*50, 50, 50, sf::Color::Green);
                
                DispMapArr.push_back(Rect);
            }
            cout << MapArr[i][j]; // Displays the theoretical map.
        }
        cout << "\n";
    }
You show two different patterns up there, which says something got read in wrong.

I don't know is what is the definition of MapArr.
1
2
3
4
5
6
7
//I assume maparr
char MapArr[50] [50]; // or something similar

MapArr[i][j] = line[i];

// should be, should change the orientation of the output map. 
MapArr[j][i] = line[i];


If I wanted to figure this out I would dump the line I read in, to make sure it came in right. The other thing I would make sure of is was accounting for other text features in the file, since I am reading it in as binary and looping with an index.
Last edited on
The orientation is already correct though. I have a little blue square set to move on the 0's (or 48 in ASCII). It moves perfectly on the right tiles.

The only problem is that the program isn't printing the green tiles in the right place. The green tiles are supposed to print on the 0's, but they are printing in a little square in the corner as the illustration in my first post shows. There are no values there to make them be there. It's really weird.
But is the cout correct?

Not sure, but I think that the coordinates of the shape are absolute.
1
2
if (MapArr[i][j] == '0') { // Now this comment is superfluous
  Rect = sf::Shape::Rectangle(i*50, j*50, (i+1)*50, (j+1)*50, sf::Color::Green);

If you multiply (i+1) and (j+1) by 50 then the size of the squares is just going to get bigger and bigger as I and j get bigger.

EDIT: I have an example of what I'm trying to say if you want to get on Skype.
Last edited on
Holy Crap!! How did you know to do that?!?! That worked! I am so sorry for doubting you. LOL
Topic archived. No new replies allowed.