Currency Manager API - HY-CtrlS/Invaders-SDP GitHub Wiki
๋ฉ์๋๋ช (Method Name) | ํ๋ผ๋ฏธํฐ (Parameters) | ๋ฐํ๊ฐ (Return Type) | ์ค๋ช (Description) |
---|---|---|---|
addCurrency | int amount | void | amount์ ์๋งํผ ํํ๋ฅผ ์ง๊ธํฉ๋๋ค. (Grants currency equal to the amount.) |
spendCurrency | int amount | boolean | amount์ ์๋งํผ ํํ๋ฅผ ์๋นํ๋ฉฐ, ์ฑ๊ณต ์ true, ์คํจ ์ false๋ฅผ ๋ฐํํฉ๋๋ค. (Consumes currency equal to the amount; returns true if successful, false otherwise.) |
getCurrency | - | int | ํ์ฌ ๋ณด์ ํํ๋์ ๋ฐํํฉ๋๋ค. (Returns the current amount of currency.) |
CurrencyManager๋ FileManager, DrawManager์ ๊ฐ์ด ์ฑ๊ธํค ์คํ์ผ ํด๋์ค์ด๋ฉฐ, Core.getCurrencyManager()๋ฅผ ํตํด ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
CurrencyManager is a singleton class like FileManager and DrawManager, and the object can be accessed through Core.getCurrencyManager().
์ฌ์ฉ ์์ (Usage Example)
์์ 1: ํํ๋ฅผ ์ง๊ธํ๋ ๊ฒฝ์ฐ (Example 1: When granting currency)
CurrencyManager currencyManager = Core.getCurrencyManager();
currencyManager.addCurrency(100); // 100 ํํ ์ง๊ธ (Grant 100 currency)
System.out.println("ํ์ฌ ๋ณด์ ํํ (Current currency balance): " + currencyManager.getCurrency());
์์ 2: ํํ๋ฅผ ์๋นํ๋ ๊ฒฝ์ฐ (Example 2: When spending currency)
CurrencyManager currencyManager = Core.getCurrencyManager();
if (currencyManager.spendCurrency(50)) {
System.out.println("์๋น ์ฑ๊ณต! ๋จ์ ํํ (Spending successful! Remaining currency): " + currencyManager.getCurrency());
} else {
System.out.println("์๋น ์คํจ! ํํ๊ฐ ๋ถ์กฑํฉ๋๋ค. (Spending failed! Not enough currency.)");
}