Advertisement
Guest User

stuff

a guest
Oct 25th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1.     void GameOfLife::seedBoard(string fileName) throw(csci2312::FileIOException)
  2.     {
  3.         // Open input file
  4.         ifstream inFile;
  5.         inFile.open("cells.txt");
  6.         int value;
  7.  
  8.         if(!inFile)
  9.         {
  10.             cout << "Error opening the file!" << endl;
  11.         }
  12.  
  13.         while(!inFile.eof())
  14.         {
  15.             // Loop through each row
  16.             for(int row = 0; row < boardSize / boardSize; row++)
  17.             {
  18.                 // Loop through each column
  19.                 for(int col = 0; col < boardSize; col++) //why does this work, but not "int col = 0"?
  20.                 {
  21.                     // Get a value from the file [alternatively you can place this at the top of your loop]
  22.                     inFile >> value;
  23.  
  24.                     // Set value of currentLife
  25.                     if (value == 0)
  26.                     {
  27.                         currentLife[row][col].setState(false);
  28.                     }
  29.                     else if(value == 1)
  30.                     {
  31.                         currentLife[row][col].setState(true);
  32.                     }
  33.  
  34.                     // Output row/column value
  35.                     cout << value;
  36.                 }
  37.  
  38.                 // End line after all cells in the row are displayed
  39.                 cout << '\n';
  40.             }
  41.         }
  42.         inFile.close();
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement