Hello everyone! I have a slight problem:
I have a file called "testfile.txt" and inside is a line:
TR01[100,300,1] TR01[130,310,1] TR01[300,300,1]
Above is an example of a TREES placed at the xy coordinates and lastly the collision flag, which is TRUE in all of the cases. [x,y,collision]
I'm making a game and this is how objects are placed on the map.
---------
It was fairly easy to read a 2D array from a file (for tilemap), but this is making me insane.
I want to store all the objects into a vector.
It should also continue reading the file to find all the objects (When there comes a whitespace, it should know there's the next object).
My mind is blank atm and i have no clue how to do that.
Heres my test code so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <fstream>
using namespace std;
int main(int argc, char **argv){
int state = 0;
enum { Object,x,y,Collision };
string fileInfo;
string helper;
ifstream file("testfile.txt");
if(!file.is_open())
cout << "Could not load file \n\n";
while(!file.eof())
{
getline(file, fileInfo);
if(fileInfo.find("[") != string::npos)
{
state = Object;
continue;
}
} //!file.eof
switch(state)
{
case Object:
{
stringstream fileStr(fileInfo);
while(!fileStr.eof())
{
// ------------- //
// What to do? - //
// ------------- //
}
break;
}
}//switch
cout << "\n\n";
system("PAUSE");
file.close();
return 0;
}
|
Help needed, please :)!