Skip to content

Commit

Permalink
Merge pull request #228 from Exprescode/master
Browse files Browse the repository at this point in the history
Display game save location.
  • Loading branch information
Exprescode authored Oct 31, 2019
2 parents 90ebd81 + 04feee6 commit b9ef7a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/main/java/commands/CommandGameSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public class CommandGameSave extends Command {
@Override
public void execute(Farmio farmio) throws FarmioFatalException {
Ui ui = farmio.getUi();
if (farmio.getStorage().storeFarmerPartial(farmio.getFarmer())) {
String location = farmio.getStorage().storeFarmerPartial(farmio.getFarmer());
if (location != null) {
farmio.getSimulation().simulate();
ui.show("Game saved successfully!");
ui.show("Game saved successfully!\nGame save location:\n" + location);
} else {
farmio.getSimulation().simulate();
ui.show("Game save failed!! Try again later.");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/farmio/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public boolean storeFarmer(Farmer farmer) {
* @param farmer Farmer instance to be updated to from json data.
* @return True if save is successful.
*/
public boolean storeFarmerPartial(Farmer farmer) {
public String storeFarmerPartial(Farmer farmer) {
if(jsonFarmer == null){
return false;
return null;
}
FileWriter file;
try {
Expand All @@ -110,9 +110,9 @@ public boolean storeFarmerPartial(Farmer farmer) {
file.write(jsonFarmer.toJSONString());
file.close();
} catch (IOException e) {
return false;
return null;
}
return true;
return appDir.concat(jsonName);
}

/**
Expand Down

0 comments on commit b9ef7a1

Please sign in to comment.