@@ -8,52 +8,58 @@ GameBoard::~GameBoard() {
88
99}
1010
11- int GameBoard::saveBoardToFile (std::string filename){
12- std::ofstream file;
13- file.exceptions (std::ofstream::failbit | std::ofstream::badbit);
11+
12+ int GameBoard::save_Board (std::string filename){
13+ std::ofstream * file = new std::ofstream;
14+ file->exceptions (std::ofstream::failbit | std::ofstream::badbit);
1415 try {
1516 filename = filename + " .wocs" ;
16- file. open (filename.c_str (), std::fstream::out | std::fstream::trunc );
17+ file-> open (filename.c_str ());
1718 constructFileFromBoard (file);
18-
19- } catch (std::ofstream::failure e){
20- std::cerr << " Exception opening/reading/closing file \n " ;
19+ file->close ();
20+ delete (file);
21+ return 0 ;
22+ } catch (std::ofstream::failure e) {
23+ std::cerr << " Exception opening/closing/writing file: " << e.what ();
24+ delete (file);
2125 }
26+ return -1 ;
2227
23-
24-
25- return 0 ;
2628}
2729
28- int GameBoard::loadBoardFromFile (std::string filename){
29- std::ifstream file;
30- file.exceptions (std::ifstream::failbit | std::ifstream::badbit);
30+ int GameBoard::load_Board (std::string filename){
31+ std::ifstream * file = new std::ifstream;
3132 try {
3233 filename = filename + " .wocs" ;
33- file. open (filename.c_str (), std::fstream::in );
34+ file-> open (filename.c_str ());
3435 constructBoardFromFile (file);
35-
36- file.close ();
36+ file->close ();
37+ delete (file);
38+ return 0 ;
3739 } catch (std::ifstream::failure e) {
38- std::cerr << " Exception opening/reading/closing file\n " ;
40+ std::cerr << " Exception opening/closing/reading file: " << e.what ();
41+ delete (file);
3942 }
40- return 0 ;
43+ return - 1 ;
4144}
4245
43- int GameBoard::constructBoardFromFile (std::ifstream & file){
46+ int GameBoard::constructBoardFromFile (std::ifstream * file){
4447 // Parse and construct the board from the file
4548 // @ TODO
46- while (!file.eof ()) {
47- std::cout << file.get ();
49+ std::string line;
50+ if (file->is_open ()) {
51+ while (getline (*file, line)) {
52+ std::cout << line << ' \n ' ;
53+ }
4854 }
4955 return 0 ;
5056}
5157
5258
53- int GameBoard::constructFileFromBoard (std::ofstream & file){
59+ int GameBoard::constructFileFromBoard (std::ofstream * file){
5460 // Construct the file based on the structure of the board
5561 // @ TODO
56- file << " Hello World!" ;
62+ * file << " Hello World!" ;
5763 return 0 ;
5864}
5965
0 commit comments