-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoins.java
More file actions
30 lines (28 loc) · 811 Bytes
/
Coins.java
File metadata and controls
30 lines (28 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* This actor stores all the coins earned throughout the game and displays
* the total coins earned using the label constructed into the world
*
* @author Isaac Chan
* @version January 28, 2022
*/
public class Coins extends Actor
{
//the total amount of coins that the player has
private int totalCoins = 0;
public void act()
{
//updates the coin label every act
Label label = (((GameWorld)getWorld()).getCoinLabel());
label.setValue("Coins: " + totalCoins);
}
public void earnCoins(int coins)
{
//increases the total amount of coins when they are earned
totalCoins += coins;
}
public int getCoins()
{
return totalCoins;
}
}