C++: Writing game program...Rogue-Like?

Printable View

• 12-06-2012
rvbplayer123
C++: Writing game program...Rogue-Like? Import x,y Cords
I'm writing a rogue like game for my cs class. Everything is running fine but I need to import the walls for the game. The coordinates for the walls are in 3 text files. How do I inport it to the correct position on screen.
This is the code i'm using but it isn't printing right on the screen.
Can you look over? Thank you!

Code:

```bool loadData( int coordinates[MAX_ARRAY][MAX_ARRAY], int fileIndex, int &arraySize ) { char fileOne[] = "lowlevel.txt"; char fileTwo[] = "midlevel.txt"; char fileThree[] = "highlevel.txt"; ifstream fin; if ( fileIndex == 1 )     {       fin.clear();       fin.open( fileOne );     } else if( fileIndex == 2 )     {       fin.clear();       fin.open( fileTwo );     } else if( fileIndex == 3)   {       fin.clear();       fin.open( fileThree );   } else     return false; while ( fin.good() && arraySize < 100 )     {       fin >> coordinates[arraySize][arraySize];       arraySize++;       fin >> coordinates[arraySize][arraySize];       arraySize++;     }     fin.close(); return true; }```

• 12-06-2012
Lesshardtofind
Hey,

The way you are navigating through your array looks linear. Like you are saving data in a straight line such as on a graph would be y = x.

It looks like you are only saving into positions that would satisfy the equaion Y = X. So points (0, 0), (1, 1), (2, 2) ect. If it is a array that is 100, by 100 then you have 1000 possible positions but you are writing to only 100 of them.