SHARE
TWEET

Untitled

a guest Apr 25th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 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[])
  2. {
  3.     //create a array for the extention
  4.     char ext[10];
  5.     char support[2][10] = { ".sim1", ".sim2" };
  6.  
  7.     char determine;
  8.  
  9.     //creates temp names for width and height
  10.     int width1, height1;
  11.  
  12.     //create a variable to hold file type
  13.     ///sim1 or sim2
  14.     int sim_type;
  15.  
  16.     ifstream fin;
  17.  
  18.     //check to see if the file extention is supported and determine if the file is sim1 or sim2
  19.     get_extension(test_name, ext);
  20.     //is it sim1?
  21.     if (strcmp(ext, support[0]) == 0)
  22.     {
  23.         sim_type = 1;
  24.     }
  25.     //is it sim2?
  26.     else if (strcmp(ext, support[1]) == 0)
  27.     {
  28.         sim_type = 2;
  29.     }
  30.     //if neither, end
  31.     else
  32.     {
  33.         cout << "File type not supported." << endl;
  34.         return false;
  35.     }
  36.  
  37.     //open the file
  38.     fin.open(test_name);
  39.  
  40.     //check to see if the file opened
  41.     if (!fin)
  42.     {
  43.         cout << test_name << " could not be loaded." << endl;
  44.         return false;
  45.     }
  46.  
  47.     //gets the file name
  48.     fin.getline(filename, 999);
  49.  
  50.     //gets the length and width from the file
  51.     fin >> width1;
  52.     fin >> height1;
  53.  
  54.     //check to see if the height and width are in the range
  55.     if (width1 < 2 || width1 > 50 || height1 < 2 || height1 > 50)
  56.     {
  57.         //cout range error
  58.         cout << RANGE_ERR << endl;
  59.         cout << "Size must be between 2 and 50" << endl;
  60.         //close the file
  61.         fin.close();
  62.         //return false
  63.         return false;
  64.     }
  65.  
  66.     //copy temp data over to permanent vairables
  67.     width = width1;
  68.     height = height1;
  69.  
  70.  
  71.     //fills the array
  72.     for (int h = 0; h < height; h++)
  73.     {
  74.         for (int w = 0; w < width; w++)
  75.         {
  76.             //load based on sim1 type
  77.             if (sim_type == 1)
  78.             {
  79.                 fin >> b_map[h][w];
  80.                 f_map[h][w] = b_map[h][w];
  81.                 c_map[h][w] = ' ';
  82.             }
  83.  
  84.             //load based on sim2 type
  85.             if (sim_type == 2)
  86.             {
  87.                 fin >> b_map[h][w];
  88.                 fin >> f_map[h][w];
  89.                 fin >> determine;
  90.                 if (determine == '_')
  91.                 {
  92.                     c_map[h][w] == ' ';
  93.                 }
  94.                 else
  95.                 {
  96.                     c_map[h][w] = determine;
  97.                 }
  98.             }
  99.         }
  100.     }
  101.  
  102.     //close the file
  103.     fin.close();
  104.  
  105.     //return true that the function succeeded
  106.     return true;
  107.  
  108. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top