Skip to content

Gavin l #11

Merged
merged 26 commits into from
Feb 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dc1c3ee
Added new Classes: *Added the Transaction,
Feb 20, 2015
f9cf1b2
Added methods to Item and Player, adjusted comments on Merchant:
Feb 20, 2015
3418288
Updated TestPlayer
Feb 20, 2015
5049c7a
Adjusted the sell method in Player class
Feb 20, 2015
48ca7a1
Updated RPGame and Transaction Classes with unfinished methods
Feb 20, 2015
672224d
Added toggleMovement method in the RPGame class
Feb 20, 2015
de25901
Added actionBuy and actionSell to the Transaction Class
Feb 20, 2015
39e35d6
Added a buildMerchants method to the RPGame Class
Feb 20, 2015
8c1d35a
Updated RPGame
Feb 21, 2015
c92c00a
Implemented the Map class as well as movement for the Player. Graph,
john Feb 23, 2015
1d93168
Merge branch 'John-B' of https://github.uconn.edu/gal11002/MerchantRP…
john Feb 23, 2015
e69a1c9
Added TransactionUI class, build skeleton window.
Feb 23, 2015
fe0fe23
Updated Transaction and TransactionUI
Feb 23, 2015
586e6d4
Updated TransactionUI
Feb 23, 2015
a823a7f
Updated Transaction related classes
Feb 24, 2015
2310f04
Reverted to previous
Feb 24, 2015
bb8dfcc
Merge remote-tracking branch 'origin/John-B' into Gavin-L
Feb 24, 2015
ace3312
Avoided conflicts
Feb 24, 2015
4b2d037
Added buildPlayer method to RPGame
Feb 24, 2015
a4c54d7
Updated TransactionUI and created a test method for it in RPGame
Feb 24, 2015
346b22a
Updated TransactionUI
Feb 24, 2015
af58d96
Updated the actionSell method in TransactionUI
Feb 25, 2015
11a3fdb
Completed rough version of TransactionUI
Feb 28, 2015
1db941b
Added a new package exceptions and updated the TransactionUI sell method
Feb 28, 2015
1b7904d
Made some aesthetic changes
Feb 28, 2015
1a897e9
Updated TransactionUI and removed unnecessary Test class
Feb 28, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions MerchantRPGCSE2102/rpgclass diagram.mgc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<ClassDiagram>
<Class name="model.Player" x="873" y="252">
<AttributesDisplayFilter public-accepted="true"
private-accepted="true" protected-accepted="true"
default-accepted="true" static-accepted="false"/>
<MethodDisplayFilter public-accepted="true"
private-accepted="false" protected-accepted="false"
default-accepted="false" static-accepted="false"
accessors-accepted="false" constructors-accepted="false"/>
<Association destinationClassName="model.Item"
endpointName="_playerInventory" kind="Simple"/>
</Class>
<Class name="controller.RPGame" x="598" y="68">
<AttributesDisplayFilter public-accepted="true"
private-accepted="true" protected-accepted="true"
default-accepted="true" static-accepted="false"/>
<MethodDisplayFilter public-accepted="true"
private-accepted="false" protected-accepted="false"
default-accepted="false" static-accepted="false"
accessors-accepted="false" constructors-accepted="false"/>
</Class>
<Class name="model.Item" x="635" y="566">
<AttributesDisplayFilter public-accepted="true"
private-accepted="true" protected-accepted="true"
default-accepted="true" static-accepted="false"/>
<MethodDisplayFilter public-accepted="true"
private-accepted="false" protected-accepted="false"
default-accepted="false" static-accepted="false"
accessors-accepted="false" constructors-accepted="false"/>
</Class>
<Class name="model.Merchant" x="375" y="243">
<AttributesDisplayFilter public-accepted="true"
private-accepted="true" protected-accepted="true"
default-accepted="true" static-accepted="false"/>
<MethodDisplayFilter public-accepted="true"
private-accepted="false" protected-accepted="false"
default-accepted="false" static-accepted="false"
accessors-accepted="false" constructors-accepted="false"/>
<Association destinationClassName="model.Item"
endpointName="_merchantInventory" kind="Simple"/>
<Communication destinationClassName="model.Item"/>
</Class>
</ClassDiagram>
121 changes: 109 additions & 12 deletions MerchantRPGCSE2102/src/controller/RPGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@
import java.util.ArrayList;
import java.util.Scanner;

import model.Merchant;
import model.Player;

public class RPGame {
private ArrayList<String> merchantInventoryList1 = new ArrayList<String>(); // merchant 1's inventory list
private ArrayList<String> merchantInventoryList2 = new ArrayList<String>(); // merchant 2's inventory list
private ArrayList<String> merchantInventoryList3 = new ArrayList<String>(); // merchant 3's inventory list
private ArrayList<String> playerInventoryList = new ArrayList<String>(); // the player's inventory list
private Player _player;
private Merchant _merchant1;
private Merchant _merchant2;
private Merchant _merchant3;
private boolean _movement;

public RPGame() {
//constructor
}

/**
* This method scans the inventory.txt file located in src\config. It will read lines of the format <stringname> <price> and store them in the inventory list member variables
*
Expand All @@ -26,32 +34,54 @@ public void inventoryFromFile() {
int currentMerchant = 0; // keeps track of which merchant's inventory the scanner is reading
String token = null;
String item = null;
while(fileScanner.hasNextLine()) { // loops as long as there is another line to read

while(fileScanner.hasNextLine()) { // loops as long as there is another line to read
token = fileScanner.next();
if (token.equals("merchant"))
currentMerchant = fileScanner.nextInt();
else {
item = token + " " + fileScanner.nextInt(); // a string containing the item name and price
item = token + " " + fileScanner.nextInt(); // a string containing the item name and price
if (currentMerchant == 1)
merchantInventoryList1.add(item);
else if (currentMerchant == 2)
merchantInventoryList2.add(item);
else
else if (currentMerchant == 3)
merchantInventoryList3.add(item);
playerInventoryList.add(item);
}
if (fileScanner.hasNextLine()) // only advances to the next line if there is one to read
if (fileScanner.hasNextLine()) // only advances to the next line if there is one to read
fileScanner.nextLine();
}
} catch (FileNotFoundException e) { // if inventory.txt is deleted or missing

} catch (FileNotFoundException e) { // if inventory.txt is deleted or missing
System.out.println("Inventory file not found");
e.printStackTrace();
}

}


/**
* Generates all three merchants
* will add them to the map, but function is not written yet
*/
public void buildMerchants()
{
_merchant1 = new Merchant("Merchant 1", 1000, merchantInventoryList1);
_merchant2 = new Merchant("Merchant 2", 1000, merchantInventoryList2);
_merchant3 = new Merchant("Merchant 3", 1000, merchantInventoryList3);
}

/**
* Generates the player
* @param name Player name
* @param startingCash Amount of cash the player starts with
* @param startingInventory The Player's starting inventory
*/
public void buildPlayer(String name, int startingCash, ArrayList<String> startingInventory)
{
_player = new Player(name, startingCash, startingInventory);
}

/**
* This method returns the specified merchant inventory list
*
Expand All @@ -71,8 +101,7 @@ else if (merchantNumber == 3)
return null;
}
}



/**
* This method returns the player's inventory list
*
Expand All @@ -81,4 +110,72 @@ else if (merchantNumber == 3)
public ArrayList<String> getPlayerInventoryList() {
return playerInventoryList;
}

/**
* This method will create a new instance of Transaction which runs independently
*
* @param player
* @param targetMerchant The merchant that the player is trading with
*/
public void createTransaction(Player player, Merchant targetMerchant)
{
toggleMovement("OFF");
Transaction newTransaction = new Transaction(player, targetMerchant);
toggleMovement("ON");
}

/**
* Toggles the movement on or off based on the input
* @param command either "ON" or "OFF"
*/
public void toggleMovement(String command)
{
if(command.equals("ON"))
_movement = true;
else if(command.equals("OFF"))
_movement = false;
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;
}

/**
* Main method used to test the GUI components since test classes do not maintain the GUI
* @param args no need for input
*/
public static void main(String[] args)
{
RPGame _rpg = new RPGame();
_rpg.inventoryFromFile();
_rpg.buildMerchants();
ArrayList<String> playerInventory = _rpg.getMerchantInventoryList(1);
playerInventory.addAll(_rpg.getMerchantInventoryList(2));
playerInventory.addAll(_rpg.getMerchantInventoryList(3));
_rpg.buildPlayer("test", 500, playerInventory);
_rpg.getPlayer().getItem("armor").increaseQuantity(15);
_rpg.createTransaction(_rpg.getPlayer(), _rpg.getMerchant(1));
}
}
109 changes: 109 additions & 0 deletions MerchantRPGCSE2102/src/controller/Transaction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package controller;

import exceptions.NotInInventoryException;
import view.TransactionUI;
import model.Item;
import model.Merchant;
import model.Player;

public class Transaction
{
private Player _player;
private Merchant _targetMerchant;
private TransactionUI _window;

public Transaction(Player player, Merchant targetMerchant)
{
_player = player;
_targetMerchant = targetMerchant;
_window = new TransactionUI(this);
_window.setVisible(true);
}

/**
* Will be Transaction class's main method
* incomplete method
*/
public void runTransaction()
{
}

/**
* This method invokes the related buy methods and checks in the Player and Merchant classes
*
* @param itemName name of the item
* @param amount amount that the player wants to buy
* @return returns true if transaction successful, false otherwise
*/
public boolean actionBuy(String itemName, int amount)
{
if(_player.buy(itemName, _targetMerchant, amount))
return true;
else
return false;
}

/**
* This method invokes the related sell methods and checks in the Player and Merchant classes
*
* @param itemName name of the item
* @param amount amount that the player wants to buy
* @return returns true if transaction successful, false otherwise
* @throws NotInInventoryException
*/
public boolean actionSell(String itemName, int amount) throws NotInInventoryException
{
if(_player.sell(itemName, _targetMerchant, amount))
return true;
else
return false;
}

/**
* This method will push a true up to the class calling it
* incomplete method
* @return returns true
*/
public boolean actionCancel()
{
return true;
}

/**
* Searches the player inventory for the item matching the item name
* @param itemName name of the item
* @return returns the item with the corresponding name
*/
public Item searchPlayerInventory(String itemName)
{
return _player.getItem(itemName);
}

/**
* Searches the merchant's inventory for the item matching the item name
* @param itemName name of the item
* @return returns item with the corresponding name
*/
public Item searchMerchantInventory(String itemName)
{
return _targetMerchant.getItem(itemName);
}

/**
* 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;
}
}
10 changes: 10 additions & 0 deletions MerchantRPGCSE2102/src/exceptions/NotInInventoryException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package exceptions;

@SuppressWarnings("serial")
public class NotInInventoryException extends Exception
{
public NotInInventoryException()
{
super();
}
}
35 changes: 35 additions & 0 deletions MerchantRPGCSE2102/src/graph/Edge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package graph;


public class Edge {
private Vertex _v;
private Vertex _w;


public Vertex getV() {
return _v;
}

public void setV(Vertex v) {
_v = v;
}

public Vertex getW() {
return _w;
}

public void setW(Vertex w) {
_w = w;
}

public Vertex opposite(Vertex v) {
if (v == _v)
return _w;
else if (v == _w)
return _v;
return null;

}


}
Loading