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.)");
}