Skip to content

Commit

Permalink
Updated Transaction related classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Li committed Feb 24, 2015
1 parent 586e6d4 commit a823a7f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
25 changes: 24 additions & 1 deletion MerchantRPGCSE2102/src/controller/RPGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public void createTransaction(Player player, Merchant targetMerchant)
{
toggleMovement("OFF");
Transaction newTransaction = new Transaction(player, targetMerchant);
newTransaction.runTransaction();
}

/**
Expand All @@ -129,4 +128,28 @@ else if(command.equals("OFF"))
else
System.out.println("Invalid movement toggle command");
}

/**
* Returns the player
* @return Returns the player
*/
public Player getPlayer()
{
return _player;
}

/**
* Returns a merchant based off of the input number
* @param merchantNum The number of the merchant you want
* @return Returns the merchant that you specified
*/
public Merchant getMerchant(int merchantNum)
{
if(merchantNum == 1)
return _merchant1;
else if(merchantNum == 2)
return _merchant2;
else
return _merchant3;
}
}
19 changes: 18 additions & 1 deletion MerchantRPGCSE2102/src/controller/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public Transaction(Player player, Merchant targetMerchant)
*/
public void runTransaction()
{
_window = new TransactionUI(this);
}

/**
Expand Down Expand Up @@ -65,4 +64,22 @@ public boolean actionCancel()
{
return true;
}

/**
* Returns the player in transaction
* @return returns the player
*/
public Player getPlayer()
{
return _player;
}

/**
* Returns the merchant in transaction
* @return returns the merchant
*/
public Merchant getTargetMerchant()
{
return _targetMerchant;
}
}
16 changes: 15 additions & 1 deletion MerchantRPGCSE2102/src/tests/TestTransaction.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
package tests;

import controller.RPGame;
import junit.framework.TestCase;

public class TestTransaction extends TestCase
{

private RPGame _rpg;

public void setup()
{
_rpg = new RPGame();
_rpg.inventoryFromFile();
_rpg.buildMerchants();
}

public void testActionSell()
{
_rpg.createTransaction(_rpg.getPlayer(), _rpg.getMerchant(1));
System.out.println("wow");
}
}
28 changes: 26 additions & 2 deletions MerchantRPGCSE2102/src/view/TransactionUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import java.awt.EventQueue;

import javax.swing.BoxLayout;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JLabel;
Expand All @@ -23,6 +26,7 @@

public class TransactionUI extends JFrame {

private static final ComboBoxModel[] Item = null;
private JPanel contentPane;
private static Transaction MASTER; //TransactionUI class will hold the instance of the Transaction that created it

Expand Down Expand Up @@ -124,7 +128,7 @@ public void run()
{
JFrame frame = new JFrame("Buy");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setBounds(100, 100, 600, 900);
frame.setBounds(100, 100, 600, 600);
JPanel contentPane = new JPanel();
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
Expand All @@ -140,17 +144,37 @@ public void run()
* Will create a window for the SELL option
* incomplete method
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void createSellWindow()
{
JFrame frame = new JFrame("Sell");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setBounds(100, 100, 600, 900);
frame.setBounds(100, 100, 600, 600);
JPanel contentPane = new JPanel();
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
frame.setContentPane(contentPane);
contentPane.setLayout(null);

JComboBox comboBox = new JComboBox(MASTER.getPlayer().getInventory());
comboBox.setBounds(61, 141, 131, 20);
contentPane.add(comboBox);

JSlider slider = new JSlider();
slider.setBounds(61, 237, 200, 26);
contentPane.add(slider);

JLabel lblSelectTheItem = new JLabel("Select the Item you want:");
lblSelectTheItem.setBounds(61, 105, 168, 14);
contentPane.add(lblSelectTheItem);

JLabel lblSelectTheAmount = new JLabel("Select the amount:");
lblSelectTheAmount.setBounds(61, 197, 131, 14);
contentPane.add(lblSelectTheAmount);

JButton btnAccept = new JButton("Accept");
btnAccept.setBounds(247, 306, 89, 23);
contentPane.add(btnAccept);
frame.setVisible(true);
}
}

0 comments on commit a823a7f

Please sign in to comment.