@@ -10,56 +10,52 @@ GameBoard::~GameBoard() {
1010
1111
1212int GameBoard::save_Board (std::string filename){
13- std::ofstream * file = new std::ofstream ;
14- file-> exceptions (std::ofstream::failbit | std::ofstream::badbit);
13+ std::ofstream file;
14+ file. exceptions (std::ofstream::failbit | std::ofstream::badbit);
1515 try {
1616 filename = filename + " .wocs" ;
17- file-> open (filename.c_str ());
17+ file. open (filename.c_str ());
1818 constructFileFromBoard (file);
19- file->close ();
20- delete (file);
19+ file.close ();
2120 return 0 ;
2221 } catch (std::ofstream::failure e) {
2322 std::cerr << " Exception opening/closing/writing file: " << e.what ();
24- delete (file);
2523 }
2624 return -1 ;
2725
2826}
2927
3028int GameBoard::load_Board (std::string filename){
31- std::ifstream * file = new std::ifstream ;
29+ std::ifstream file;
3230 try {
3331 filename = filename + " .wocs" ;
34- file-> open (filename.c_str ());
32+ file. open (filename.c_str ());
3533 constructBoardFromFile (file);
36- file->close ();
37- delete (file);
34+ file.close ();
3835 return 0 ;
3936 } catch (std::ifstream::failure e) {
4037 std::cerr << " Exception opening/closing/reading file: " << e.what ();
41- delete (file);
4238 }
4339 return -1 ;
4440}
4541
46- int GameBoard::constructBoardFromFile (std::ifstream * file){
42+ int GameBoard::constructBoardFromFile (std::ifstream & file){
4743 // Parse and construct the board from the file
4844 // @ TODO
4945 std::string line;
50- if (file-> is_open ()) {
51- while (getline (* file, line)) {
46+ if (file. is_open ()) {
47+ while (getline (file, line)) {
5248 std::cout << line << ' \n ' ;
5349 }
5450 }
5551 return 0 ;
5652}
5753
5854
59- int GameBoard::constructFileFromBoard (std::ofstream * file){
55+ int GameBoard::constructFileFromBoard (std::ofstream & file){
6056 // Construct the file based on the structure of the board
6157 // @ TODO
62- * file << " Hello World!" ;
58+ file << " Hello World!" ;
6359 return 0 ;
6460}
6561
0 commit comments