public class Coins extends Object
Represents in-game currency. This object handles all currency conversion. For example, given 15310 copper:
Coins coins = new Coins(15310);
System.out.println(coins.goldValue()); // 1.0
System.out.println(coins.silverValue()); // 53.0
System.out.println(coins.copperValue()); // 10.0
Constructor and Description |
---|
Coins()
Create an instance with the value set to
0 . |
Coins(int amount)
Create an instance with the value set to
amount . |
Coins(String amount)
Same as
Coins(int) . |
Modifier and Type | Method and Description |
---|---|
void |
addCopper(int copper)
Increase the instance's value by the specified number of
in-game copper.
|
void |
addGold(int gold)
Increase the instance's value by the specified number of
in-game gold.
|
void |
addSilver(int silver)
Increase the instance's value by the specified number of
in-game silver.
|
double |
copperValue()
The number of in-game copper the instance represents.
|
double |
getValue()
Retrieve the actual value the instance represents.
|
double |
goldValue()
The number of in-game gold the instance represents.
|
void |
setAmount(int amount)
Set the instance's actual value to a specific number of coins.
|
void |
setAmount(int gold,
int silver,
int copper)
Set the instance's actual value to a specific number of coins as
represented by the in-game currency denominations.
|
double |
silverValue()
The number of in-game silver the instance represents.
|
void |
subtractCopper(int copper)
Decrease the instance's value by the specified number of
in-game copper.
|
void |
subtractGold(int gold)
Decrease the instance's value by the specified number of
in-game gold.
|
void |
subtractSilver(int silver)
Decrease the instance's value by the specified number of
in-game silver.
|
public Coins()
0
.public Coins(int amount)
amount
.amount
- The initial number of coins in "copper".public Coins(String amount)
Coins(int)
.
Only used for deserialization.amount
- The initial number of coins in "copper".public double getValue()
public double goldValue()
public double silverValue()
public double copperValue()
public void addGold(int gold)
gold
- A number of gold coins.public void addSilver(int silver)
silver
- A number of silver coins.public void addCopper(int copper)
copper
- A number of copper coins.public void subtractGold(int gold)
gold
- A number of gold coins.public void subtractSilver(int silver)
silver
- A number of silver coins.public void subtractCopper(int copper)
copper
- A number of copper coins.public void setAmount(int amount)
amount
- The amount of coins this instance should represent.public void setAmount(int gold, int silver, int copper)
gold
- The number of gold coins this instance should represent.silver
- The number of silver coins this instance should represent.copper
- The number of copper coins this instance should represent.Copyright © 2014. All Rights Reserved.