Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool load_file(char filename[], int b_map[][50], int f_map[50][50], char c_map[50][50], int &width, int &height, char test_name[])
- {
- //create a array for the extention
- char ext[10];
- char support[2][10] = { ".sim1", ".sim2" };
- char determine;
- //creates temp names for width and height
- int width1, height1;
- //create a variable to hold file type
- ///sim1 or sim2
- int sim_type;
- ifstream fin;
- //check to see if the file extention is supported and determine if the file is sim1 or sim2
- get_extension(test_name, ext);
- //is it sim1?
- if (strcmp(ext, support[0]) == 0)
- {
- sim_type = 1;
- }
- //is it sim2?
- else if (strcmp(ext, support[1]) == 0)
- {
- sim_type = 2;
- }
- //if neither, end
- else
- {
- cout << "File type not supported." << endl;
- return false;
- }
- //open the file
- fin.open(test_name);
- //check to see if the file opened
- if (!fin)
- {
- cout << test_name << " could not be loaded." << endl;
- return false;
- }
- //gets the file name
- fin.getline(filename, 999);
- //gets the length and width from the file
- fin >> width1;
- fin >> height1;
- //check to see if the height and width are in the range
- if (width1 < 2 || width1 > 50 || height1 < 2 || height1 > 50)
- {
- //cout range error
- cout << RANGE_ERR << endl;
- cout << "Size must be between 2 and 50" << endl;
- //close the file
- fin.close();
- //return false
- return false;
- }
- //copy temp data over to permanent vairables
- width = width1;
- height = height1;
- //fills the array
- for (int h = 0; h < height; h++)
- {
- for (int w = 0; w < width; w++)
- {
- //load based on sim1 type
- if (sim_type == 1)
- {
- fin >> b_map[h][w];
- f_map[h][w] = b_map[h][w];
- c_map[h][w] = ' ';
- }
- //load based on sim2 type
- if (sim_type == 2)
- {
- fin >> b_map[h][w];
- fin >> f_map[h][w];
- fin >> determine;
- if (determine == '_')
- {
- c_map[h][w] == ' ';
- }
- else
- {
- c_map[h][w] = determine;
- }
- }
- }
- }
- //close the file
- fin.close();
- //return true that the function succeeded
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement