From 3c2224e20b5323d51589b7d09a11182a3e951d10 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Wed, 2 Apr 2014 10:12:57 +0200 Subject: Fix web runtime error (HashMap import) --- src/esieequest/view/View.java | 54 ++++++++++++++++++------- src/esieequest/view/app/UserInterface.java | 61 ++++++++++++++++++----------- src/esieequest/view/text/TextInterface.java | 36 +++++++++++------ src/esieequest/view/web/WebInterface.java | 48 +++++++++++++---------- 4 files changed, 131 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/esieequest/view/View.java b/src/esieequest/view/View.java index 545879a..9ffd7ec 100644 --- a/src/esieequest/view/View.java +++ b/src/esieequest/view/View.java @@ -3,8 +3,13 @@ */ package esieequest.view; +import java.util.HashMap; + import esieequest.controller.GameEngine; -import esieequest.model.Game; +import esieequest.model.Item; +import esieequest.model.Quest; +import esieequest.model.Room; +import esieequest.model.Side; /** * The view interface that describes an user interface. @@ -13,14 +18,6 @@ import esieequest.model.Game; */ public interface View { - /** - * Sets the model to use. - * - * @param game - * the Game model - */ - public void setModel(Game game); - /** * Sets the controller to use. * @@ -39,22 +36,49 @@ public interface View { */ public void enable(); + /** + * Displays a message. + * + * @param message + * the message + */ + public void echo(String message); + /** * Disables the user interface. */ public void disable(); /** - * Refreshes the user interface. + * Updates the view to match the current room. + * + * @param room + * the room to display */ - public void refresh(); + public void updateRoom(Room room); /** - * Displays a message. + * Updates the view to match a side of a room. * - * @param message - * the message + * @param side + * the side of a room */ - public void echo(String message); + public void updateSide(Side side); + + /** + * Updates the view to match the current quest. + * + * @param quest + * the current quest to display + */ + public void updateQuest(Quest quest); + + /** + * Updates the view to display the items contained in the inventory + * + * @param items + * the items + */ + public void updateInventory(HashMap items); } diff --git a/src/esieequest/view/app/UserInterface.java b/src/esieequest/view/app/UserInterface.java index 1fc57bd..28b2f37 100644 --- a/src/esieequest/view/app/UserInterface.java +++ b/src/esieequest/view/app/UserInterface.java @@ -18,7 +18,10 @@ import javax.swing.border.EmptyBorder; import com.wordpress.tipsforjava.swing.StretchIcon; import esieequest.controller.GameEngine; -import esieequest.model.Game; +import esieequest.model.Item; +import esieequest.model.Quest; +import esieequest.model.Room; +import esieequest.model.Side; import esieequest.view.View; /** @@ -28,7 +31,6 @@ import esieequest.view.View; */ abstract class UserInterface implements View, ActionListener { - protected Game game; private GameEngine gameEngine; private JPanel layout; @@ -127,18 +129,20 @@ abstract class UserInterface implements View, ActionListener { controlPanel.add(topControlPanel, BorderLayout.NORTH); topControlPanel.setLayout(new BorderLayout(0, 0)); + final Font font = new Font("Dialog", Font.BOLD, 19); + final JButton forwardButton = new JButton("↥"); - forwardButton.setFont(new Font("Dialog", Font.BOLD, 19)); + forwardButton.setFont(font); forwardButton.setToolTipText("Go forward"); topControlPanel.add(forwardButton, BorderLayout.CENTER); final JButton inventoryButton = new JButton("⇱"); - inventoryButton.setFont(new Font("Dialog", Font.BOLD, 19)); + inventoryButton.setFont(font); inventoryButton.setToolTipText("Use item"); topControlPanel.add(inventoryButton, BorderLayout.WEST); final JButton actionButton = new JButton("⇲"); - actionButton.setFont(new Font("Dialog", Font.BOLD, 19)); + actionButton.setFont(font); actionButton.setToolTipText("Talk/Take item"); topControlPanel.add(actionButton, BorderLayout.EAST); @@ -147,17 +151,17 @@ abstract class UserInterface implements View, ActionListener { bottomControlPanel.setLayout(new BorderLayout(0, 0)); final JButton backButton = new JButton("↧"); - backButton.setFont(new Font("Dialog", Font.BOLD, 19)); + backButton.setFont(font); backButton.setToolTipText("Go back"); bottomControlPanel.add(backButton, BorderLayout.CENTER); final JButton leftButton = new JButton("↰"); - leftButton.setFont(new Font("Dialog", Font.BOLD, 19)); + leftButton.setFont(font); leftButton.setToolTipText("Turn left"); bottomControlPanel.add(leftButton, BorderLayout.WEST); final JButton rightButton = new JButton("↱"); - rightButton.setFont(new Font("Dialog", Font.BOLD, 19)); + rightButton.setFont(font); rightButton.setToolTipText("Turn right"); bottomControlPanel.add(rightButton, BorderLayout.EAST); @@ -215,8 +219,7 @@ abstract class UserInterface implements View, ActionListener { * @param actionListener * the action listener */ - private void setActionListener(final HashMap hashMap, - final ActionListener actionListener) { + private void setActionListener(final HashMap hashMap, final ActionListener actionListener) { for (final JButton vButton : hashMap.values()) { vButton.addActionListener(actionListener); } @@ -260,15 +263,15 @@ abstract class UserInterface implements View, ActionListener { * @param quest * the quest title */ - private void setQuest(final String quest) { - this.questTextPane.setText(quest); + private void setQuestLabel(final String questTitle) { + this.questTextPane.setText(questTitle); } /** * Updates the room illustration. */ - private void updateIllustration() { - String imageName = this.game.getLocationImageName(); + private void updateIllustration(final String locationImageName) { + String imageName = locationImageName; if (imageName == null) { imageName = "res/img/placeholder.jpg"; } @@ -287,13 +290,19 @@ abstract class UserInterface implements View, ActionListener { } @Override - public void setModel(final Game game) { - this.game = game; + public void setController(final GameEngine gameEngine) { + this.gameEngine = gameEngine; } @Override - public void setController(final GameEngine gameEngine) { - this.gameEngine = gameEngine; + public void enable() { + this.setControlsState(true); + } + + @Override + public void disable() { + this.setControlsState(false); + this.setQuestLabel("ESIEEquest"); } @Override @@ -303,16 +312,24 @@ abstract class UserInterface implements View, ActionListener { } @Override - public void enable() { + public void updateRoom(final Room room) { + // this.updateIllustration(room.getImageName()); + this.echo(room.getInformations()); } @Override - public void disable() { + public void updateSide(final Side side) { + // this.updateIllustration(side.getImageName()); + } + + @Override + public void updateQuest(final Quest quest) { + this.setQuestLabel(quest.getTitle()); } @Override - public void refresh() { - // TODO + public void updateInventory(final HashMap items) { + // TODO Auto-generated method stub } } diff --git a/src/esieequest/view/text/TextInterface.java b/src/esieequest/view/text/TextInterface.java index f52b6a2..133b03b 100644 --- a/src/esieequest/view/text/TextInterface.java +++ b/src/esieequest/view/text/TextInterface.java @@ -1,7 +1,12 @@ package esieequest.view.text; +import java.util.HashMap; + import esieequest.controller.GameEngine; -import esieequest.model.Game; +import esieequest.model.Item; +import esieequest.model.Quest; +import esieequest.model.Room; +import esieequest.model.Side; import esieequest.view.View; /** @@ -11,7 +16,6 @@ import esieequest.view.View; */ abstract class TextInterface implements View { - protected Game game; protected GameEngine gameEngine; protected boolean running; @@ -25,11 +29,6 @@ abstract class TextInterface implements View { protected abstract void run(); - @Override - public void setModel(final Game game) { - this.game = game; - } - @Override public void setController(final GameEngine gameEngine) { this.gameEngine = gameEngine; @@ -54,13 +53,28 @@ abstract class TextInterface implements View { } @Override - public void refresh() { - this.echo(this.game.getLocationInfo()); + public void echo(final String message) { + System.out.println(message); } @Override - public void echo(final String message) { - System.out.println(message); + public void updateRoom(final Room room) { + this.echo(room.getInformations()); + } + + @Override + public void updateSide(final Side side) { + // TODO Auto-generated method stub + } + + @Override + public void updateQuest(final Quest quest) { + this.echo("Current quest: " + quest.getTitle()); + } + + @Override + public void updateInventory(final HashMap items) { + // TODO Auto-generated method stub } } diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index f1abe9d..97265cb 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -1,15 +1,13 @@ package esieequest.view.web; +import java.util.HashMap; + import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; 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.event.dom.client.KeyPressEvent; -import com.google.gwt.event.dom.client.KeyPressHandler; -import com.google.gwt.event.dom.client.KeyUpEvent; -import com.google.gwt.event.dom.client.KeyUpHandler; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.Event; @@ -25,7 +23,10 @@ import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.Widget; import esieequest.controller.GameEngine; -import esieequest.model.Game; +import esieequest.model.Item; +import esieequest.model.Quest; +import esieequest.model.Room; +import esieequest.model.Side; import esieequest.view.View; /** @@ -36,7 +37,6 @@ import esieequest.view.View; class WebInterface extends Composite implements View { private GameEngine gameEngine; - private Game game; private static WebInterfaceUiBinder uiBinder = GWT.create(WebInterfaceUiBinder.class); @@ -138,8 +138,9 @@ class WebInterface extends Composite implements View { */ private void bindKeys() { Event.addNativePreviewHandler(new NativePreviewHandler() { - public void onPreviewNativeEvent(NativePreviewEvent event) { - int key = event.getNativeEvent().getKeyCode(); + @Override + public void onPreviewNativeEvent(final NativePreviewEvent event) { + final int key = event.getNativeEvent().getKeyCode(); } }); } @@ -261,11 +262,6 @@ class WebInterface extends Composite implements View { } } - @Override - public void setModel(final Game game) { - this.game = game; - } - @Override public void setController(final GameEngine gameEngine) { this.gameEngine = gameEngine; @@ -288,16 +284,28 @@ class WebInterface extends Composite implements View { } @Override - public void refresh() { - // TODO: current quest title and music - // TODO: current room/side illustration - // TODO: control buttons state - // TODO: inventory + public void echo(final String message) { + this.displayLabel.setText(message); } @Override - public void echo(final String message) { - this.displayLabel.setText(message); + public void updateRoom(final Room room) { + this.echo(room.getInformations()); + } + + @Override + public void updateSide(final Side side) { + // this.setIllustration(side.); + } + + @Override + public void updateQuest(final Quest quest) { + this.setQuestLabel(quest.getTitle()); + } + + @Override + public void updateInventory(final HashMap items) { + // TODO Auto-generated method stub } } -- cgit v1.2.3