Skip to content

Commit

Permalink
Integrated the start screen with the main class
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Li committed Apr 25, 2015
1 parent 4d27282 commit cc02013
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 20 deletions.
24 changes: 23 additions & 1 deletion MerchantRPGCSE2102/src/controller/RPGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

Expand All @@ -11,6 +12,7 @@
import model.Merchant;
import model.Player;
import view.MapUI;
import view.StartScreen;

public class RPGame {

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions MerchantRPGCSE2102/src/model/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
87 changes: 68 additions & 19 deletions MerchantRPGCSE2102/src/view/StartScreen.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
}
});
Expand Down Expand Up @@ -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);
// }
}

0 comments on commit cc02013

Please sign in to comment.