public class Market
extends com.badlogic.gdx.scenes.scene2d.ui.Table
Modifier and Type | Field and Description |
---|---|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
auctionButton
Button to move from market to auction
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
buyEnergy
Button in the market's interface that buys energy
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
buyFood
Button in the market's interface that buys food
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
buyOre
Button in the market's interface that buys ore
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
buyRoboticon
Button in the market's interface that buys Roboticons
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
confirmSale
button to confirm a trade
|
private com.mygdx.game.Drawer |
drawer
Object defining QOL drawing functions for rectangles and on-screen tables
Used in this class to simplify row creation in tables
|
private int |
EnergyBuyPrice
Variable holding energy resource buying price.
|
private int |
EnergySellPrice
Variable holding energy resource selling price.
|
private int |
EnergyStock
Variable holding current Energy resource amount as an int, initialises at 16 as stated in the brief.
|
private com.badlogic.gdx.scenes.scene2d.ui.Label |
energyStockLabel
Visualises the amount of energy stocks currently held by the market
|
private int |
energyTradeAmount
variable storing amount of energy to be traded
|
private com.badlogic.gdx.scenes.scene2d.ui.Label |
energyTradeLabel
label to show amount of energy being traded
|
private com.mygdx.game.GameEngine |
engine
Engine class that handles all of the game's logical processing
|
private int |
FoodBuyPrice
Variable holding food resource buying price.
|
private int |
FoodSellPrice
Variable holding food resource selling price.
|
private int |
FoodStock
Variable holding current Food resource amount as an int, initialises at 16 as stated in the brief.
|
private com.badlogic.gdx.scenes.scene2d.ui.Label |
foodStockLabel
Visualises the amount of food stocks currently held by the market
|
private int |
foodTradeAmount
variable storing amount of food to be traded
|
private com.badlogic.gdx.scenes.scene2d.ui.Label |
foodTradeLabel
label to show amount of food being traded
|
private com.badlogic.gdx.Game |
game
Holds game-state
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
marketButton
button to move from market to auction
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
nextPlayerButton
move forward through list of players you want to trade with in auction
|
private int |
OreBuyPrice
Variable holding ore resource buying price.
|
private int |
OreSellPrice
Variable holding ore resource selling price.
|
private int |
OreStock
Variable holding current Ore resource amount as an int, initialises at 0 as stated in the brief.
|
private com.badlogic.gdx.scenes.scene2d.ui.Label |
oreStockLabel
Visualises the amount of ore stocks currently held by the market
|
private int |
oreTradeAmount
variable storing amount of ore to be traded
|
private com.badlogic.gdx.scenes.scene2d.ui.Label |
oreTradeLabel
label to show amount of ore being traded
|
private com.badlogic.gdx.utils.Array<com.mygdx.game.Player> |
otherPlayer
a list of players that the current player can trade with
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
playerBuyEnergy
Button to add energy to a trade
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
playerBuyFood
Button to add food to a trade
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
playerBuyOre
Button to add ore to a trade
|
private com.badlogic.gdx.scenes.scene2d.ui.Label |
playerLabel
Label to show which player a trade is going to be sent to
|
private int |
playerListPosition
current position in other player list in auction
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
playerSellEnergy
Button to remove energy from a trade
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
playerSellFood
Button to remove food from a trade
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
playerSellOre
Button to remove ore from a trade
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
prevPlayerButton
move backwardward through list of players you want to trade with in auction
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
priceMinus1
button to take 1 from the price of a trade
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
priceMinus10
button to take 10 from the price of a trade
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
priceMinus100
button to take 100 from price of a trade
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
pricePlus1
button to add 1 to the price of a trade
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
pricePlus10
button to add 10 to the price of a trade
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
pricePlus100
button to add 100 to the price of a trade
|
private int |
RoboticonBuyPrice
Variable holding roboticon buying price.
|
private int |
RoboticonStock
Variable holding current amount of Roboticons as an int, initialises at 12 as stated in the brief.
|
private com.badlogic.gdx.scenes.scene2d.ui.Label |
roboticonStockLabel
Visualises the amount of Roboticon stocks currently held by the market
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
sellEnergy
Button in the market's interface that sells the current player's energy stocks to the market
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
sellFood
Button in the market's interface that sells the current player's food stocks to the market
|
private com.badlogic.gdx.scenes.scene2d.ui.TextButton |
sellOre
Button in the market's interface that sells the current player's ore stocks to the market
|
private com.mygdx.game.TTFont |
tableFont
Defines the font of the text comprising the market's interface
|
private int |
tradePrice
variable storing price of trade
|
private com.badlogic.gdx.scenes.scene2d.ui.Label |
tradePriceLabel
label to show the price of a trade
|
Constructor and Description |
---|
Market(com.badlogic.gdx.Game game,
com.mygdx.game.GameEngine engine)
Constructs the market by calculating buying/selling costs and arranging the associated visual interface
Imports the game's state (for direct renderer access) and the engine which controls it, before setting up
the functions and visual features of its internal purchase/sale buttons and populating a drawable visual
framework with them and some other stock/identification labels
|
Modifier and Type | Method and Description |
---|---|
com.mygdx.game.Player |
buy(java.lang.String Stock_Type,
int Quantity,
com.mygdx.game.Player Player)
A method that allows buying resources from the market.
|
private int |
calculateNewCost(int Stock,
java.lang.String oper)
A method that calculates cost of market selling and buying prices.
|
private void |
constructAuctionInterface()
Builds the auction's visual interface by populating it with labels and buttons
Once this method has finished executing, the market can be drawn to a stage like any other actor
|
private void |
constructButtons()
Instantiates the purchase/sale buttons to be placed in the market and sets their on-click functions
Obviously, these buttons enable players to buy and sell resources during certain game-phases
|
private void |
constructInterface()
Builds the market's visual interface by populating it with labels and buttons
Once this method has finished executing, the market can be drawn to a stage like any other actor
|
java.lang.Boolean |
gamble(int amountToGamble,
com.mygdx.game.Player Player)
A method that allows gambling as specified in the brief.
|
int |
getEnergyBuyPrice()
Getter for EnergyBuyPrice.
|
int |
getEnergySellPrice()
Getter for EnergySellPrice
|
int |
getEnergyStock()
Getter for EnergyStock
|
int |
getFoodBuyPrice()
Getter for FoodBuyPrice.
|
int |
getFoodSellPrice()
Getter for FoodSellPrice
|
int |
getFoodStock()
Getter for FoodStock
|
int |
getOreBuyPrice()
Getter for OreBuyPrice.
|
int |
getOreSellPrice()
Getter for OreSellPrice
|
int |
getOreStock()
Getter for OreStock
|
int |
getRoboticonBuyPrice()
Getter for RoboticonBuyPrice
|
int |
getRoboticonStock()
Returns the number of Roboticons currently held in the market
|
void |
produceRoboticon()
allows the market to get it's inventory of roboticons up to 10 so long as it has
at least 10 ore, each roboticon costs 3 ore
|
void |
refreshAuction()
Enables and disables various buttons in the auction based on the players inventory and the value
of the current resources and price of the current trade
|
void |
refreshButtonAvailability()
Enables/disables the market's purchase/sale buttons and updates their colours to reflect the player's current
amount of money, the game's current phase and the player's inventory
GRAY: Cannot buy/sell resource on the current phase
GREEN: Can buy/sell resource
RED: Cannot buy/sell resource due to a lack of money or stock
|
void |
refreshPlayers()
updates the other player list so all players except the current player are in it
|
com.mygdx.game.Player |
sell(java.lang.String Stock_Type,
int Quantity,
com.mygdx.game.Player Player)
A method that allows selling resources to the market.
|
void |
setEnergyBuyPrice(int NewEnergyBuyPrice)
Setter for EnergyBuyPrice.
|
void |
setEnergySellPrice(int NewEnergySellPrice)
Setter for EnergySellPrice.
|
void |
setEnergyStock(int NewEnergyStock)
Setter for EnergyStock.
|
void |
setFoodBuyPrice(int NewFoodBuyPrice)
Setter for FoodBuyPrice.
|
void |
setFoodSellPrice(int NewFoodSellPrice)
Setter for FoodSellPrice.
|
void |
setFoodStock(int NewFoodStock)
Setter for FoodStock.
|
void |
setOreBuyPrice(int NewOreBuyPrice)
Setter for OreBuyPrice.
|
void |
setOreSellPrice(int NewOreSellPrice)
Setter for OreSellPrice.
|
void |
setOreStock(int NewOreStock)
Setter for OreStock.
|
void |
setPlayerListPosition(int i) |
void |
setRoboticonBuyPrice(int NewRoboticonBuyPrice)
Setter for RoboticonBuyPrice
|
void |
setRoboticonStock(int NewRoboticonStock)
Sets the market's Roboticon stock level
Also updates the appropriate stock label to reflect the new quantity given
|
add, add, add, add, add, add, add, align, background, background, bottom, center, clearChildren, columnDefaults, debug, debug, debugActor, debugAll, debugCell, debugTable, defaults, draw, drawBackground, drawDebug, drawDebugBounds, getAlign, getBackground, getCell, getCells, getClip, getColumns, getColumnWidth, getMinHeight, getMinWidth, getPadBottom, getPadBottomValue, getPadLeft, getPadLeftValue, getPadRight, getPadRightValue, getPadTop, getPadTopValue, getPadX, getPadY, getPrefHeight, getPrefWidth, getRow, getRowHeight, getRows, getSkin, getTableDebug, hit, invalidate, layout, left, pad, pad, pad, pad, padBottom, padBottom, padLeft, padLeft, padRight, padRight, padTop, padTop, removeActor, removeActor, reset, right, row, setBackground, setBackground, setClip, setDebug, setRound, setSkin, stack, top
childrenChanged, getMaxHeight, getMaxWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
act, addActor, addActorAfter, addActorAt, addActorBefore, applyTransform, applyTransform, clear, computeTransform, drawChildren, drawDebugChildren, findActor, getChildren, getCullingArea, hasChildren, isTransform, localToDescendantCoordinates, resetTransform, resetTransform, setCullingArea, setDebug, setStage, setTransform, swapActor, swapActor, toString
addAction, addCaptureListener, addListener, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasParent, isAscendantOf, isDescendantOf, isTouchable, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront
private com.badlogic.gdx.Game game
private com.mygdx.game.GameEngine engine
private com.mygdx.game.Drawer drawer
private com.mygdx.game.TTFont tableFont
private int OreStock
private int FoodStock
private int EnergyStock
private int RoboticonStock
private int OreSellPrice
private int FoodSellPrice
private int EnergySellPrice
private int OreBuyPrice
private int FoodBuyPrice
private int EnergyBuyPrice
private int RoboticonBuyPrice
private com.badlogic.gdx.scenes.scene2d.ui.TextButton buyOre
private com.badlogic.gdx.scenes.scene2d.ui.TextButton buyFood
private com.badlogic.gdx.scenes.scene2d.ui.TextButton buyEnergy
private com.badlogic.gdx.scenes.scene2d.ui.TextButton buyRoboticon
private com.badlogic.gdx.scenes.scene2d.ui.TextButton sellOre
private com.badlogic.gdx.scenes.scene2d.ui.TextButton sellFood
private com.badlogic.gdx.scenes.scene2d.ui.TextButton sellEnergy
private com.badlogic.gdx.scenes.scene2d.ui.Label oreStockLabel
private com.badlogic.gdx.scenes.scene2d.ui.Label foodStockLabel
private com.badlogic.gdx.scenes.scene2d.ui.Label energyStockLabel
private com.badlogic.gdx.scenes.scene2d.ui.Label roboticonStockLabel
private com.badlogic.gdx.scenes.scene2d.ui.TextButton marketButton
private com.badlogic.gdx.scenes.scene2d.ui.TextButton auctionButton
private com.badlogic.gdx.scenes.scene2d.ui.TextButton playerBuyOre
private com.badlogic.gdx.scenes.scene2d.ui.TextButton playerBuyEnergy
private com.badlogic.gdx.scenes.scene2d.ui.TextButton playerBuyFood
private com.badlogic.gdx.scenes.scene2d.ui.TextButton playerSellOre
private com.badlogic.gdx.scenes.scene2d.ui.TextButton playerSellEnergy
private com.badlogic.gdx.scenes.scene2d.ui.TextButton playerSellFood
private int oreTradeAmount
private int energyTradeAmount
private int foodTradeAmount
private com.badlogic.gdx.scenes.scene2d.ui.TextButton confirmSale
private com.badlogic.gdx.scenes.scene2d.ui.TextButton pricePlus1
private com.badlogic.gdx.scenes.scene2d.ui.TextButton pricePlus10
private com.badlogic.gdx.scenes.scene2d.ui.TextButton pricePlus100
private com.badlogic.gdx.scenes.scene2d.ui.TextButton priceMinus1
private com.badlogic.gdx.scenes.scene2d.ui.TextButton priceMinus10
private com.badlogic.gdx.scenes.scene2d.ui.TextButton priceMinus100
private com.badlogic.gdx.scenes.scene2d.ui.Label oreTradeLabel
private com.badlogic.gdx.scenes.scene2d.ui.Label energyTradeLabel
private com.badlogic.gdx.scenes.scene2d.ui.Label foodTradeLabel
private int tradePrice
private com.badlogic.gdx.scenes.scene2d.ui.Label tradePriceLabel
private com.badlogic.gdx.scenes.scene2d.ui.TextButton nextPlayerButton
private com.badlogic.gdx.scenes.scene2d.ui.TextButton prevPlayerButton
private com.badlogic.gdx.scenes.scene2d.ui.Label playerLabel
private com.badlogic.gdx.utils.Array<com.mygdx.game.Player> otherPlayer
private int playerListPosition
public Market(com.badlogic.gdx.Game game, com.mygdx.game.GameEngine engine)
game
- The game's state, which is used in this context to operate the game's renderer via the Drawer classengine
- The game's engine, which directly controls the availability and prices of market resourcesprivate void constructButtons()
private void constructInterface()
private void constructAuctionInterface()
public int getRoboticonStock()
public void setRoboticonStock(int NewRoboticonStock)
NewRoboticonStock
- The new number of Roboticons to be held in the marketpublic int getRoboticonBuyPrice()
public void setRoboticonBuyPrice(int NewRoboticonBuyPrice)
NewRoboticonBuyPrice
- integer value that RoboticonBuyPrice is assigned to.public int getOreStock()
public void setOreStock(int NewOreStock)
NewOreStock
- integer value that OreStock is assigned to.public int getOreSellPrice()
public void setOreSellPrice(int NewOreSellPrice)
NewOreSellPrice
- integer value that OreSellPrice is set to.public int getOreBuyPrice()
public void setOreBuyPrice(int NewOreBuyPrice)
NewOreBuyPrice
- integer value that OreBuyPrice is set to.public int getFoodStock()
public void setFoodStock(int NewFoodStock)
NewFoodStock
- integer value that FoodStock is assigned to.public int getFoodSellPrice()
public void setFoodSellPrice(int NewFoodSellPrice)
NewFoodSellPrice
- integer value that FoodSellPrice is set to.public int getFoodBuyPrice()
public void setFoodBuyPrice(int NewFoodBuyPrice)
NewFoodBuyPrice
- integer value that FoodBuyPrice is set to.public int getEnergyStock()
public void setEnergyStock(int NewEnergyStock)
NewEnergyStock
- integer value that EnergyStock is assigned to.public int getEnergySellPrice()
public void setEnergySellPrice(int NewEnergySellPrice)
NewEnergySellPrice
- integer value that EnergySellPrice is set to.public int getEnergyBuyPrice()
public void setEnergyBuyPrice(int NewEnergyBuyPrice)
NewEnergyBuyPrice
- integer value that EnergyBuyPrice is set to.public com.mygdx.game.Player buy(java.lang.String Stock_Type, int Quantity, com.mygdx.game.Player Player) throws java.lang.Exception
Stock_Type
- Type of resources (ore, energy or food) that is stored in the market.Quantity
- The amount of resources that Player wants to buy.Player
- A Player object.java.lang.Exception
- for insufficient resourcespublic com.mygdx.game.Player sell(java.lang.String Stock_Type, int Quantity, com.mygdx.game.Player Player) throws java.lang.Exception
Depending on what type of resources it is passed ("ore", "food" or "energy") method checks whether the Player has sufficient amount (Quantity) of resource that he is willing to sell. Market stock value (e.g. OreStock) is increased by the quantity that has been sold by Player. Players money(playersMoney) are increased by the amount that was gotten by selling resources. The value of Player's resource is decreased by the amount that has been sold. New selling and buying prices, for that chosen resource, are calculated (calculateNewCost()).
Stock_Type
- Type of resources (ore, energy or food) that is stored in the market.Quantity
- The amount of resources that Player wants to buy.Player
- A Player object.java.lang.Exception
- when the seller has insufficient resources to sellpublic java.lang.Boolean gamble(int amountToGamble, com.mygdx.game.Player Player)
First it is checked whether a chosen amount of money is not higher than the total amount of Player's money. Number generator generates whether 0 or 1. If 0 is generated - Player loses and his money is reduced by the "amountToGamble". If 1 is generated - Player wins and his money is increased by the "amountToGamble".
amountToGamble
- The amount of money that is meant to be spent for gambling.Player
- A Player object.private int calculateNewCost(int Stock, java.lang.String oper) throws java.lang.Exception
When Stock value equals 0 and wanted operation is "buy", costOfResource value is set to 0. When Stock value is equal to 0 and wanted operation is "sell", costOfResource value is set to 200. If wanted operation is "buy", new buying price is calculated. If wanted operation is "sell", then new selling price is calculated.
Stock
- int values of market resources.oper
- String value representing operations "buy" and "sell".java.lang.Exception
- Thrown if there's a wrong operator used with the functionpublic void refreshButtonAvailability()
public void refreshAuction()
public void refreshPlayers()
public void setPlayerListPosition(int i)
public void produceRoboticon()