⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 player.java

📁 龙与地下城游戏(小型)的设计与实现。主要是随机产生地牢
💻 JAVA
字号:
package dungeonsanddragons.model;import dungeonsanddragons.model.monsters.Monster;import dungeonsanddragons.model.weapons.Weapon;import java.awt.event.KeyEvent;import java.util.ArrayList;/** * Class player representing and keeping track of a player * @author Sandra Nilsson */public class Player extends Showable {    /**Image representing this player*/    private static String playerImg = "img/player.png";    private static String soundFileName = "sound/R2.wav";    /**Player status of treasures*/    private int treasureValue;    /**Player status of weapons*/    private ArrayList<Weapon> weapons;    /**Player status of health*/    private int healthStatus;        /**Create a new player     * The player has an initial health status of 5 and an initial      * treasure value of 0     * The player shall have no weapons to start with     */    public Player () {        super(playerImg,soundFileName);        treasureValue = 0;        healthStatus = 5;        weapons = new ArrayList<Weapon>();    }        /**     * Increase the value of the treasure status (called when a player picks up a treasure)     * @param value the value of the treasure picked up     */    public void increaseTreasureValue(int value){        treasureValue=value+treasureValue;                    }        /**     * Add a weapon for this player to carry (called when a player picks upp a weapon)     * @param w the weapon to add     */    public void addWeapon(Weapon w){        weapons.add(w);        play();    }        /**     * Increase the value of the players health (called when a player picks up a aid kit)     * @param value the value of the aid kit picked up     */    public void increaseHealthStatus(int value){        healthStatus=value+healthStatus;           }        /**     * Check if the monster can bite this player     * @param m the monster     * @return true if the monster can bite, false if the player has a weapons that kill the monster     */    public boolean canBeBitten (Monster m) {                                    for (int i = 0; i < weapons.size(); i++) {            if (m.killedBy(weapons.get(i))) {            return false;        }           }           return true;        }                             public void bitten (Monster m) {        healthStatus=healthStatus-m.getPower();            }        /**     * Given a key code, walk through to the next room.      * And return the room to which this player goes (depending on key)     * @param keyCode the code of the key that represents where to move (the direction)     * @return the door through which the player moves given the key code, null if there is no door in the given direction.     */    public Door move(int keyCode){        if(keyCode == KeyEvent.VK_UP){            Door d=this.currentRoom.getNorth();           if(d!=null){               d.walkThrough(this, currentRoom);               return d;           }        }         if(keyCode == KeyEvent.VK_DOWN){           Door d=this.currentRoom.getSouth();           if(d!=null){               d.walkThrough(this, currentRoom);               return d;           }        }              if(keyCode == KeyEvent.VK_LEFT){           Door d=this.currentRoom.getWest();           if(d!=null){               d.walkThrough(this, currentRoom);               return d;           }        }        if(keyCode == KeyEvent.VK_RIGHT){           Door d=this.currentRoom.getEast();           if(d!=null){               d.walkThrough(this, currentRoom);               return d;           }        }           return null;    }                      public int getHealthStatus() {        return healthStatus;    }    /**     *      * @return the value of the treasures of this player     */    public int getTreasureValue() {        return treasureValue;    }    /**     *      * @return the lists of weapons that this player has     */    public ArrayList<Weapon> getWeapons() {        return weapons;    }        /**     * Calculate the total points of this player     *      * @return the total points     */    public int calculateTotalPoints(long seconds){             return (int) (treasureValue - seconds*10);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -