Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…GProject into John-B

Conflicts:
	MerchantRPGCSE2102/src/model/Map.java
  • Loading branch information
john committed Mar 7, 2015
2 parents 466d78e + 0d459d4 commit 80e9eec
Show file tree
Hide file tree
Showing 22 changed files with 893 additions and 330 deletions.
29 changes: 13 additions & 16 deletions MerchantRPGCSE2102/src/controller/RPGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
import java.util.ArrayList;
import java.util.Scanner;

import javax.swing.JFrame;

import model.Merchant;
import model.Player;
import view.MapUI;

public class RPGame {
public static final int WIDTH = 1206;
public static final int HEIGHT = 929;
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
Expand All @@ -35,12 +40,12 @@ public void inventoryFromFile() {
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)
Expand All @@ -49,11 +54,11 @@ 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();
}
Expand Down Expand Up @@ -112,8 +117,7 @@ public ArrayList<String> getPlayerInventoryList() {
}

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

/**
Expand Down Expand Up @@ -165,17 +170,9 @@ else if(merchantNum == 2)
/**
* Main method used to test the GUI components since test classes do not maintain the GUI
* @param args no need for input
* @throws InterruptedException
*/
public static void main(String[] args)
public static void main(String[] args) throws InterruptedException
{
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));
}
}
4 changes: 3 additions & 1 deletion MerchantRPGCSE2102/src/controller/Transaction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package controller;

import exceptions.NotInInventoryException;
import view.TransactionUI;
import model.Item;
import model.Merchant;
Expand Down Expand Up @@ -48,8 +49,9 @@ public boolean actionBuy(String itemName, int amount)
* @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)
public boolean actionSell(String itemName, int amount) throws NotInInventoryException
{
if(_player.sell(itemName, _targetMerchant, amount))
return true;
Expand Down
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();
}
}
40 changes: 24 additions & 16 deletions MerchantRPGCSE2102/src/graph/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
public class Graph
{
private Vertex[] _vertexList;
private int _size;
private int _rows;
private int _cols;

public Graph(int size)
public Graph(int rows, int cols)
{
_size = size;
_vertexList = new Vertex[size*size];
_rows = rows;
_cols = cols;
_vertexList = new Vertex[rows*cols];
}

public void initializeGraph() {
Expand All @@ -17,24 +19,25 @@ public void initializeGraph() {
}

public void initializeVertices() {
for (int row = 0; row < _size; row++) {
for (int col = 0; col < _size; col++) {
int cellNum = row*_size + col;
Vertex v = new Vertex(cellNum, _size);
for (int row = 0; row < _rows; row++) {
for (int col = 0; col < _cols; col++) {
int cellNum = row*_cols + col;
Vertex v = new Vertex(cellNum, row, col);
setVertex(cellNum, v);
}
}
}

public void initializeEdges() {
for (int row = 0; row < _size; row++) {
for (int col = 0; col < _size; col++) {
for (int row = 0; row < _rows; row++) {
for (int col = 0; col < _cols; col++) {

if (row !=0)
connectWithEdge(getVertex(_size*row + col), getVertex(_size*(row - 1) + col));
if (row !=0) {
connectWithEdge(getVertex(_cols*row + col), getVertex(_cols*(row - 1) + col));
}

if (col != _size - 1)
connectWithEdge(getVertex(_size*row + col), getVertex(_size*row + col + 1));
if (col != _cols - 1)
connectWithEdge(getVertex(_cols*row + col), getVertex(_cols*row + col + 1));
}
}
}
Expand All @@ -47,9 +50,14 @@ public void connectWithEdge(Vertex v, Vertex w) {
edge.setW(w);
}

public int getSize()
public int getRows()
{
return _size;
return _rows;
}

public int getCols()
{
return _cols;
}

public Vertex getVertex(int vertexNum)
Expand Down
11 changes: 3 additions & 8 deletions MerchantRPGCSE2102/src/graph/Vertex.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ public class Vertex
private LinkedList<Edge> _incidentEdges = new LinkedList<Edge>();


public Vertex(int cellNum, int n) {
public Vertex(int cellNum, int row, int col) {
_row = row;
_col = col;
_cellNum = cellNum;
_row = 0;
int temp = _cellNum;
while (temp - n >= 0) { // Calculates the row of the vertex
temp = temp - n;
_row++;
}
_col = _cellNum - _row*n; // Calculates the column of the vertex
}

public void addEdge(Edge edge) {
Expand Down
Binary file added MerchantRPGCSE2102/src/images/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MerchantRPGCSE2102/src/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions MerchantRPGCSE2102/src/model/Character.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package model;

public class Character {
private int _x, _y;
protected Item[] _inventory;
protected String _name;


/**
* Searches through the player's inventory for the item corresponding to the specified item name
*
* @param itemName string containing the name of the item
* @return the item matching the specified item name
*/
public Item getItem(String itemName)
{
for(int i = 0; i < _inventory.length; i++)
{
if(_inventory[i].getItemName().equals(itemName))
return _inventory[i];
}

System.out.println("No such item exists"); // item was not found by searching the inventory
return null;
}

/**
* Returns the merchant's item inventory
* @return item inventory array
*/
public Item[] getInventory()
{
return _inventory;
}

/**
* Returns a string containing the name of the merchant
*
* @return merchant name string
*/
public String getName()
{
return _name;
}

public int getX() {
return _x;
}

public void setX(int x) {
_x = x;
}

public int getY() {
return _y;
}

public void setY(int y) {
_y = y;
}



}
3 changes: 1 addition & 2 deletions MerchantRPGCSE2102/src/model/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Item(String itemName, int basePrice, int quantity)
* @return adjusted price integer
*
*/
public int scaleAdjPrice(double merchantPercent)
public void scaleAdjPrice(double merchantPercent)
{
int calculatedPrice = (int) Math.floor((merchantPercent / 100) * _basePrice); //will find the floor of the price to prevent decimals

Expand All @@ -48,7 +48,6 @@ else if(calculatedPrice < _minPrice)
_adjustedPrice = _minPrice;
else
_adjustedPrice = calculatedPrice;
return _adjustedPrice;
}

/**
Expand Down
Loading

0 comments on commit 80e9eec

Please sign in to comment.