Package com.csse3200.game.services
Class CurrencyService
java.lang.Object
com.csse3200.game.services.CurrencyService
Service for managing in-level currency.
-
Constructor Summary
ConstructorsConstructorDescriptionCurrencyService
(int initialAmount, int maxAmount) Creates a new currency service with the specified initial amount and maximum limit. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int amount) Adds a positive amount to the currency.boolean
canAfford
(int amount) Checks if the specified amount is affordable.int
get()
Gets the currency amount.void
set
(int amount) Sets the currency amount.boolean
spend
(int amount) Attempts to spend the specified amount if affordable.
-
Constructor Details
-
CurrencyService
public CurrencyService(int initialAmount, int maxAmount) Creates a new currency service with the specified initial amount and maximum limit.- Parameters:
initialAmount
- starting currency amountmaxAmount
- maximum currency cap
-
-
Method Details
-
get
public int get()Gets the currency amount.- Returns:
- the currency amount
-
set
public void set(int amount) Sets the currency amount.- Parameters:
amount
- the new amount
-
add
public void add(int amount) Adds a positive amount to the currency.- Parameters:
amount
- the amount to add
-
spend
public boolean spend(int amount) Attempts to spend the specified amount if affordable.- Parameters:
amount
- the amount to spend- Returns:
- true if successful, false if insufficient funds
-
canAfford
public boolean canAfford(int amount) Checks if the specified amount is affordable.- Parameters:
amount
- the amount to check- Returns:
- true if affordable, false otherwise
-