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

📄 gamestatus.java

📁 龙与地下城游戏(小型)的设计与实现。主要是随机产生地牢
💻 JAVA
字号:
package dungeonsanddragons.game;import dungeonsanddragons.model.Player;import dungeonsanddragons.model.weapons.Weapon;import javax.swing.BoxLayout;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;/** * Class showing the current game status * @author Sandra Nilsson */public class GameStatus extends JFrame {    private JPanel weaponsPanel;    private JPanel treasurePanel;    private JPanel helthPanel;        private JLabel helth;    private JLabel weapon;    private JLabel treasure;        private ImageIcon treasureIcon = new ImageIcon("img/treasure.png");    private ImageIcon healthIcon = new ImageIcon( "img/aid2.png");        /**     * Creates a new game status panel     */    public GameStatus(){        super("Status Window");        setSize(450,350);        init();    }        /**     * Initializes the contents of the status panel     */    private void init(){        JPanel mainPanel = new JPanel();        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));        helthPanel = new JPanel();        weaponsPanel = new JPanel();        treasurePanel = new JPanel();                    helth = new JLabel("0", healthIcon, JLabel.CENTER);        weapon= new JLabel("Weapons: ");        treasure = new JLabel("0",treasureIcon,JLabel.CENTER);            helthPanel.add(helth);        weaponsPanel.add(weapon);        treasurePanel.add(treasure);                mainPanel.add(helthPanel);        mainPanel.add(treasurePanel);        mainPanel.add(weaponsPanel);        this.getContentPane().add(mainPanel);    }        /**     * resets the status information     */    public void reset(){        helthPanel.removeAll();        weaponsPanel.removeAll();        treasurePanel.removeAll();                        helth = new JLabel("0", healthIcon, JLabel.CENTER);        weapon= new JLabel("Weapons: ");        treasure = new JLabel("0",treasureIcon,JLabel.CENTER);            helthPanel.add(helth);        weaponsPanel.add(weapon);        treasurePanel.add(treasure);        helthPanel.revalidate();        weaponsPanel.revalidate();        treasurePanel.revalidate();    }     /**     * Updates helth and treasure status for player p     * @param p the player to show status for     */    public void updateStatus(Player p){        System.out.println("Updating status ");        helth.setText(" " + p.getHealthStatus());        treasure.setText(" " + p.getTreasureValue());    }        /**     * Update the weapons status      * @param p the player to show the weapons status for     */    public void updateWeapons(Player p){        weaponsPanel.removeAll();                for (Weapon w : p.getWeapons()) {            System.out.println("Adding " + w);            ImageIcon icon = new ImageIcon(w.getImg());            weaponsPanel.add(new JLabel("Strenght: " + w.getStrenght(),icon, JLabel.CENTER));                    }        weaponsPanel.revalidate();    }}

⌨️ 快捷键说明

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