Skip to content

Commit

Permalink
Merge pull request #25 from gal11002/master
Browse files Browse the repository at this point in the history
Master into William-C
  • Loading branch information
wkc12001 committed Apr 11, 2015
2 parents b40a4a0 + 0541699 commit 461a56a
Show file tree
Hide file tree
Showing 14 changed files with 481 additions and 110 deletions.
3 changes: 2 additions & 1 deletion MerchantRPGCSE2102/.classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="junit-4.11.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
6 changes: 3 additions & 3 deletions MerchantRPGCSE2102/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.source=1.6
35 changes: 27 additions & 8 deletions MerchantRPGCSE2102/src/config/inventory.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
merchant 1
water 3
armor 5
food 10
Water 2
Candy 5
Apple 7
Bread 3
Cake 14
Jerky 9
merchant 2
wood 3
tarp 6
PigIron 19
HighQualityIron 25
Steel 29
WoodPlanks 10
HighQualityWood 18
FairyTreeWood 40
WornSword 23
IronSword 29
SteelSword 38
FairySteelSword 95
BlessedIronDaggerofPig 50000
merchant 3
glass 3
tape 13
rope 5
LooseGems 60
FineCutDiamond 70
SilverBracelets 85
SilverNecklace 93
SilverEmeraldRing 100
GoldBracelets 84
GoldNecklace 103
GoldSapphireRing 133
GoldDiamondCrown 210
ExpensiveJewlery? 500
74 changes: 62 additions & 12 deletions MerchantRPGCSE2102/src/controller/RPGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javax.swing.JFrame;

import model.Map;
import model.Merchant;
import model.Player;
import view.MapUI;
Expand All @@ -20,7 +21,7 @@ public class RPGame {
private ArrayList<String> playerInventoryList = new ArrayList<String>(); // the player's inventory list
private Player _player;
private Merchant _merchant1, _merchant2, _merchant3;
private boolean _movement;
public boolean _movement;
private int _currentDay;
private int _transactionLimit;

Expand Down Expand Up @@ -74,9 +75,9 @@ else if (currentMerchant == 3)
*/
public void buildMerchants()
{
_merchant1 = new Merchant("Merchant 1", 1000, merchantInventoryList1);
_merchant2 = new Merchant("Merchant 2", 1000, merchantInventoryList2);
_merchant3 = new Merchant("Merchant 3", 1000, merchantInventoryList3);
_merchant1 = new Merchant("Cheap Merchant", 200, merchantInventoryList1);
_merchant2 = new Merchant("Medium Merchant", 600, merchantInventoryList2);
_merchant3 = new Merchant("Expensive Merchant", 1000, merchantInventoryList3);
}

/**
Expand Down Expand Up @@ -130,8 +131,7 @@ public void createTransaction(Player player, Merchant targetMerchant)
if(_transactionLimit > 0)
{
toggleMovement("OFF");
Transaction newTransaction = new Transaction(player, targetMerchant);
toggleMovement("ON");
Transaction newTransaction = new Transaction(player, targetMerchant, this);
_transactionLimit -= 1;
}
else
Expand All @@ -140,6 +140,7 @@ public void createTransaction(Player player, Merchant targetMerchant)
}
}


/**
* Will refresh number of transactions the Player has available
*
Expand All @@ -163,11 +164,13 @@ public void advanceDailyCycle(){

scaleAllMerchantPrices(allMerchants); //will scale all the prices of the items that the merchants hold based on their dailyRandomPercent

if( (_currentDay % 3) == 0) //will increase the merchant's base cash every 3 days
if( (_currentDay % 6) == 0) //will increase the merchant's base cash every 6 days
{
addAndRefreshCash(_merchant1, 100);
addAndRefreshCash(_merchant2, 100);
addAndRefreshCash(_merchant3, 100);
int multiplier = (int) Math.floor(_currentDay / 10) + 1;

addAndRefreshCash(_merchant1, multiplier * 100);
addAndRefreshCash(_merchant2, multiplier * 100);
addAndRefreshCash(_merchant3, multiplier * 100);
}
else //if not on a third day, will just refresh the merchant's cash amount
{
Expand Down Expand Up @@ -251,6 +254,15 @@ public int getDay()
{
return _currentDay;
}

/**
*
* @return Movement variable
*/
public boolean getMovement()
{
return _movement;
}

/**
* Main method used to test the GUI components since test classes do not maintain the GUI
Expand All @@ -265,7 +277,45 @@ public static void main(String[] args) throws InterruptedException
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));

// SETTING UP PLAYER AND MERCHANT
Player player = new Player("Player", 0, null);
Merchant merch1 = new Merchant("Bill", 0, null);
Merchant merch2 = new Merchant("Joe", 0, null);
Merchant merch3 = new Merchant("Sam", 0, null);

// CREATING MAP AND INITIALIZE PLAYER AND MERCHANTS
Map map = new Map(30, 40);
map.initializePlayer(player, 15, 20);
map.initializeMerchant(merch1, 15, 0);
map.initializeMerchant(merch2, 29, 20);
map.initializeMerchant(merch3, 15, 39);

// CREATING JFRAME WINDOW
JFrame frame = new JFrame("Merchant RPG");

// CREATING MAPUI AND SPRITES
MapUI mapui = new MapUI(map,_rpg);
mapui.createPlayerSprite(15, 20);
mapui.addMerchantSprite(15, 0);
mapui.addMerchantSprite(29, 20);
mapui.addMerchantSprite(15, 39);

// ADDING MAPUI TO JFRAME
frame.add(mapui);

// SETTING PROPERTIES OF JFRAME
frame.setSize(RPGame.WIDTH, RPGame.HEIGHT);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);

// MAIN GAME LOOP
while (true) {
mapui.move();
mapui.repaint();
Thread.sleep(100/12); // Controls the speed of the game (currently 120 frames/second)
}
}
}
22 changes: 11 additions & 11 deletions MerchantRPGCSE2102/src/controller/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public class Transaction
private Player _player;
private Merchant _targetMerchant;
private TransactionUI _window;
private RPGame _game;

public Transaction(Player player, Merchant targetMerchant)
public Transaction(Player player, Merchant targetMerchant, RPGame game)
{
_player = player;
_targetMerchant = targetMerchant;
_game = game;
_window = new TransactionUI(this);
_window.setVisible(true);
}
Expand Down Expand Up @@ -61,16 +63,6 @@ public boolean actionSell(String itemName, int amount) throws NotInInventoryExce
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
Expand All @@ -91,6 +83,14 @@ public Item searchMerchantInventory(String itemName)
return _targetMerchant.getItem(itemName);
}

/**
* Toggles the RPGame movement back on
*/
public void endTransaction()
{
_game.toggleMovement("ON");
}

/**
* Returns the player in transaction
* @return returns the player
Expand Down
Binary file added MerchantRPGCSE2102/src/images/testsprite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion MerchantRPGCSE2102/src/model/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Map {

private Graph _mapGraph; // Graph representation of the map
private int _rows, _cols; // The n*n dimension of the map
private int[] initialPlayerLocation = new int[2];
private Player _player;

public Map(int rows, int cols) {
Expand All @@ -22,7 +23,9 @@ public Map(int rows, int cols) {
* @param column The column of the player's location
*/
public void initializePlayer(Player player, int row, int col) {
_player = player;
_player = player;
initialPlayerLocation[0] = row;
initialPlayerLocation[1] = col;
int vertexNum = row*_cols + col;
player.setCol(col);
player.setRow(row);
Expand Down Expand Up @@ -134,6 +137,11 @@ public boolean collisionTo(String direction) {
return false;
}

public void resetPlayerLocation() {
_player.setCol(initialPlayerLocation[1]);
_player.setRow(initialPlayerLocation[0]);
}

public Player getPlayer() {
return _player;
}
Expand Down
104 changes: 104 additions & 0 deletions MerchantRPGCSE2102/src/sprites/Animation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package sprites;

import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;


public class Animation {

private int frameCount; // Counts ticks for change
private int frameDelay; // frame delay 1-12 (You will have to play around with this)
private int currentFrame; // animations current frame
private int animationDirection; // animation direction (i.e counting forward or backward)
private int totalFrames; // total amount of frames for your animation

private boolean stopped; // has animations stopped

private List<Frame> frames = new ArrayList<Frame>(); // Arraylist of frames

public Animation(BufferedImage[] frames, int frameDelay) {
this.frameDelay = frameDelay;
this.stopped = true;

for (int i = 0; i < frames.length; i++) {
addFrame(frames[i], frameDelay);
}

this.frameCount = 0;
this.frameDelay = frameDelay;
this.currentFrame = 0;
this.animationDirection = 1;
this.totalFrames = this.frames.size();

}

public void start() {
if (!stopped) {
return;
}

if (frames.size() == 0) {
return;
}

stopped = false;
}

public void stop() {
if (frames.size() == 0) {
return;
}

stopped = true;
}

public void restart() {
if (frames.size() == 0) {
return;
}

stopped = false;
currentFrame = 0;
}

public void reset() {
this.stopped = true;
this.frameCount = 0;
this.currentFrame = 0;
}

private void addFrame(BufferedImage frame, int duration) {
if (duration <= 0) {
System.err.println("Invalid duration: " + duration);
throw new RuntimeException("Invalid duration: " + duration);
}

frames.add(new Frame(frame, duration));
currentFrame = 0;
}

public BufferedImage getSprite() {
return frames.get(currentFrame).getFrame();
}

public void update() {
if (!stopped) {
frameCount++;

if (frameCount > frameDelay) {
frameCount = 0;
currentFrame += animationDirection;

if (currentFrame > totalFrames - 1) {
currentFrame = 0;
}
else if (currentFrame < 0) {
currentFrame = totalFrames - 1;
}
}
}

}

}
Loading

0 comments on commit 461a56a

Please sign in to comment.