Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy character more explicit, customise character #66

Merged
merged 1 commit into from
Jul 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bobbin/constants/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public int respondToInteraction(PlayerCharacter actor,
public static final BaseAction NEW_GAME =
new BaseAction(Globals.messages.getString("Actions.NEW_GAME.name"),
"",
gameCharacter -> Main.stockGame());
gameCharacter -> Main.buildStockGame());

public static BaseAction OPEN_DOOR(Door door) {
return new BaseAction(Printers.format("Actions.OPEN_DOOR", door.getName()),
Expand Down
16 changes: 15 additions & 1 deletion src/bobbin/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import bobbin.characters.PlayerCharacter;
import bobbin.constants.Items;
import bobbin.effects.GameCharacterEffect;
import bobbin.interaction.ConsolePrompt;
import bobbin.interaction.ExitToException;
import bobbin.interaction.Interactive;
import bobbin.interaction.actions.Action;
Expand Down Expand Up @@ -52,7 +53,20 @@ private static void start(BufferedReader reader, PrintWriter writer,
}
}

public static PlayerCharacter stockGame() {
/**
* Build a room, allowing the player to configure their character.
*
* @return {@link PlayerCharacter} in the new game.
*/
public static PlayerCharacter buildNewGame(BufferedReader reader, PrintWriter writer) {
Room startingRoom = new Room("Starting Room", "A Whole New Room");
return new PlayerCharacter(
ConsolePrompt.getResponseString(reader, writer, "Character Name"),
ConsolePrompt.getResponseString(reader, writer, "Character Tagline"),
startingRoom);
}

public static PlayerCharacter buildStockGame() {
Room startingRoom = new Room("Starting Room", "The room you start in",
Items.getCopiesOf(Items.BLUEBERRY, Items.BED));
Room otherRoom = new Room("Another Room", "Not the room you start in",
Expand Down
18 changes: 14 additions & 4 deletions src/bobbin/menus/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@

public class MainMenu extends Menu {

class DummyPlayerCharacter extends PlayerCharacter {
public DummyPlayerCharacter(String name, String description, Room location) {
super(name, description, location);
}
}

public static PlayerCharacter dummyPlayerCharacter() {
Room fakeRoom = new Room("Fake Room", "For dummy character to exist in");
return new PlayerCharacter("A Dummy Character", "To be used in the main menu", fakeRoom);
Expand All @@ -31,8 +37,8 @@ public static PlayerCharacter dummyPlayerCharacter() {
public void saveGame(PrintWriter writer, PlayerCharacter playerCharacter) {
try {
new SaveGameSerial(playerCharacter.getName()
.replace(' ', '_')
.replace(File.separatorChar, '.'))
.replace(' ', '_')
.replace(File.separatorChar, '.'))
.saveData(playerCharacter);
Printers.printMessage(writer, "MainMenu.gameSaved");
}
Expand All @@ -59,7 +65,11 @@ protected ActionList actions(GameCharacter actor, BaseGameEntity from) {
ActionList actions = new ActionList();

if (SaveGameSerial.hasActiveSave()) {
actions.add(Actions.CONTINUE);
SaveGameSerial activeSave = SaveGameSerial.loadActiveSave();
if (activeSave != null && !(activeSave.loadData() instanceof DummyPlayerCharacter)) {
// Only allow continue if the current player isn't a dummy
actions.add(Actions.CONTINUE);
}
}

actions.add(Actions.NEW_GAME);
Expand Down Expand Up @@ -88,7 +98,7 @@ public int respondToInteraction(PlayerCharacter actor, BaseGameEntity from, Buff
}

if (next.equals(Actions.NEW_GAME)) {
PlayerCharacter playerCharacter = Main.stockGame();
PlayerCharacter playerCharacter = Main.buildNewGame(reader, writer);
return playerCharacter.interact(playerCharacter, this, reader, writer);
}

Expand Down