Skip to content

Commit

Permalink
Start reintegrating load menu with new menu system.
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanQuan committed Aug 15, 2018
1 parent c531300 commit 5de1663
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
18 changes: 17 additions & 1 deletion src/game/menu/LoadMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import game.system.input.PlayerCommand;
import game.system.output.IPrintBuffer;
import game.system.output.SemanticColor;
import game.system.save.InvalidSaveNameException;
import game.system.save.InvalidSaveNumException;
import game.system.save.Save;
Expand All @@ -17,6 +18,10 @@ public class LoadMenu extends Menu {

public static final String LOAD_GAME = "Load game";
// public static final String NEW_GAME = "New game";

/**
* Singleton instance.
*/
private static LoadMenu instance;
/**
* Enumerated order of saves
Expand Down Expand Up @@ -46,7 +51,8 @@ private LoadMenu() {
}

/**
* Process a {@link PlayerCommand} as receiveInput. This will set some corresponding output to this menu's currently set
* Process a {@link PlayerCommand} as receiveInput. This will set some
* corresponding output to this menu's currently set
* {@link IPrintBuffer}.
*
* @param playerCommand to processInput
Expand Down Expand Up @@ -85,10 +91,13 @@ public static LoadMenu getInstance() {
*/
public void printMainPrompt() {
updateSaves();
out.println(LOAD_GAME, SemanticColor.TITLE);
// printTitleln(LOAD_GAME);
String gameName;
ArrayList<Save> saves = saver.getSaves();
for (int i = 0; i < saves.size(); i++) {
out.print(i + 1, SemanticColor.PLAYER);
out.print(". ");
// printItem(i + 1);
// print(". ");
outputSaveInfo(saves.get(i));
Expand All @@ -111,6 +120,13 @@ public void printMainPrompt() {
// outputlnRoom(splitCamelCaseToString(MenuManager.getInstance().getPreviousMenu().getClass().getSimpleName()));
}
public void outputSaveInfo(Save save) {
out.println(save.getName(), SemanticColor.TITLE);
out.print("\tRoom: ", SemanticColor.LOCATION);
out.print(save.getRoom().getSingleName());
out.print("\tTurns: ", SemanticColor.ITEM);
out.print(save.getTurnCount());
out.print("\tVersion: ", SemanticColor.DIRECTION);
out.print(save.getVersion());
// println(save.getName());
// printItem(" Room: ");
// print(save.getRoom().getSingleName());
Expand Down
6 changes: 3 additions & 3 deletions src/game/menu/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ private void printTitleScreen() {

/**
*
* @param playerCommand
* to processInput
* @param playerCommand to process
*/
@Override
public void processInput(PlayerCommand playerCommand) {
Expand Down Expand Up @@ -221,7 +220,8 @@ private void startAboutThisGame() {
}

/**
* To start the game, go the load menu to choose a game to start.
* If there are already existing game saves, go to the load menu.
* Otherwise, immediately start a new game.
*/
private void startGame() {
changeTo(LoadMenu.getInstance());
Expand Down
23 changes: 12 additions & 11 deletions src/game/system/save/SaveManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
* Influence: Credits to Mkyong.com
* https://www.mkyong.com/java/how-to-write-an-object-to-file-in-java/
*/
public class SaveManager extends CollectionUtils {
public class SaveManager {
public static final int MAXIMUM_SAVES = 50;
public static final int MAX_NAME_LENGTH = 50;
public static final String SAVE_DIRECTORY = "game/system/saves";
public static final String FILE_EXTENTION = "cheese";
// public static final String FILE_NAME = "World";
public static final String[] INVALID_CHARACTERS = {"<",">",":","\"","/","\\","|","?","*"};
public static final HashSet<String> INVALID_CHARACTERS = new HashSet<>(
Set.of("<", ">",":", "\"","/", "\\","|","?","*")
);
private String saveName; // current save name
private static SaveManager instance;
private File directory;
Expand Down Expand Up @@ -83,7 +85,7 @@ public void updateSaves() {
// }
/**
* Serialize object to save file
* @param Object object to be saved
* @param object to be saved
*/
public void save(Object object) {
FileOutputStream fout = null;
Expand Down Expand Up @@ -117,9 +119,8 @@ public void save(Object object) {
}

/**
* Deserialize object from file of filename of saveNum
* @param String filename name of file to retrieve object
* @return object from file
* Deserialize object from file of filename of saveNum.
* @return object from file
*/
public Object restore() {
Object object = null;
Expand Down Expand Up @@ -239,7 +240,7 @@ public String getCurrentSaveName() {

/**
* Sets new value of currentSaveFile by save name
* @param String saveName
* @param saveName
*/
public void setCurrentSave(String saveName) throws InvalidSaveNameException {
for (String c : INVALID_CHARACTERS) {
Expand All @@ -252,7 +253,7 @@ public void setCurrentSave(String saveName) throws InvalidSaveNameException {
}
/**
* Sets values of currentSaveFile by save number
* @param int saveNum
* @param saveNum
*/
public void setCurrentSave(int saveNum) throws InvalidSaveNumException {
try {
Expand All @@ -265,15 +266,15 @@ public void setCurrentSave(int saveNum) throws InvalidSaveNumException {

/**
* Checks if save directory exists
* @return [description]
* @return true if save file exists.
*/
public boolean directoryExists() {
return directory.exists();
}

/**
* Checks if save file exists
* @return [description]
* @return true if save file exists.
*/
public boolean currentSaveFileExists() {
return currentSaveFile.exists();
Expand All @@ -293,7 +294,7 @@ public boolean currentSaveFileExists() {
//
// }

// public Address deserialzeAddressJDK7(String filename) {
// public Address deserializeAddressJDK7(String filename) {
//
// Address address = null;
//
Expand Down
1 change: 1 addition & 0 deletions src/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static String getVersion() {
*/
@SuppressWarnings("unused")
public static void main(String[] args) {
args = new String[] {"-c"}; // Debug for now
if (args.length != 1) {
help();
} else if (args[0].equals("-c")) {
Expand Down

0 comments on commit 5de1663

Please sign in to comment.