• 云龙开炮版飞机大战(Java+JavaSwing+关卡+技能物品+宠物+商店界面+可切换音乐界面)



    前言

         基于Java Swing,以飞机大战为原形,以抗日电视剧《亮剑》中的“李云龙”为主题,
         实现菜单、选关、难度、等级、技能、商店等功能
    
    • 1
    • 2

    更多项目:

    1、大鱼吃小鱼小游戏(Java版含源代码,JavaSwing+多线程+接口)

    2、Java之马里奥游戏

    3、魔塔小游戏Java版项目含源代码

    4、贪吃蛇游戏项目(Java版含源代码)

    5、飞机大战Java版(Java+JavaSwing+多线程结构)


    👉项目完整源码获取👈


    一、主界面展示


    请添加图片描述


    请添加图片描述


    二、部分关卡、商店代码展示


    ⭐游戏工具类⭐

    package main.java.com.wave.game;
    
    import main.java.com.wave.game.Object.*;
    
    import java.awt.*;
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     * Created with IntelliJ IDEA.
     * <p>
     * Author: Wave&&KJ.JK
     * <p>
     * Date: 2021/11/18/9:35
     * <p>
     * Description: 游戏工具类,公共调用图片、路径、集合、音效
     */
    
    public class GameUtils {
        // Keypoint 图片定义
        // 封面图片
        public static Image coverImg = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/cover.jpg"));
        // 背景图片
        public static Image bgImg = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/background.jpg"));
        // 程序图标
        public static Image icon = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/王有胜.png"));
    
        // 游戏暂停图片
        public static Image gamePauseImg = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/gamePause.png"));
        // 游戏失败图片
        public static Image gameFailureImg = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/gameFailure.png"));
        // 游戏胜利图片
        public static Image gameVictoryImg = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/gameVictory.png"));
    
        // 飞机图片
        public static Image planeImg = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/plane1.png"));
        public static Image planeImg2 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/plane2.png"));
        public static Image planeImg3 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/plane3.png"));
        // 敌机图片
        public static Image enemy1Img = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/1/enemy1.png"));
        public static Image enemy2Img = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/2/enemy2.png"));
        public static Image enemy3Img = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/3/enemy3.png"));
        public static Image enemy4Img = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/3/enemy4.png"));
    
        // boss图片
        public static Image bossImg = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/1/boss1.png"));
        public static Image bossImg2 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/2/boss2.gif"));
        public static Image bossImg3 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/2/boss3.png"));
        public static Image bossImg4 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/3/boss4.png"));
        public static Image bossImg5 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/3/boss5.png"));
        // boss出现预警
        public static Image warning = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/warning.png"));
    
        // 飞机子弹图片
        public static Image planeShellImg = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/planeShell1.png"));
        public static Image planeShellImg2 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/planeShell2.png"));
        public static Image planeShellImg3 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/planeShell3.png"));
        public static Image planeShellImg4 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/planeShell4.png"));
        public static Image planeShellImg5 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/planeShell5.png"));
    
        // 敌机子弹图片
        public static Image enemyShellImg = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/1/enemyShell1.png"));
        public static Image enemyShellImg2 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/2/enemyShell2.png"));
        public static Image enemyShellImg3 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/2/enemyShell3.png"));
        public static Image enemyShellImg4 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/3/enemyShell4.png"));
        public static Image enemyShellImg5 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/3/enemyShell5.png"));
    
        // 技能图片
        public static Image skillImg1 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/skill/skill1.png"));
        public static Image skillImg3 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/skill/skill3.png"));
        public static Image skillImg4 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/skill/skill4.png"));
        public static Image skillImg5 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/skill/skill5.png"));
        public static Image skillImg6 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/skill/skill6.png"));
        public static Image skillImg7 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/skill/skill7.png"));
        public static Image skillImg8 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/skill/skill8.png"));
        public static Image skillImg9 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/skill/skill9.png"));
    
        // 礼物
        public static Image giftImg1 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/gift/gift1.png"));
        public static Image giftImg2 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/gift/gift2.png"));
    
        // 商店图片
        public static Image commodityImg1 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/Mythical_Animals/MA1.png"));
        public static Image commodityImg2 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/Mythical_Animals/MA2.png"));
        public static Image commodityImg3 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/Mythical_Animals/MA3.png"));
        public static Image commodityImg4 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/Mythical_Animals/E1.png"));
        public static Image commodityImg5 = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/Mythical_Animals/E2.png"));
    
        // Keypoint 按钮图片
        public static Image button_start = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/button/开始游戏.png"));
        public static Image button_select = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/button/下一首.png"));
        public static Image button_exit = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/button/退出.png"));
        public static Image button_selection = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/button/选择关卡_难度.png"));
        public static Image button_explain = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/button/信息按钮.png"));
        public static Image button_selection_plane = Toolkit.getDefaultToolkit().getImage(GameUtils.class.getClassLoader().getResource("images/button/选择战机.png"));
    
        // Keypoint 爆炸图片path
        public static String explode = "images/explode/e";
        public static String skill2 = "images/explode/skill2_";
        public static String level = "images/explode/level_";
    
        // Keypoint 集合定义
        private static final int CAPACITY_SIZE = 10000;
        // 所有游戏对象集合
        public static List<GameObject> gameObjList = new ArrayList<>(CAPACITY_SIZE);
        // 战机子弹集合
        public static List<PlaneShell> planeShellList = new ArrayList<>();
        // 敌机子弹集合
        public static List<EnemyShell> enemyShellList = new ArrayList<>();
        // 要删除元素集合
        public static List<GameObject> removeList = new ArrayList<>(CAPACITY_SIZE);
        // 战机技能集合
        public static List<Skill> skillList = new ArrayList<>();
        // 敌机集合
        public static List<Enemy> enemyList = new ArrayList<>();
        // 动态爆炸集合
        public static List<Explode> explodeList = new ArrayList<>();
        // 动态技能二集合
        public static List<Explode2> explodeList2 = new ArrayList<>();
        // 动态升级集合
        public static List<Explode3> explodeList3 = new ArrayList<>();
        // 礼物集合
        public static List<Gift> giftList = new ArrayList<>();
        public static List<Gift2> giftList2 = new ArrayList<>();
    
        // Keypoint 音效
        // 初始界面
        public static String run_no1 = "music/1/亮剑.wav"; // 初始界面及第一游戏背景音乐
        public static String run_no2 = "music/1/开炮.wav"; // 开始按钮
    
        // 第一关
        public static String run_no3 = "music/1/日本人.wav"; // 第一关第一个boss出现
        public static String run_no4 = "music/1/注意啦节省子弹.wav"; // boss死亡
    
        // 第二关
        public static String run2_no1 = "music/2/无人机群.wav"; // 第二关叠加背景音效
        public static String run2_no2 = "music/2/全体上刺刀,准备进攻.wav"; // 第二关第一个boss出现
        public static String run2_no3 = "music/2/冲锋.wav"; // 第二关第二个boss出现
        public static String run2_no4 = "music/2/狼走千里吃肉,狗走千里吃屎.wav"; // boss死亡1
        public static String run2_no5 = "music/2/哈哈哈,老天爷帮忙啊.wav"; // boss死亡2
    
        // 第三关
        public static String run3_no1 = "music/3/什么精锐,老子打的就是精锐.wav"; // boss死亡1
        public static String run3_no3 = "music/3/小鬼子拼刺刀.wav"; // boss出场1
        public static String run3_no4 = "music/3/意大利开炮.wav"; // boss出场2
    
        // 技能
        public static String skill_no1 = "music/skill/鹰啼.wav";
        public static String skill_no2 = "music/skill/雷电火卷.wav";
        public static String skill_no3 = "music/skill/雷刃.wav";
        public static String skill_no4 = "music/skill/黑洞.wav";
        public static String skill_no5 = "music/skill/星耀光环.wav";
        public static String skill_no6 = "music/skill/火星球.wav";
        public static String skill_no7 = "music/skill/火龙卷.wav";
        public static String skill_no8 = "music/skill/恢复.wav";
        public static String skill_no9 = "music/skill/蓄气.wav";
        // 45678 嘴炮技能
        public static String skill_no10 = "music/skill/4567/过瘾.wav";
        public static String skill_no11 = "music/skill/4567/日你仙人.wav";
        public static String skill_no12 = "music/skill/4567/我倒要看看这帮日本猪知不知道疼.wav";
        public static String skill_no13 = "music/skill/4567/要乌龟王八蛋.wav";
        public static String skill_no14 = "music/skill/4567/警报.wav";
    
        // 基础
        public static String basic_no1 = "music/basic/飞机爆炸.wav";
        public static String basic_no2 = "music/basic/升级.wav";
        public static String basic_no3 = "music/basic/礼物1.wav"; // 加蓝礼物
        public static String basic_no4 = "music/basic/礼物2.wav"; // 随机技能礼物
        public static String basic_no5 = "music/basic/枪林弹雨.wav"; // 背景配乐2
        public static String basic_no6 = "music/basic/受伤.wav"; // 背景配乐2
        public static String basic_no7 = "music/basic/没出息.wav"; // 失败
        public static String basic_no8 = "music/basic/你他娘的还真是个天才.wav"; // 胜利
        public static String basic_no9 = "music/basic/你猜旅长怎么说x花田错.wav"; // 切歌
        public static String basic_no10 = "music/basic/按钮声.wav"; // 按钮
        public static String basic_no11 = "music/basic/选择按钮音效.wav"; // 选择按钮音效
        public static String basic_no12 = "music/basic/boss出现预警.wav"; // boss出现预警
    }
    
    • 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
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177

    ⭐游戏面板类⭐

    package main.java.com.wave.game;
    
    import main.java.com.wave.game.Object.Plane;
    
    import javax.swing.*;
    import java.awt.*;
    
    /**
     * Created with IntelliJ IDEA.
     * <p>
     * Author:  Wave&&KJ.JK
     * <p>
     * Date: 2021/12/10/18:44
     * <p>
     * Description: 选择飞机弹窗类
     */
    
    public class Popup_SelectPlane extends JFrame {
    
        public Popup_SelectPlane() {
            new Sound(GameUtils.basic_no11).start();
            init();
        }
    
        public void init() {
            // 说明
            JLabel jLabel = new JLabel("选择战机:");
            jLabel.setFont(new Font("acetone-family", Font.BOLD, 15));
            jLabel.setBounds(10, 10, 200, 20);
    
            // 标签文字
            JRadioButton option1 = new JRadioButton("胜利飞燕1号", true);
            JRadioButton option2 = new JRadioButton("胜利飞燕2号");
            JRadioButton option3 = new JRadioButton("新四高达战士");
            option1.setBounds(45, 40, 132, 20);
            option2.setBounds(230, 40, 120, 20);
            option3.setBounds(415, 40, 120, 20);
    
            // 单选
            ButtonGroup group = new ButtonGroup();
            group.add(option1);
            group.add(option2);
            group.add(option3);
    
            // 标签图片
            JLabel commodity1 = new JLabel(new ImageIcon(GameUtils.planeImg));
            JLabel commodity2 = new JLabel(new ImageIcon(GameUtils.planeImg2));
            JLabel commodity3 = new JLabel(new ImageIcon(GameUtils.planeImg3));
            commodity1.setBounds(45, 80, 120, 140);
            commodity2.setBounds(235, 80, 120, 140);
            commodity3.setBounds(405, 80, 120, 140);
    
            // 确定按钮
            JPanel jPanel = new JPanel();
            JButton button = new JButton("确定");
            button.setFont(new Font("acetone-family", Font.BOLD, 20));
            jPanel.setLayout(null);
            button.setBounds(245, 220, 90, 50);
            jPanel.add(button);
            jPanel.setVisible(true);
    
            // 将组件添加进面板
            this.add(jLabel);
            this.add(option1);
            this.add(option2);
            this.add(option3);
            this.add(commodity1);
            this.add(commodity2);
            this.add(commodity3);
            this.add(jPanel);
    
            // 面板设置
            this.setTitle("云龙机场");
            this.setVisible(true);
            this.setResizable(false);
            this.setSize(590, 320);
            this.setLocationRelativeTo(null);
            this.repaint();
    
            // 监听
            button.addActionListener(e -> {
                if (option1.isSelected()) {
                    Plane.plane_number = 1;
                    GamePanel.plane_create = true;
                    System.out.println("选择:胜利飞燕1号");
                } else if (option2.isSelected()) {
                    Plane.plane_number = 2;
                    GamePanel.plane_create = true;
                    System.out.println("选择:胜利飞燕2号");
                } else if (option3.isSelected()) {
                    Plane.plane_number = 3;
                    GamePanel.plane_create = true;
                    System.out.println("选择:新四高达战士");
                }
                new Sound(GameUtils.basic_no10).start();
                // 提示弹窗
                JOptionPane.showMessageDialog(null, "选择成功! 准备战斗!!!", "云龙机场温馨提醒", JOptionPane.INFORMATION_MESSAGE);
                this.dispose();
            });
        }
    }
    
    
    • 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
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102

    请添加图片描述


    请添加图片描述


    请添加图片描述


    请添加图片描述


    ⭐商店类⭐

    package main.java.com.wave.game;
    
    import main.java.com.wave.game.Object.MAnimals;
    import main.java.com.wave.game.Object.Plane;
    
    import javax.swing.*;
    import java.awt.*;
    
    /**
     * Created with IntelliJ IDEA.
     * <p>
     * Author:  Wave&&KJ.JK
     * <p>
     * Date: 2021/12/06/21:34
     * <p>
     * Description: 商店类
     */
    
    public class Popup_Shop extends JFrame {
        boolean buy = false;
        int price1 = 500, price2 = 799, price3 = 888, price4 = 800, price5 = 800;
    
        public Popup_Shop() {
            new Sound(GameUtils.basic_no11).start();
            init();
        }
    
        public void init() {
            // 说明
            JLabel jLabel = new JLabel("选择购买商品:");
            jLabel.setFont(new Font("acetone-family", Font.BOLD, 15));
            jLabel.setBounds(10, 10, 200, 20);
    
            JLabel jLabel2 = new JLabel("-------------------- 当前金币数:" + Plane.goldNumber + "  --------------------");
            jLabel2.setFont(new Font("acetone-family", Font.BOLD, 15));
            jLabel2.setBounds(130, 150, 800, 20);
    
            // 标签文字
            JRadioButton option1 = new JRadioButton("吞天紫金貂(" + price1 + "$)");
            JRadioButton option2 = new JRadioButton("九幽冥凤(" + price2 + "$)");
            JRadioButton option3 = new JRadioButton("太虚古龙(" + price3 + "$)");
            JRadioButton option4 = new JRadioButton("血量+1(" + price4 + "$)");
            JRadioButton option5 = new JRadioButton("技能+1(" + price5 + "$)");
            option1.setBounds(5, 40, 132, 20);
            option2.setBounds(140, 40, 120, 20);
            option3.setBounds(265, 40, 120, 20);
            option4.setBounds(385, 40, 120, 20);
            option5.setBounds(505, 40, 120, 20);
    
            // 单选
            ButtonGroup group = new ButtonGroup();
            group.add(option1);
            group.add(option2);
            group.add(option3);
            group.add(option4);
            group.add(option5);
    
            // 标签图片
            JLabel commodity1 = new JLabel(new ImageIcon(GameUtils.commodityImg1));
            JLabel commodity2 = new JLabel(new ImageIcon(GameUtils.commodityImg2));
            JLabel commodity3 = new JLabel(new ImageIcon(GameUtils.commodityImg3));
            JLabel commodity4 = new JLabel(new ImageIcon(GameUtils.commodityImg4));
            JLabel commodity5 = new JLabel(new ImageIcon(GameUtils.commodityImg5));
            commodity1.setBounds(45, 80, 63, 63);
            commodity2.setBounds(165, 80, 63, 63);
            commodity3.setBounds(285, 80, 63, 63);
            commodity4.setBounds(405, 80, 63, 63);
            commodity5.setBounds(525, 80, 63, 63);
    
            // 购买按钮
            JPanel jPanel = new JPanel();
            JButton button = new JButton("购买");
            button.setFont(new Font("acetone-family", Font.BOLD, 20));
            jPanel.setLayout(null);
            button.setBounds(255, 180, 90, 50);
            jPanel.add(button);
            jPanel.setVisible(true);
    
            // 将组件添加进面板
            this.add(jLabel);
            this.add(jLabel2);
            this.add(option1);
            this.add(option2);
            this.add(option3);
            this.add(option4);
            this.add(option5);
            this.add(commodity1);
            this.add(commodity2);
            this.add(commodity3);
            this.add(commodity4);
            this.add(commodity5);
            this.add(jPanel);
    
            // 面板设置
            this.setTitle("超级神秘商店");
            this.setVisible(true);
            this.setResizable(false);
            this.setSize(630, 280);
            this.setLocationRelativeTo(null);
            this.repaint();
    
            // 监听
            button.addActionListener(e -> {
                if (option1.isSelected() && Plane.goldNumber >= price1) {
                    buy = true;
                    if (!GamePanel.MAExist) {
                        Plane.goldNumber -= price1;
                        MAnimals.MAnimalsNumber = 1;
                        GamePanel.MAAppear = true;
                        System.out.println("购买:吞天紫金貂(" + price1 + "$)");
                    }
                } else if (option2.isSelected() && Plane.goldNumber >= price2) {
                    buy = true;
                    if (!GamePanel.MAExist) {
                        Plane.goldNumber -= price2;
                        MAnimals.MAnimalsNumber = 2;
                        GamePanel.MAAppear = true;
                        System.out.println("购买:九幽冥凤(" + price2 + "$)");
                    }
                } else if (option3.isSelected() && Plane.goldNumber >= price3) {
                    buy = true;
                    if (!GamePanel.MAExist) {
                        Plane.goldNumber -= price3;
                        MAnimals.MAnimalsNumber = 3;
                        GamePanel.MAAppear = true;
                        System.out.println("购买:太虚古龙(" + price3 + "$)");
                    }
                } else if (option4.isSelected() && Plane.goldNumber >= price4) {
                    buy = true;
                    Plane.goldNumber -= price4;
                    Plane.record_plane_life += 5;
                    Plane.plane_life += 100;
                    System.out.println("购买:(" + price4 + "$)");
                } else if (option5.isSelected() && Plane.goldNumber >= price5) {
                    buy = true;
                    Plane.goldNumber -= price5;
                    Plane.record_plane_skill += 5;
                    Plane.plane_skill += 100;
                    System.out.println("购买:技能+1(" + price5 + "$)");
                }
                new Sound(GameUtils.basic_no10).start();
    
                // 提示弹窗
                boolean select = (option1.isSelected() || option2.isSelected() || option3.isSelected() || option4.isSelected() || option5.isSelected());
    
                if (!select) {
                    JOptionPane.showMessageDialog(null, "请选择所需商品!", "超级神秘商店温馨提醒", JOptionPane.WARNING_MESSAGE);
                } else if (!buy) {
                    JOptionPane.showMessageDialog(null, "兄弟,金币不足啊!", "超级神秘商店温馨提醒", JOptionPane.ERROR_MESSAGE);
                } else if ((option1.isSelected() || option2.isSelected() || option3.isSelected()) && GamePanel.MAExist) {
                    JOptionPane.showMessageDialog(null, "已存在一只神兽,不可贪多哦~", "超级神秘商店温馨提醒", JOptionPane.ERROR_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(null, "购买成功!!" + "剩余金币:" + Plane.goldNumber, "超级神秘商店温馨提醒", JOptionPane.INFORMATION_MESSAGE);
                    this.dispose();
                }
            });
        }
    }
    
    
    • 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
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159

    请添加图片描述


    ⭐音乐类⭐

    package main.java.com.wave.game;
    
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.Clip;
    import java.io.File;
    import java.util.Objects;
    
    /**
     * Created with IntelliJ IDEA.
     * <p>
     * Author:  Wave&&KJ.JK
     * <p>
     * Date: 2021/11/26/17:44
     * <p>
     * Description:音效类
     **/
    
    public class Sound {
        private Clip clip;
        AudioInputStream audio;
    //    File file;
    
        /**
         * 打开声音文件
         */
        public Sound(String path) {
            try {
                audio = AudioSystem.getAudioInputStream(Objects.requireNonNull(Sound.class.getClassLoader().getResource(path)));
    //            file = new File(path);
    //            audio = AudioSystem.getAudioInputStream(file);
                clip = AudioSystem.getClip();
                clip.open(audio);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        /**
         * 停止播放
         */
        public void stop() {
            clip.stop();
        }
    
        /**
         * 开始播放
         */
        public void start() {
            clip.start();
        }
    
        /**
         * 循环播放
         */
        public void loop() {
            clip.loop(clip.LOOP_CONTINUOUSLY);
        }
    }
    
    
    
    • 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
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61

    作者:KJ.JK

  • 相关阅读:
    Linux TCP/IP 协议栈调优
    2023_Spark_实验二十:SparkStreaming累加计算单词频率
    2023-2024 计算机信息安全专业毕设题目推荐
    如何让光从光纤平滑地进入波导?
    【leetcode】【2022/8/15】641. 设计循环双端队列
    MindSpore能把两个实数组合成复数的操作算子么
    Python平板电脑数据分析-课程大作业-部分源码
    如何封装axios请求。统一基地址、加载遮罩层、响应参数优化
    如何安装Torch7在Ubuntu20.04 ( CUDA10.1 和 CUDNN7.6.5)
    【毕业设计】机器学习驾驶疲劳检测系统 - python
  • 原文地址:https://blog.csdn.net/m0_47384542/article/details/125509586