Skip to content

Commit

Permalink
Merge pull request #11 from gal11002/Gavin-L
Browse files Browse the repository at this point in the history
Gavin l
  • Loading branch information
gal11002 committed Feb 28, 2015
2 parents 3e3bc27 + 1a897e9 commit 81a96e6
Show file tree
Hide file tree
Showing 16 changed files with 1,119 additions and 30 deletions.
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

0 comments on commit 81a96e6

Please sign in to comment.