Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
lul11003 committed Apr 11, 2015
1 parent d64b67e commit cebba3b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
42 changes: 41 additions & 1 deletion 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 Down Expand Up @@ -140,6 +141,7 @@ public void createTransaction(Player player, Merchant targetMerchant)
}
}


/**
* Will refresh number of transactions the Player has available
*
Expand Down Expand Up @@ -266,6 +268,44 @@ public static void main(String[] args) throws InterruptedException
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)
}
}
}
8 changes: 8 additions & 0 deletions MerchantRPGCSE2102/src/sprites/PlayerSprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ public void keyReleased(KeyEvent e) {
if (upBeingPressed == false) // Sprite will stop only when the UP key is not being pressed
dy = 0;
}
if (e.getKeyCode() == KeyEvent.VK_F){
if(collision()){
mapui.game.createTransaction(null, null);//RPGame initialize Trade
}
else{
return;
}
}

// This fixes some bugs with holding three keys down at once and letting go of two (Basically ensures that dx and dy match which keys are currently being held)
if(leftBeingPressed)
Expand Down
10 changes: 7 additions & 3 deletions MerchantRPGCSE2102/src/view/MapUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import javax.swing.JPanel;

import controller.RPGame;

import model.Map;
import sprites.MerchantSprite;
import sprites.PlayerSprite;
Expand All @@ -19,12 +21,14 @@
public class MapUI extends JPanel {

private Map map;
public RPGame game;
private PlayerSprite player;
private ArrayList<MerchantSprite> merchants = new ArrayList<MerchantSprite>();


public MapUI(Map map) {
public MapUI(Map map,RPGame Game) {
this.map = map;
this.game= Game;
addKeyListener(new KeyListener() {

@Override
Expand Down Expand Up @@ -70,7 +74,7 @@ public void paint(Graphics g) {
for (MerchantSprite merchant : merchants)
merchant.paint(g2d);

// For testing purposes. Showes the Player's current x and y position as well as the current Vertex
// For testing purposes. Shows the Player's current x and y position as well as the current Vertex
g2d.setColor(Color.GRAY);
g2d.setFont(new Font("Verdana", Font.BOLD, 20));
g2d.drawString("x: " + player.getX() + " y : " + player.getY(), 10, 20);
Expand All @@ -87,7 +91,7 @@ public void addMerchantSprite(int row, int col) {
MerchantSprite merchant = new MerchantSprite(row, col);
merchants.add(merchant);
}

/**
* Creates a player sprite to be painted on the canvas
* @param row The row of the player
Expand Down

0 comments on commit cebba3b

Please sign in to comment.