📄 treasure.java
字号:
package dungeonsanddragons.model;import java.awt.Graphics;/** * Class to represent a treasure of coint that can be picked up by the player * @author Sandra Nilsson */public class Treasure extends Thing { private static String treasureImg = "img/treasure2.png"; /**The value of the treasure*/ private int coins; /** * Create a new treasure * @param value the value of this treasure */ public Treasure(int value) { super(treasureImg); this.coins = value; } /** * * @return the value of this treausre */ public int getCoins() { return coins; } /** * Give this treasure to the player (and remove it from the room) * @param p1 the player that picks up the treasure */ public void giveTo(Player p1) { p1.increaseTreasureValue(coins); currentRoom.setItem(null); currentRoom = null; } /** * Draw this treasure. Calls the draw in the super class (Showable) * then it also draws the value of itself * @param g the graphics to draw on. */ public void draw(Graphics g) { if (currentRoom != null) { super.draw(g); g.drawString("$" + coins, currentRoom.getX() + 30, currentRoom.getY() + 40); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -