treasure.java

来自「龙与地下城游戏(小型)的设计与实现。主要是随机产生地牢」· Java 代码 · 共 55 行

JAVA
55
字号
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 + =
减小字号Ctrl + -
显示快捷键?