Skip to content

Commit cdba1fe

Browse files
committed
Added check if file exists
1 parent 4394f49 commit cdba1fe

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@
4040
# debug information files
4141
*.dwo
4242

43+
# Save Files
44+
*.csv
45+
4346
# build directory
4447
build/

monopoly.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,16 +1310,23 @@ bool lastManStanding(){
13101310
return activePlayers == 1;
13111311
}
13121312

1313+
bool fileExists(const std::string& name) {
1314+
std::ifstream f(name);
1315+
return f.is_open();
1316+
}
1317+
13131318
// Main function to initialize and run the Monopoly game loop
13141319
int main(){
13151320
int sel;
13161321
// Initialize Gameboard
1317-
std::cout<<"Do you want to load last saved game?\n"
1318-
<<"┌────────┬────────┐\n"
1319-
<<"│ 1: YES │ 0: NO │\n"
1320-
<<"└────────┴────────┘\n"
1321-
<<std::endl;
1322-
std::cin>>sel;
1322+
if (fileExists("Tiles.csv") && fileExists("Players.csv") && fileExists("OwnedStreets.csv") && fileExists("otherData.csv")) {
1323+
std::cout<<"Do you want to load last saved game?\n"
1324+
<<"┌────────┬────────┐\n"
1325+
<<"│ 1: YES │ 0: NO │\n"
1326+
<<"└────────┴────────┘\n"
1327+
<<std::endl;
1328+
std::cin>>sel;
1329+
} else { sel = 0; }
13231330
if(sel == 1 && std::cin.good()){
13241331
importFile(gameBoard);
13251332
importFile(players);

0 commit comments

Comments
 (0)