From 3fc06f393c5f8fc3647e58aee2dc6048c72e8e56 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Wed, 5 Mar 2014 10:25:44 +0100 Subject: Implement single item and remove convention --- src/esieequest/Main.java | 22 +- src/esieequest/controller/GameEngine.java | 28 +-- src/esieequest/controller/Interpreter.java | 42 ++-- src/esieequest/controller/Parser.java | 18 +- src/esieequest/controller/Performer.java | 45 ++-- src/esieequest/model/Game.java | 56 +++-- src/esieequest/model/Item.java | 54 ++++ src/esieequest/model/Room.java | 57 +++-- src/esieequest/model/command/Command.java | 18 +- src/esieequest/model/command/CommandWord.java | 16 +- src/esieequest/view/View.java | 6 +- src/esieequest/view/app/Applet.java | 8 +- src/esieequest/view/app/UserInterface.java | 345 +++++++++++++------------- src/esieequest/view/app/Window.java | 12 +- src/esieequest/view/console/Console.java | 28 +-- src/esieequest/view/web/Main.java | 6 +- src/esieequest/view/web/WebInterface.java | 22 +- 17 files changed, 430 insertions(+), 353 deletions(-) create mode 100644 src/esieequest/model/Item.java diff --git a/src/esieequest/Main.java b/src/esieequest/Main.java index 5a08f1d..b4bfb59 100755 --- a/src/esieequest/Main.java +++ b/src/esieequest/Main.java @@ -25,28 +25,28 @@ public class Main extends JApplet { /** * */ - private static final long serialVersionUID = 1726402114771940798L; + private static long serialVersionUID = 1726402114771940798L; public void init() { // applet - Game vGame = new Game(); - Applet vApplet = new Applet(this); - new GameEngine(vGame, vApplet); + Game game = new Game(); + Applet applet = new Applet(this); + new GameEngine(game, applet); } - public static void main(final String[] pArgs) { + public static void main(String[] args) { // cli or standalone - Game vGame = new Game(); - View vView; + Game game = new Game(); + View view; - if (Arrays.asList(pArgs).contains("--nogui")) { - vView = new Console(); + if (Arrays.asList(args).contains("--nogui")) { + view = new Console(); } else { - vView = new Window(); + view = new Window(); } - new GameEngine(vGame, vView); + new GameEngine(game, view); } } diff --git a/src/esieequest/controller/GameEngine.java b/src/esieequest/controller/GameEngine.java index 3999cd0..4a1f47f 100644 --- a/src/esieequest/controller/GameEngine.java +++ b/src/esieequest/controller/GameEngine.java @@ -14,35 +14,35 @@ import esieequest.view.View; */ public class GameEngine { - private Game aGame; - private View aView; + private Game game; + private View view; - private Interpreter aInterpreter; + private Interpreter interpreter; - public GameEngine(final Game pGame, final View pView) { - this.aGame = pGame; - this.aView = pView; + public GameEngine(Game game, View view) { + this.game = game; + this.view = view; - this.aView.setModel(pGame); - this.aView.setController(this); + this.view.setModel(game); + this.view.setController(this); - this.aInterpreter = new Interpreter(this.aGame, this.aView); + this.interpreter = new Interpreter(this.game, this.view); this.startGame(); this.startView(); } private void startGame() { - this.aGame.setRunning(true); - this.aInterpreter.interpret("new"); + this.game.setRunning(true); + this.interpreter.interpret("new"); } private void startView() { - this.aView.enable(); + this.view.enable(); } - public void interpret(final String pCommandString) { - this.aInterpreter.interpret(pCommandString); + public void interpret(String commandString) { + this.interpreter.interpret(commandString); } } diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java index b4fbb3e..55d468b 100644 --- a/src/esieequest/controller/Interpreter.java +++ b/src/esieequest/controller/Interpreter.java @@ -13,52 +13,52 @@ import esieequest.view.View; */ public class Interpreter { - private Performer aPerformer; - private Parser aParser; + private Performer performer; + private Parser parser; - public Interpreter(final Game pGame, final View pView) { - this.aPerformer = new Performer(pGame, pView); - this.aParser = new Parser(); + public Interpreter(Game game, View view) { + this.performer = new Performer(game, view); + this.parser = new Parser(); } - public void interpret(String pCommandString) { - Command vCommand = this.aParser.getCommand(pCommandString); - this.dispatch(vCommand); + public void interpret(String commandString) { + Command command = this.parser.getCommand(commandString); + this.dispatch(command); } - public void dispatch(final Command pCommand) { - if (pCommand.getAction() != null) { - switch (pCommand.getAction()) { + public void dispatch(Command command) { + if (command.getAction() != null) { + switch (command.getAction()) { case "new": - this.aPerformer.newGame(); + this.performer.newGame(); return; case "load": - this.aPerformer.loadGame(); + this.performer.loadGame(); return; case "save": - this.aPerformer.saveGame(); + this.performer.saveGame(); return; case "sound": - this.aPerformer.toggleSound(); + this.performer.toggleSound(); return; case "go": - this.aPerformer.goTo(pCommand.getOption()); + this.performer.goTo(command.getOption()); return; case "look": - this.aPerformer.look(); + this.performer.look(); return; case "eat": - this.aPerformer.eat(); + this.performer.eat(); return; case "help": - this.aPerformer.showHelp(); + this.performer.showHelp(); return; case "quit": - this.aPerformer.quitGame(); + this.performer.quitGame(); return; } } - this.aPerformer.echo("Unknown command."); + this.performer.echo("Unknown command."); return; } } diff --git a/src/esieequest/controller/Parser.java b/src/esieequest/controller/Parser.java index c9095fe..117d69f 100644 --- a/src/esieequest/controller/Parser.java +++ b/src/esieequest/controller/Parser.java @@ -7,20 +7,20 @@ public class Parser { public Parser() { } - public Command getCommand(final String pCommandString) { - String[] vElements = pCommandString.split(" "); + public Command getCommand(String commandString) { + String[] elements = commandString.split(" "); - String vAction = null; - String vOption = null; + String action = null; + String option = null; - if (vElements.length > 0) { - vAction = vElements[0]; + if (elements.length > 0) { + action = elements[0]; } - if (vElements.length > 1) { - vOption = vElements[1]; + if (elements.length > 1) { + option = elements[1]; } - return new Command(vAction, vOption); + return new Command(action, option); } private void validateCommand() { diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java index c56ef39..b7044f2 100644 --- a/src/esieequest/controller/Performer.java +++ b/src/esieequest/controller/Performer.java @@ -13,60 +13,61 @@ import esieequest.view.View; */ public class Performer { - private Game aGame; - private View aView; + private Game game; + private View view; - public Performer(final Game pGame, final View pView) { - this.aGame = pGame; - this.aView = pView; + public Performer(Game game, View view) { + this.game = game; + this.view = view; } - public void echo(final String pString) { - this.aView.echo(pString); + public void echo(String message) { + this.view.echo(message); } public void newGame() { // this.loadGame(default game); - this.aView.echo(this.aGame.getWelcomeMessage() + "\n" + this.aGame.getLocationInfo()); + this.view.echo(this.game.getWelcomeMessage() + "\n" + this.game.getLocationInfo()); } public void loadGame() { - this.aView.echo("Not implemented."); + this.view.echo("Not implemented."); } public void saveGame() { - this.aView.echo("Not implemented."); + this.view.echo("Not implemented."); } public void toggleSound() { - this.aView.echo("Not implemented."); + this.view.echo("Not implemented."); } public void quitGame() { - this.aView.echo(this.aGame.getQuitMessage()); - this.aGame.setRunning(false); + this.view.echo(this.game.getQuitMessage()); + this.game.setRunning(false); } public void showHelp() { - this.aView.echo(this.aGame.getHelpMessage()); + this.view.echo(this.game.getHelpMessage()); } - public void goTo(final String pDirection) { - Room vNextRoom = this.aGame.getRoomExit(pDirection); - if (vNextRoom != null) { - this.aGame.goToRoom(vNextRoom); - this.aView.echo(this.aGame.getLocationInfo()); + public void goTo(String direction) { + Room nextRoom = this.game.getRoomExit(direction); + if (nextRoom != null) { + this.game.goToRoom(nextRoom); + this.view.echo(this.game.getLocationInfo()); } else { - this.aView.echo(this.aGame.getNoExitMessage()); + this.view.echo(this.game.getNoExitMessage()); } } public void look() { - this.aView.echo(this.aGame.getLocationInfo()); + this.view.echo(this.game.getLocationInfo()); + this.view.echo(this.game.getItemDescription()); } public void eat() { - this.aView.echo(this.aGame.getEatMessage()); + this.view.echo(this.game.getEatMessage()); } } diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java index 668a7f9..eb74f85 100644 --- a/src/esieequest/model/Game.java +++ b/src/esieequest/model/Game.java @@ -11,27 +11,27 @@ import java.util.HashMap; */ public class Game { - private boolean aRunning; - private HashMap aRooms; - private Room aCurrentRoom; + private boolean running; + private HashMap rooms; + private Room currentRoom; public Game() { - this.aRunning = false; - this.aRooms = new HashMap(); - this.aCurrentRoom = null; + this.running = false; + this.rooms = new HashMap(); + this.currentRoom = null; this.createRooms(); this.linkRooms(); + this.createItems(); this.goToRoom("AmphitheaterSeat"); } - private void createRoom(final String pName, final String pDescription) { - this.aRooms.put(pName, new Room(pDescription)); + private void createRoom(String name, String description) { + this.rooms.put(name, new Room(description)); } - private void setRoomExit(final String pRoomName, final String pDirection, - final String pExitRoomName) { - this.aRooms.get(pRoomName).setExit(pDirection, this.aRooms.get(pExitRoomName)); + private void setRoomExit(String roomName, String direction, String exitRoomName) { + this.rooms.get(roomName).setExit(direction, this.rooms.get(exitRoomName)); } private void createRooms() { @@ -165,32 +165,36 @@ public class Game { this.setRoomExit("OffscriptMovingcharacter", "west", "OffscriptAlea"); } - public void setRunning(final boolean pState) { - this.aRunning = pState; + private void createItems() { + this.rooms.get("Cafeteria").setItem(new Item("Banana", 12)); + } + + public void setRunning(boolean state) { + this.running = state; } public boolean isRunning() { - return this.aRunning; + return this.running; } - public void goToRoom(final Room pRoom) { - this.aCurrentRoom = pRoom; + public void goToRoom(Room room) { + this.currentRoom = room; } - public void goToRoom(final String pRoomName) { - this.aCurrentRoom = this.aRooms.get(pRoomName); + public void goToRoom(String roomName) { + this.currentRoom = this.rooms.get(roomName); } - public Room getRoomExit(final String pDirection) { - return this.aCurrentRoom.getExit(pDirection); + public Room getRoomExit(String direction) { + return this.currentRoom.getExit(direction); } public String getLocationInfo() { - return this.aCurrentRoom.getLongDescription(); + return this.currentRoom.getLongDescription(); } public String getLocationImageName() { - return this.aCurrentRoom.getImageName(); + return this.currentRoom.getImageName(); } public String getEatMessage() { @@ -213,4 +217,12 @@ public class Game { return "There is no exit."; } + public String getItemDescription() { + if (this.currentRoom != null) { + return "This room contain : " + this.currentRoom.getItem().getDescription(); + } else { + return ""; + } + } + } diff --git a/src/esieequest/model/Item.java b/src/esieequest/model/Item.java new file mode 100644 index 0000000..dded1a1 --- /dev/null +++ b/src/esieequest/model/Item.java @@ -0,0 +1,54 @@ +/** + * + */ +package esieequest.model; + +/** + * @author pacien + * + */ +public class Item { + + private String description; + private int weight; + + public Item() { + this(null, 0); + } + + public Item(String description, int weight) { + this.description = description; + this.weight = weight; + } + + /** + * @return the description + */ + public String getDescription() { + return this.description; + } + + /** + * @param description + * the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the weight + */ + public int getWeight() { + return this.weight; + } + + /** + * @param weight + * the weight to set + */ + public void setWeight(int weight) { + this.weight = weight; + } + +} diff --git a/src/esieequest/model/Room.java b/src/esieequest/model/Room.java index 2564b91..0ab0a48 100644 --- a/src/esieequest/model/Room.java +++ b/src/esieequest/model/Room.java @@ -19,9 +19,10 @@ import java.util.Set; */ public class Room { - private String aDescription; - private String aImageName; - private HashMap aExits; + private String description; + private String imageName; + private HashMap exits; + private Item item; /** * Create a room described "description". Initially, it has no exits. @@ -32,14 +33,14 @@ public class Room { * @param image * name The room's image */ - public Room(final String pDescription, final String pImageName) { - this.aDescription = pDescription; - this.aImageName = pImageName; - this.aExits = new HashMap(); + public Room(String description, String imageName) { + this.description = description; + this.imageName = imageName; + this.exits = new HashMap(); } - public Room(final String pDescription) { - this(pDescription, null); + public Room(String description) { + this(description, null); } /** @@ -47,7 +48,7 @@ public class Room { * constructor). */ public String getShortDescription() { - return this.aDescription; + return this.description; } /** @@ -60,22 +61,22 @@ public class Room { * @return A description of the room, including exits. */ public String getLongDescription() { - return "You are " + this.aDescription + ".\n" + getExitString(); + return "You are " + this.description + ".\n" + getExitString(); } /** * Return a string describing the room's image name */ public String getImageName() { - return this.aImageName; + return this.imageName; } /** * Return the room that is reached if we go from this room in direction * "direction". If there is no room in that direction, return null. */ - public Room getExit(String pDirection) { - return this.aExits.get(pDirection); + public Room getExit(String direction) { + return this.exits.get(direction); } /** @@ -85,13 +86,13 @@ public class Room { * @return A description of the available exits. */ public String getExitString() { - StringBuilder vStrBuilder = new StringBuilder("Available exits:"); - Set vKeys = this.aExits.keySet(); - for (Iterator vIter = vKeys.iterator(); vIter.hasNext();) { - vStrBuilder.append(" ").append(vIter.next()); + StringBuilder strBuilder = new StringBuilder("Available exits:"); + Set keys = this.exits.keySet(); + for (Iterator iter = keys.iterator(); iter.hasNext();) { + strBuilder.append(" ").append(iter.next()); } - vStrBuilder.append("."); - return vStrBuilder.toString(); + strBuilder.append("."); + return strBuilder.toString(); } /** @@ -103,7 +104,21 @@ public class Room { * The room in the given direction. */ public void setExit(String direction, Room neighbor) { - this.aExits.put(direction, neighbor); + this.exits.put(direction, neighbor); + } + + /** + * @return the item + */ + public Item getItem() { + return item; + } + + /** + * @param item the item to set + */ + public void setItem(Item item) { + this.item = item; } } diff --git a/src/esieequest/model/command/Command.java b/src/esieequest/model/command/Command.java index a0a26fb..17c17f6 100644 --- a/src/esieequest/model/command/Command.java +++ b/src/esieequest/model/command/Command.java @@ -2,34 +2,34 @@ package esieequest.model.command; public class Command { - private String aAction; - private String aOption; + private String action; + private String option; - public Command(final String pAction, final String pOption) { - this.aAction = pAction; - this.aOption = pOption; + public Command(String action, String option) { + this.action = action; + this.option = option; } /** * @return the Action */ public String getAction() { - return this.aAction; + return this.action; } public boolean isUnknown() { - return this.aAction == null; + return this.action == null; } /** * @return the Option */ public String getOption() { - return this.aOption; + return this.option; } public boolean hasOption() { - return this.aOption != null; + return this.option != null; } } diff --git a/src/esieequest/model/command/CommandWord.java b/src/esieequest/model/command/CommandWord.java index e8bc7ad..7f11c0b 100644 --- a/src/esieequest/model/command/CommandWord.java +++ b/src/esieequest/model/command/CommandWord.java @@ -20,24 +20,24 @@ public enum CommandWord { "talk", new String[] { "" }), INVENTORY("inventory", new String[] { "" }), USE("use", null), UNKNOWN("?", new String[] { "" }); - private String aAction; - private String[] aValidOptions; + private String action; + private String[] validOptions; - CommandWord(final String pAction, final String[] pValidOptions) { - this.aAction = pAction; - this.aValidOptions = pValidOptions; + CommandWord(String action, String[] validOption) { + this.action = action; + this.validOptions = validOption; } public String toString() { - return this.aAction; + return this.action; } public String getAction() { - return this.aAction; + return this.action; } public String[] getValidOptions() { - return this.aValidOptions; + return this.validOptions; } } diff --git a/src/esieequest/view/View.java b/src/esieequest/view/View.java index ad84b61..8dbd42b 100644 --- a/src/esieequest/view/View.java +++ b/src/esieequest/view/View.java @@ -12,14 +12,14 @@ import esieequest.model.Game; */ public interface View { - public void setModel(final Game pGame); + public void setModel(Game game); - public void setController(final GameEngine pGameEngine); + public void setController(GameEngine gameEngine); public void enable(); public void refresh(); - public void echo(final String pMessage); + public void echo(String message); } diff --git a/src/esieequest/view/app/Applet.java b/src/esieequest/view/app/Applet.java index f472b06..485dbda 100644 --- a/src/esieequest/view/app/Applet.java +++ b/src/esieequest/view/app/Applet.java @@ -13,15 +13,15 @@ import esieequest.model.Game; */ public class Applet extends UserInterface { - private JApplet aApplet; + private JApplet applet; - public Applet(final JApplet pApplet) { + public Applet(JApplet applet) { //this.aGame = pGame; - this.aApplet = pApplet; + this.applet = applet; } public void enable() { - this.aApplet.add(this.getLayout()); + this.applet.add(this.getLayout()); } } diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index 36b928e..4f87ef6 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -25,232 +25,231 @@ import java.awt.Font; public abstract class UserInterface implements View, ActionListener { - protected Game aGame; - private GameEngine aGameEngine; + protected Game game; + private GameEngine gameEngine; - private JPanel aLayout; + private JPanel layout; - private JTextPane aQuestTextPane; - private JTextPane aInfoTextPane; + private JTextPane questTextPane; + private JTextPane infoTextPane; - private JLabel aImageLabel; + private JLabel imageLabel; - private HashMap aGameButtons; - private HashMap aControlButtons; - private JTextField aInputField; + private HashMap gameButtons; + private HashMap controlButtons; + private JTextField inputField; /** * Create the panel. */ public UserInterface() { this.buildUI(); - this.aInputField.addActionListener(this); + this.inputField.addActionListener(this); this.setControlsState(false); - aInputField.setEnabled(true); + inputField.setEnabled(true); } private void buildUI() { - this.aLayout = new JPanel(); - this.aLayout.setLayout(new BorderLayout(0, 0)); + this.layout = new JPanel(); + this.layout.setLayout(new BorderLayout(0, 0)); - JPanel vMenuPanel = new JPanel(); - this.aLayout.add(vMenuPanel, BorderLayout.NORTH); - vMenuPanel.setLayout(new BorderLayout(0, 0)); + JPanel menuPanel = new JPanel(); + this.layout.add(menuPanel, BorderLayout.NORTH); + menuPanel.setLayout(new BorderLayout(0, 0)); - JPanel vQuestPanel = new JPanel(); - vMenuPanel.add(vQuestPanel, BorderLayout.CENTER); + JPanel questPanel = new JPanel(); + menuPanel.add(questPanel, BorderLayout.CENTER); - this.aQuestTextPane = new JTextPane(); - this.aQuestTextPane.setEditable(false); - this.aQuestTextPane.setText("ESIEEquest"); - vQuestPanel.add(this.aQuestTextPane); + this.questTextPane = new JTextPane(); + this.questTextPane.setEditable(false); + this.questTextPane.setText("ESIEEquest"); + questPanel.add(this.questTextPane); - JPanel vGamePanel = new JPanel(); - vMenuPanel.add(vGamePanel, BorderLayout.WEST); + JPanel gamePanel = new JPanel(); + menuPanel.add(gamePanel, BorderLayout.WEST); - JButton vNewButton = new JButton("New"); - vNewButton.setToolTipText("New game"); - vGamePanel.add(vNewButton); + JButton newButton = new JButton("New"); + newButton.setToolTipText("New game"); + gamePanel.add(newButton); - JButton vSoundButton = new JButton("Sound"); - vSoundButton.setToolTipText("Toggle sound"); - vGamePanel.add(vSoundButton); + JButton soundButton = new JButton("Sound"); + soundButton.setToolTipText("Toggle sound"); + gamePanel.add(soundButton); JPanel filePanel = new JPanel(); - vMenuPanel.add(filePanel, BorderLayout.EAST); - - JButton vLoadButton = new JButton("Load"); - vLoadButton.setToolTipText("Load a game"); - filePanel.add(vLoadButton); - - JButton vSaveButton = new JButton("Save"); - vSaveButton.setToolTipText("Save the current game"); - filePanel.add(vSaveButton); - - JPanel vImagePanel = new JPanel(); - aLayout.add(vImagePanel, BorderLayout.CENTER); - vImagePanel.setLayout(new BorderLayout(0, 0)); - - this.aImageLabel = new JLabel(); - vImagePanel.add(this.aImageLabel); - - JPanel vUserPanel = new JPanel(); - this.aLayout.add(vUserPanel, BorderLayout.SOUTH); - vUserPanel.setLayout(new BorderLayout(0, 0)); - - JPanel vDispPanel = new JPanel(); - vDispPanel.setBorder(new EmptyBorder(5, 5, 5, 0)); - vUserPanel.add(vDispPanel, BorderLayout.CENTER); - vDispPanel.setLayout(new BorderLayout(0, 0)); - - this.aInfoTextPane = new JTextPane(); - this.aInfoTextPane.setEditable(false); - this.aInfoTextPane.setText("Welcome to ESIEEquest!"); - vDispPanel.add(this.aInfoTextPane); - - aInputField = new JTextField(); - vDispPanel.add(aInputField, BorderLayout.SOUTH); - aInputField.setColumns(10); - - JPanel vControlPanel = new JPanel(); - vControlPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); - vUserPanel.add(vControlPanel, BorderLayout.EAST); - vControlPanel.setLayout(new BorderLayout(0, 0)); - - JPanel vTopControlPanel = new JPanel(); - vControlPanel.add(vTopControlPanel, BorderLayout.NORTH); - vTopControlPanel.setLayout(new BorderLayout(0, 0)); - - JButton vForwardButton = new JButton("↥"); - vForwardButton.setFont(new Font("Dialog", Font.BOLD, 19)); - vForwardButton.setToolTipText("Go forward"); - vTopControlPanel.add(vForwardButton, BorderLayout.CENTER); - - JButton vInventoryButton = new JButton("⇱"); - vInventoryButton.setFont(new Font("Dialog", Font.BOLD, 19)); - vInventoryButton.setToolTipText("Use item"); - vTopControlPanel.add(vInventoryButton, BorderLayout.WEST); - - JButton vActionButton = new JButton("⇲"); - vActionButton.setFont(new Font("Dialog", Font.BOLD, 19)); - vActionButton.setToolTipText("Talk/Take item"); - vTopControlPanel.add(vActionButton, BorderLayout.EAST); - - JPanel vBottomControlPanel = new JPanel(); - vControlPanel.add(vBottomControlPanel, BorderLayout.SOUTH); - vBottomControlPanel.setLayout(new BorderLayout(0, 0)); - - JButton vBackButton = new JButton("↧"); - vBackButton.setFont(new Font("Dialog", Font.BOLD, 19)); - vBackButton.setToolTipText("Go back"); - vBottomControlPanel.add(vBackButton, BorderLayout.CENTER); - - JButton vLeftButton = new JButton("↰"); - vLeftButton.setFont(new Font("Dialog", Font.BOLD, 19)); - vLeftButton.setToolTipText("Turn left"); - vBottomControlPanel.add(vLeftButton, BorderLayout.WEST); - - JButton vRightButton = new JButton("↱"); - vRightButton.setFont(new Font("Dialog", Font.BOLD, 19)); - vRightButton.setToolTipText("Turn right"); - vBottomControlPanel.add(vRightButton, BorderLayout.EAST); - - Dimension vSquareButton = new Dimension(50, 50); - vForwardButton.setPreferredSize(vSquareButton); - vInventoryButton.setPreferredSize(vSquareButton); - vActionButton.setPreferredSize(vSquareButton); - vBackButton.setPreferredSize(vSquareButton); - vLeftButton.setPreferredSize(vSquareButton); - vRightButton.setPreferredSize(vSquareButton); - - vNewButton.setActionCommand("new"); - vSoundButton.setActionCommand("sound"); - vLoadButton.setActionCommand("load"); - vSaveButton.setActionCommand("save"); - - vForwardButton.setActionCommand("forward"); - vInventoryButton.setActionCommand("inventory"); - vActionButton.setActionCommand("do"); - vBackButton.setActionCommand("back"); - vLeftButton.setActionCommand("turn left"); - vRightButton.setActionCommand("turn right"); - - this.aGameButtons = new HashMap(); - - this.aGameButtons.put("vNewButton", vNewButton); - this.aGameButtons.put("vSoundButton", vSoundButton); - this.aGameButtons.put("vLoadButton", vLoadButton); - this.aGameButtons.put("vSaveButton", vSaveButton); - - this.aControlButtons = new HashMap(); - - this.aControlButtons.put("vForwardButton", vForwardButton); - this.aControlButtons.put("vInventoryButton", vInventoryButton); - this.aControlButtons.put("vActionButton", vActionButton); - this.aControlButtons.put("vBackButton", vBackButton); - this.aControlButtons.put("vLeftButton", vLeftButton); - this.aControlButtons.put("vRightButton", vRightButton); + menuPanel.add(filePanel, BorderLayout.EAST); + + JButton loadButton = new JButton("Load"); + loadButton.setToolTipText("Load a game"); + filePanel.add(loadButton); + + JButton saveButton = new JButton("Save"); + saveButton.setToolTipText("Save the current game"); + filePanel.add(saveButton); + + JPanel imagePanel = new JPanel(); + layout.add(imagePanel, BorderLayout.CENTER); + imagePanel.setLayout(new BorderLayout(0, 0)); + + this.imageLabel = new JLabel(); + imagePanel.add(this.imageLabel); + + JPanel userPanel = new JPanel(); + this.layout.add(userPanel, BorderLayout.SOUTH); + userPanel.setLayout(new BorderLayout(0, 0)); + + JPanel dispPanel = new JPanel(); + dispPanel.setBorder(new EmptyBorder(5, 5, 5, 0)); + userPanel.add(dispPanel, BorderLayout.CENTER); + dispPanel.setLayout(new BorderLayout(0, 0)); + + this.infoTextPane = new JTextPane(); + this.infoTextPane.setEditable(false); + this.infoTextPane.setText("Welcome to ESIEEquest!"); + dispPanel.add(this.infoTextPane); + + inputField = new JTextField(); + dispPanel.add(inputField, BorderLayout.SOUTH); + inputField.setColumns(10); + + JPanel controlPanel = new JPanel(); + controlPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + userPanel.add(controlPanel, BorderLayout.EAST); + controlPanel.setLayout(new BorderLayout(0, 0)); + + JPanel topControlPanel = new JPanel(); + controlPanel.add(topControlPanel, BorderLayout.NORTH); + topControlPanel.setLayout(new BorderLayout(0, 0)); + + JButton forwardButton = new JButton("↥"); + forwardButton.setFont(new Font("Dialog", Font.BOLD, 19)); + forwardButton.setToolTipText("Go forward"); + topControlPanel.add(forwardButton, BorderLayout.CENTER); + + JButton inventoryButton = new JButton("⇱"); + inventoryButton.setFont(new Font("Dialog", Font.BOLD, 19)); + inventoryButton.setToolTipText("Use item"); + topControlPanel.add(inventoryButton, BorderLayout.WEST); + + JButton actionButton = new JButton("⇲"); + actionButton.setFont(new Font("Dialog", Font.BOLD, 19)); + actionButton.setToolTipText("Talk/Take item"); + topControlPanel.add(actionButton, BorderLayout.EAST); + + JPanel bottomControlPanel = new JPanel(); + controlPanel.add(bottomControlPanel, BorderLayout.SOUTH); + bottomControlPanel.setLayout(new BorderLayout(0, 0)); + + JButton backButton = new JButton("↧"); + backButton.setFont(new Font("Dialog", Font.BOLD, 19)); + backButton.setToolTipText("Go back"); + bottomControlPanel.add(backButton, BorderLayout.CENTER); + + JButton leftButton = new JButton("↰"); + leftButton.setFont(new Font("Dialog", Font.BOLD, 19)); + leftButton.setToolTipText("Turn left"); + bottomControlPanel.add(leftButton, BorderLayout.WEST); + + JButton rightButton = new JButton("↱"); + rightButton.setFont(new Font("Dialog", Font.BOLD, 19)); + rightButton.setToolTipText("Turn right"); + bottomControlPanel.add(rightButton, BorderLayout.EAST); + + Dimension squareButton = new Dimension(50, 50); + forwardButton.setPreferredSize(squareButton); + inventoryButton.setPreferredSize(squareButton); + actionButton.setPreferredSize(squareButton); + backButton.setPreferredSize(squareButton); + leftButton.setPreferredSize(squareButton); + rightButton.setPreferredSize(squareButton); + + newButton.setActionCommand("new"); + soundButton.setActionCommand("sound"); + loadButton.setActionCommand("load"); + saveButton.setActionCommand("save"); + + forwardButton.setActionCommand("forward"); + inventoryButton.setActionCommand("inventory"); + actionButton.setActionCommand("do"); + backButton.setActionCommand("back"); + leftButton.setActionCommand("turn left"); + rightButton.setActionCommand("turn right"); + + this.gameButtons = new HashMap(); + + this.gameButtons.put("newButton", newButton); + this.gameButtons.put("soundButton", soundButton); + this.gameButtons.put("loadButton", loadButton); + this.gameButtons.put("saveButton", saveButton); + + this.controlButtons = new HashMap(); + + this.controlButtons.put("forwardButton", forwardButton); + this.controlButtons.put("inventoryButton", inventoryButton); + this.controlButtons.put("actionButton", actionButton); + this.controlButtons.put("backButton", backButton); + this.controlButtons.put("leftButton", leftButton); + this.controlButtons.put("rightButton", rightButton); } - public void actionPerformed(final ActionEvent pActionEvent) { - this.aGameEngine.interpret(pActionEvent.getActionCommand()); + public void actionPerformed(ActionEvent actionEvent) { + this.gameEngine.interpret(actionEvent.getActionCommand()); } public JPanel getLayout() { - return this.aLayout; + return this.layout; } - private void setActionListener(final HashMap vHashMap, - final ActionListener pActionListener) { - for (JButton vButton : vHashMap.values()) { - vButton.addActionListener(pActionListener); + private void setActionListener(HashMap hashMap, ActionListener actionListener) { + for (JButton vButton : hashMap.values()) { + vButton.addActionListener(actionListener); } } - public void setActionListener(final ActionListener pActionListener) { - this.aInputField.addActionListener(pActionListener); - this.setActionListener(this.aGameButtons, pActionListener); - this.setActionListener(this.aControlButtons, pActionListener); + public void setActionListener(ActionListener actionListener) { + this.inputField.addActionListener(actionListener); + this.setActionListener(this.gameButtons, actionListener); + this.setActionListener(this.controlButtons, actionListener); } private void clearInputField() { - this.aInputField.setText(null); + this.inputField.setText(null); } - private void setControlsState(final boolean pState) { - this.aInputField.setEnabled(pState); - for (JButton vButton : this.aControlButtons.values()) { - vButton.setEnabled(pState); + private void setControlsState(boolean state) { + this.inputField.setEnabled(state); + for (JButton vButton : this.controlButtons.values()) { + vButton.setEnabled(state); } } - private void setQuest(final String pQuest) { - this.aQuestTextPane.setText(pQuest); + private void setQuest(String quest) { + this.questTextPane.setText(quest); } private void updateIllustration() { - String vImageName = this.aGame.getLocationImageName(); - if (vImageName == null) { - vImageName = "res/img/placeholder.jpg"; + String imageName = this.game.getLocationImageName(); + if (imageName == null) { + imageName = "res/img/placeholder.jpg"; } - URL vImageURL = this.getClass().getClassLoader().getResource(vImageName); - StretchIcon vImageIcon = new StretchIcon(vImageURL, true); - this.aImageLabel.setIcon(vImageIcon); + URL imageURL = this.getClass().getClassLoader().getResource(imageName); + StretchIcon imageIcon = new StretchIcon(imageURL, true); + this.imageLabel.setIcon(imageIcon); } @Override - public void setModel(Game pGame) { - this.aGame = pGame; + public void setModel(Game game) { + this.game = game; } @Override - public void setController(GameEngine pGameEngine) { - this.aGameEngine = pGameEngine; + public void setController(GameEngine gameEngine) { + this.gameEngine = gameEngine; } @Override - public void echo(final String pMessage) { - this.aInfoTextPane.setText(pMessage); + public void echo(String message) { + this.infoTextPane.setText(message); this.clearInputField(); } diff --git a/src/esieequest/view/app/Window.java b/src/esieequest/view/app/Window.java index ad20ce7..8ced556 100644 --- a/src/esieequest/view/app/Window.java +++ b/src/esieequest/view/app/Window.java @@ -13,7 +13,7 @@ import esieequest.model.Game; */ public class Window extends UserInterface { - private JFrame aWindow; + private JFrame window; /** * Create the frame. @@ -22,14 +22,14 @@ public class Window extends UserInterface { */ public Window() { //this.aGame = pGame; - this.aWindow = new JFrame("ESIEEquest"); - this.aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - this.aWindow.setBounds(100, 100, 700, 500); - this.aWindow.setContentPane(this.getLayout()); + this.window = new JFrame("ESIEEquest"); + this.window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.window.setBounds(100, 100, 700, 500); + this.window.setContentPane(this.getLayout()); } public void enable() { - this.aWindow.setVisible(true); + this.window.setVisible(true); } } diff --git a/src/esieequest/view/console/Console.java b/src/esieequest/view/console/Console.java index 90cde08..4fdad5e 100644 --- a/src/esieequest/view/console/Console.java +++ b/src/esieequest/view/console/Console.java @@ -15,30 +15,30 @@ import esieequest.view.View; */ public class Console implements View { - private Game aGame; - private GameEngine aGameEngine; - private Scanner aScanner; + private Game game; + private GameEngine gameEngine; + private Scanner scanner; public Console() { - this.aScanner = new Scanner(System.in); + this.scanner = new Scanner(System.in); } private void play() { - while (this.aGame.isRunning()) { + while (this.game.isRunning()) { System.out.print("> "); - String vInputString = this.aScanner.nextLine(); - this.aGameEngine.interpret(vInputString); + String vInputString = this.scanner.nextLine(); + this.gameEngine.interpret(vInputString); } } @Override - public void setModel(Game pGame) { - this.aGame = pGame; + public void setModel(Game game) { + this.game = game; } @Override - public void setController(GameEngine pGameEngine) { - this.aGameEngine = pGameEngine; + public void setController(GameEngine gameEngine) { + this.gameEngine = gameEngine; } @Override @@ -48,12 +48,12 @@ public class Console implements View { @Override public void refresh() { - this.echo(this.aGame.getLocationInfo()); + this.echo(this.game.getLocationInfo()); } @Override - public void echo(String pMessage) { - System.out.println(pMessage); + public void echo(String message) { + System.out.println(message); } } diff --git a/src/esieequest/view/web/Main.java b/src/esieequest/view/web/Main.java index bf444c9..4e58fd7 100644 --- a/src/esieequest/view/web/Main.java +++ b/src/esieequest/view/web/Main.java @@ -10,9 +10,9 @@ public class Main implements EntryPoint { @Override public void onModuleLoad() { - Game vGame = new Game(); - WebInterface vWebInterface = new WebInterface(); - new GameEngine(vGame, vWebInterface); + Game game = new Game(); + WebInterface webInterface = new WebInterface(); + new GameEngine(game, webInterface); } } diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index 516042e..03be1ac 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -4,17 +4,13 @@ package esieequest.view.web; import com.google.gwt.core.client.GWT; -import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.dom.client.KeyDownHandler; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.uibinder.client.UiHandler; -import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.HasText; import com.google.gwt.user.client.ui.RootLayoutPanel; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Label; @@ -31,8 +27,8 @@ import com.google.gwt.user.client.ui.TextBox; */ public class WebInterface extends Composite implements View { - private GameEngine aGameEngine; - private Game aGame; + private GameEngine gameEngine; + private Game game; private static WebInterfaceUiBinder uiBinder = GWT.create(WebInterfaceUiBinder.class); @@ -81,7 +77,7 @@ public class WebInterface extends Composite implements View { inputField.addKeyDownHandler(new KeyDownHandler() { public void onKeyDown(KeyDownEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { - aGameEngine.interpret(inputField.getText()); + gameEngine.interpret(inputField.getText()); inputField.setText(null); } } @@ -90,13 +86,13 @@ public class WebInterface extends Composite implements View { } @Override - public void setModel(Game pGame) { - this.aGame = pGame; + public void setModel(Game game) { + this.game = game; } @Override - public void setController(GameEngine pGameEngine) { - this.aGameEngine = pGameEngine; + public void setController(GameEngine gameEngine) { + this.gameEngine = gameEngine; } @Override @@ -111,8 +107,8 @@ public class WebInterface extends Composite implements View { } @Override - public void echo(String pMessage) { - this.displayLabel.setText(pMessage); + public void echo(String message) { + this.displayLabel.setText(message); } /* -- cgit v1.2.3