From cc020131c97c621612df6a80421f7b80f665d370 Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Sat, 25 Apr 2015 12:56:12 -0400 Subject: [PATCH 1/2] Integrated the start screen with the main class --- MerchantRPGCSE2102/src/controller/RPGame.java | 24 ++++- MerchantRPGCSE2102/src/model/Player.java | 11 +++ MerchantRPGCSE2102/src/view/StartScreen.java | 87 +++++++++++++++---- 3 files changed, 102 insertions(+), 20 deletions(-) diff --git a/MerchantRPGCSE2102/src/controller/RPGame.java b/MerchantRPGCSE2102/src/controller/RPGame.java index 165db89..ce7718c 100644 --- a/MerchantRPGCSE2102/src/controller/RPGame.java +++ b/MerchantRPGCSE2102/src/controller/RPGame.java @@ -2,6 +2,7 @@ import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; @@ -11,6 +12,7 @@ import model.Merchant; import model.Player; import view.MapUI; +import view.StartScreen; public class RPGame { @@ -40,6 +42,7 @@ public class RPGame { public boolean _movement = true; private int _currentDay; private int _transactionLimit; + public boolean _initialGameVariable; public RPGame(int transactionLimit, int tileSize) { @@ -59,6 +62,21 @@ public RPGame(int transactionLimit, int tileSize) { buildMerchants(); buildPlayer("test", 500); + // Initialize the start screen + _initialGameVariable = false; + + try { + createStartScreen(this); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + while(_initialGameVariable == false) + { + System.out.println("In Loop"); + } + // Initialiing Map instance and adding the player and merchants to the map map = new Map(rows, cols); map.initializePlayer(_player, rows/2, cols/2); @@ -132,7 +150,7 @@ else if (currentMerchant == 3) */ public void buildMerchants() { - _merchant1 = new Merchant("Cheap Merchant", 200, merchantInventoryList1, 0); + _merchant1 = new Merchant("Cheap Merchant", 300, merchantInventoryList1, 0); _merchant2 = new Merchant("Medium Merchant", 600, merchantInventoryList2, merchantInventoryList1.size()); _merchant3 = new Merchant("Expensive Merchant", 1000, merchantInventoryList3, merchantInventoryList1.size()+ merchantInventoryList2.size()); } @@ -197,6 +215,10 @@ public void createTransaction(Player player, Merchant targetMerchant) } } + public void createStartScreen(RPGame game) throws IOException + { + StartScreen newStartScreen = new StartScreen(game); + } /** * Will refresh number of transactions the Player has available diff --git a/MerchantRPGCSE2102/src/model/Player.java b/MerchantRPGCSE2102/src/model/Player.java index 4f77878..24a768b 100644 --- a/MerchantRPGCSE2102/src/model/Player.java +++ b/MerchantRPGCSE2102/src/model/Player.java @@ -141,4 +141,15 @@ public int getPlayerCash() { return _playerCash; } + + /** + * Setter for player name + * + * @param playerName Name of the player + */ + public void setPlayerName(String playerName) + { + _name = playerName; + } + } \ No newline at end of file diff --git a/MerchantRPGCSE2102/src/view/StartScreen.java b/MerchantRPGCSE2102/src/view/StartScreen.java index 1e0bf3c..b38d440 100644 --- a/MerchantRPGCSE2102/src/view/StartScreen.java +++ b/MerchantRPGCSE2102/src/view/StartScreen.java @@ -1,35 +1,30 @@ package view; import java.awt.*; -import java.awt.Color; -import java.awt.GradientPaint; -import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JPanel; import javax.swing.*; +import javax.swing.border.EmptyBorder; -public class StartScreen extends JFrame { +import controller.RPGame; +import model.Player; - private static final long serialVersionUID = 1L; +@SuppressWarnings("serial") +public class StartScreen extends JFrame { JPanel startMenu = new JPanel(); + RPGame _master; + public StartScreen(RPGame master) throws IOException { - - public static void main(String[] args) throws IOException { - new StartScreen(); - } - - public StartScreen() throws IOException { - + _master = master; JLabel MainMenuBG = new JLabel(new ImageIcon("src/images/background.jpg")); MainMenuBG.setVisible(true); Image icon, background; @@ -47,17 +42,22 @@ public StartScreen() throws IOException { JButton start = new JButton("Start"); start.setVisible(true); - start.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e){ + start.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent arg0) { System.out.println("Game started"); + _master._initialGameVariable = true; + exitWindow(); +// createUserNameInputWindow(); } }); JButton instructions = new JButton("Instructions"); instructions.setVisible(true); - instructions.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e){ + instructions.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent arg0) { System.out.println("Instructions opened"); } }); @@ -94,5 +94,54 @@ public BufferedImage loadBackground() throws IOException { return null; } } + + public void exitWindow() + { + this.dispose(); + } + //will re-implement player name assignments when save files are implemented + +// public void createUserNameInputWindow() +// { +// final JFrame contentFrame = new JFrame(); +// JPanel inputPane; +// final JTextField textField_1; +// boolean dispose = false; +// +// contentFrame.setTitle("What is your name?"); +// contentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); +// contentFrame.setBounds(100, 100, 450, 99); +// inputPane = new JPanel(); +// inputPane.setBorder(new EmptyBorder(5, 5, 5, 5)); +// contentFrame.setContentPane(inputPane); +// inputPane.setLayout(new BorderLayout(0, 0)); +// +// textField_1 = new JTextField(); +// inputPane.add(textField_1, BorderLayout.NORTH); +// textField_1.setColumns(10); +// +// JButton btnAccept = new JButton("Accept"); +// btnAccept.addMouseListener(new MouseAdapter() { +// @Override +// public void mouseReleased(MouseEvent arg0) { +// String userInput = textField_1.getText(); +// setPlayerName(userInput); +// System.out.println(userInput); +// dispose = true; +// } +// }); +// inputPane.add(btnAccept, BorderLayout.SOUTH); +// contentFrame.setVisible(true); +// +// if(dispose = true) +// { +// this.dispose(); +// } +// } +// +// public void setPlayerName(String playerName) +// { +// _player.setPlayerName(playerName); +// } } From 29f1e756630cbbd406e69c41ecb9ddc34e0470c8 Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Sat, 25 Apr 2015 13:22:02 -0400 Subject: [PATCH 2/2] Created instructions --- .../src/config/instructions.txt | 1 + MerchantRPGCSE2102/src/view/StartScreen.java | 54 +++---------------- 2 files changed, 9 insertions(+), 46 deletions(-) create mode 100644 MerchantRPGCSE2102/src/config/instructions.txt diff --git a/MerchantRPGCSE2102/src/config/instructions.txt b/MerchantRPGCSE2102/src/config/instructions.txt new file mode 100644 index 0000000..550cd0e --- /dev/null +++ b/MerchantRPGCSE2102/src/config/instructions.txt @@ -0,0 +1 @@ +Testing Instructions file \ No newline at end of file diff --git a/MerchantRPGCSE2102/src/view/StartScreen.java b/MerchantRPGCSE2102/src/view/StartScreen.java index b38d440..8f933ca 100644 --- a/MerchantRPGCSE2102/src/view/StartScreen.java +++ b/MerchantRPGCSE2102/src/view/StartScreen.java @@ -48,7 +48,7 @@ public void mouseReleased(MouseEvent arg0) { System.out.println("Game started"); _master._initialGameVariable = true; exitWindow(); -// createUserNameInputWindow(); + } }); @@ -59,6 +59,13 @@ public void mouseReleased(MouseEvent arg0) { @Override public void mouseReleased(MouseEvent arg0) { System.out.println("Instructions opened"); + ProcessBuilder pb = new ProcessBuilder("Notepad.exe", "src/config/instructions.txt"); + try { + pb.start(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } }); @@ -99,49 +106,4 @@ public void exitWindow() { this.dispose(); } - - //will re-implement player name assignments when save files are implemented - -// public void createUserNameInputWindow() -// { -// final JFrame contentFrame = new JFrame(); -// JPanel inputPane; -// final JTextField textField_1; -// boolean dispose = false; -// -// contentFrame.setTitle("What is your name?"); -// contentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); -// contentFrame.setBounds(100, 100, 450, 99); -// inputPane = new JPanel(); -// inputPane.setBorder(new EmptyBorder(5, 5, 5, 5)); -// contentFrame.setContentPane(inputPane); -// inputPane.setLayout(new BorderLayout(0, 0)); -// -// textField_1 = new JTextField(); -// inputPane.add(textField_1, BorderLayout.NORTH); -// textField_1.setColumns(10); -// -// JButton btnAccept = new JButton("Accept"); -// btnAccept.addMouseListener(new MouseAdapter() { -// @Override -// public void mouseReleased(MouseEvent arg0) { -// String userInput = textField_1.getText(); -// setPlayerName(userInput); -// System.out.println(userInput); -// dispose = true; -// } -// }); -// inputPane.add(btnAccept, BorderLayout.SOUTH); -// contentFrame.setVisible(true); -// -// if(dispose = true) -// { -// this.dispose(); -// } -// } -// -// public void setPlayerName(String playerName) -// { -// _player.setPlayerName(playerName); -// } }