“This is the 15th day of my participation in the First Challenge 2022. For details: First Challenge 2022”

❤️ Author’s home page: Xiao Xu Zhu

❤️ About the author: Hello everyone, I am Xiao Xu Zhu. Java field quality creator 🏆, CSDN blog expert 🏆, Huawei cloud enjoy expert 🏆, Nuggets of the year popular author 🏆, Ali Cloud expert blogger 🏆

❤️ technology live, the appreciation

❤️ like 👍 collect ⭐ look again, form a habit

preface

“Aircraft war -III” is a fusion of arcade, competitive and other elements of the classic shooting mobile tour. Gorgeous and exquisite game screen, super dazzle with a sense of skill special effects, super hot screen let you adrenaline burst, give you a full range of shock feeling, experience the infinite fun of flying combat.

The game is implemented in Java language, using Swing technology for interface processing, design ideas with object-oriented thought.

The main requirements

Based on Java Swing, to the aircraft war as the prototype, to the anti-Japanese TV series “Liangjian” in the “Li Yunlong” as the theme, to achieve menu, select level, difficulty, level, skills and other functions.

The main design

① After entering the game, please press the Shift key (to change the keyboard to English mode) ② Skills for the number 1 (attack), 2 (heal), 3 (air storage) ③ numbers 4, 5, 6, 7, 8 for creative sound, the space bar for pause ④ Using 1, 2 skills will consume the corresponding skill blue bar. 3 cost must restore health must touch blue (5) the game random parachute ammunition can back to random flash blue 6 touch game particles can randomly change 1 skills, special effects, and health and blue 2 7 role by the mouse to control the position, role will automatically launch the corresponding grades of the bullet was every beat a boss, character level, Press the space button to pause the game. There are three levels and three difficulty levels for you to choose from

Screenshot function

The game start

Choose fighter

Start the game

Code implementation

Game panel class, the game object focus on drawing to this panel



public class GamePanel extends JFrame {
    // Keypoint basic variable definition
    Image offScreenImage = null; // Define a double cache
    int width = 1250, height = 725; // Window width and height
    public static int state = 0; // Keypoint game state 0 not started 1 Run 2 pause 3 failed to complete 4 succeeded
    public static int score = 0; // Game score
    public static int count = 1; // Game drawing times (timing function)
    static int enemyFrequency = 30;  // The frequency of enemy planes (different levels have different rates)
    static int enemyShellFrequency = 40;  // The frequency of enemy bullets (different levels have different rates)
    static int planeShellFrequency = 20;  // The frequency of bullets (different levels have different rates)
    public static int enemyCount = 1;  // Record the number of enemy planes
    static int bossAppear = 50;  // Define how many enemy bosses appear
    public static boolean skill_release = false; // Determine whether the skill has been released
    static boolean play_BOSS_sound = true; // Adjust the boss appearance sound to play only once
    static boolean play_warn_sound = true; // Adjust boss appearance warning sound only plays once
    static boolean end = true; // Adjust the defeat or victory sound only once
    static boolean T = false; // Press T to exit the game on defeat or victory
    public static boolean R = false; // Return to the main screen
    static boolean play = true; // Adjust button 2 (click Play, then click Pause)
    static boolean prearranged = true; // Dynamic effects are preloaded
    public static boolean MAAppear = false;  // The monster appears
    public static boolean MAExist = false;  // Whether there are gods
    public static boolean plane_create = false;  // Create a plane

    / / difficulty
    static int skillConsume = 2; // 2 5 10 mana consumed
    static int skillRecovery = 100; // 100 150 999 return blue speed
    static int lifeRecovery = 50; // 50 90 500 blood return rate

    // Keypoint element entity definition
    // Background entity class
    public GameObject backGroundObj = new BackGround(GameUtils.bgImg, 0, -1900.2.this);
    // Aircraft entity class
    public GameObject planeObj = new Plane(GameUtils.planeImg, 600.550.70.100.0.this);
    // Boss entity class
    public GameObject BOSSObj = null;
    // God beast entity class
    public GameObject mAnimalsObj = null;

    // Keypoint button declaration
    JButton button1 = new JButton("Start the game");
    JButton button2 = new JButton("Listen to the song.");
    JButton button3 = new JButton("Quit the game");
    JButton button4 = new JButton("Select difficulty level");
    JButton button5 = new JButton("Game Instructions");
    JButton button6 = new JButton("Choose your fighter");
    JPanel frame = new JPanel(); // Button panel

    // Keypoint sound declaration
    Sound sound = new Sound(GameUtils.run_no1); // Background music 1 (sword)
    // Sound sound2 = new Sound(GameUtils.run_no2); // Start button (fire)
    Sound sound3 = new Sound(GameUtils.run2_no1); // Level 2 background music (drone group)
    Sound sound4 = new Sound(GameUtils.basic_no5); // Background music 2

    public GamePanel(a) {
        // Keypoint start button
        frame.setLayout(null);
        Sound s = new Sound(GameUtils.basic_no9); // Press the button

        button1.setIcon(new ImageIcon(GameUtils.button_start)); // Start button 1
        button1.setBounds(530.350.245.70);
        frame.add(button1);
        button1.addActionListener(e -> {
            if(! Popup.select) {// If you return to the main screen without selecting the level, the first level is initialized by default
                GamePanel.bossAppear = 50;
                BOSS.number = 0;
                GamePanel.play_BOSS_sound = true;
                Plane.lock = false;
                Plane.plane_level = 1;
            }
            state = 1;
            s.stop();
            sound.start();
            sound.loop();
            new Sound(GameUtils.run_no2).start();
        });

        button2.setIcon(new ImageIcon(GameUtils.button_selection_plane)); // Start button 2
        button2.setBounds(530.435.245.70);
        frame.add(button2);
        button2.addActionListener(e -> new Popup_SelectPlane());

        button3.setIcon(new ImageIcon(GameUtils.button_selection)); // Start button 3
        button3.setBounds(530.520.245.70);
        frame.add(button3);
        button3.addActionListener(e -> new Popup());

        button4.setIcon(new ImageIcon(GameUtils.button_exit)); // Start button 4
        button4.setBounds(530.605.245.70);
        frame.add(button4);
        button4.addActionListener(e -> System.exit(0));

        button5.setIcon(new ImageIcon(GameUtils.button_explain)); // Start button 5
        button5.setBounds(20.20.45.45);
        frame.add(button5);

        button6.setIcon(new ImageIcon(GameUtils.button_select)); // Start button 2
        button6.setBounds(20.80.45.45);
        frame.add(button6);
        button6.addActionListener(e -> {
            if (play) {
                sound.stop();
                s.start();
                s.loop();
                play = false;
            } else {
                s.stop();
                sound.start();
                play = true; }}); button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                newSound(GameUtils.basic_no10).start(); }}); button2.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                newSound(GameUtils.basic_no10).start(); }}); button3.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                newSound(GameUtils.basic_no10).start(); }}); button4.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                newSound(GameUtils.basic_no10).start(); }}); button5.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                new Sound(GameUtils.basic_no11).start();
                JOptionPane.showMessageDialog(null."Dear Yunlong warrior, welcome to gunnery land!! \n" +
                                "-----------------------------------------------------2021-12-01-----------------------------------------------------\n" +
                                "Here are the instructions: \n" +
                                "① After entering the game, please press the Shift key (change the keyboard to English mode) \ N" +
                                "② Skills are numbers 1 (attack), 2 (heal), 3 (recharge) \n" +
                                "③ Numbers 4, 5, 6, 7, 8 for creative sound, space bar for pause \ N" +
                                "④ Using skills 1 and 2 will cost the corresponding blue bar, and skills 3 will cost a certain amount of health and regenerate a certain amount of blue \n" +
                                "⑤ If you touch a parachute ammo that appears randomly in the game, it will regenerate." +
                                "⑥ If you touch a random flash particle in the game, you can randomly change 1 skill effect and add 2\n health to it." +
                                "By mouse control role position, role will automatically launch the corresponding level of bullets \ N" +
                                "⑧ Every time you defeat a boss, your character gets a level up and bullets get a level up \n" +
                                "⑨ Health and blue automatically increases and replenishes with \n" +
                                "⑩ Press space to pause the game \n" +
                                "This version of the game has three levels and three difficulties, you can choose \n" +
                                "-----------------------------------------------------2021-12-07-----------------------------------------------------\n" +
                                "Update: \n" +
                                "① Press 'R' to return to the main screen and press 'T' to exit the game \n" +
                                "② Added 'O' on pause screen to enter store \n" +
                                "③w s a d up, down, left and right control animal movement \n" +
                                "-----------------------------------------------------2021-12-08-----------------------------------------------------\n" +
                                "Update: \n" +
                                "① Enemy will track and move according to fighter's position \n" +
                                "② Modify some skills \n" +
                                "-----------------------------------------------------2021-12-11-----------------------------------------------------\n" +
                                "Update: \n" +
                                "① Added initial menu selection function \n" +
                                "-----------------------------------------------------2021-12-13-----------------------------------------------------\n" +
                                "① Fix some known problems \n" +
                                "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - --\n" +
                                "\n" +
                                "Note: \n" +
                                "If you encounter any problems in the game, please shut down and restart!! \n" +
                                "\n" +
                                "Developer: tao \ n"."※ Game Instructions", JOptionPane.PLAIN_MESSAGE); }}); button6.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                newSound(GameUtils.basic_no10).start(); }});if (prearranged) {
            Explode explodeObj = new Explode(1000, -1000);
            GameUtils.explodeList.add(explodeObj);
            GameUtils.removeList.add(explodeObj);
            Explode2 explodeObj2 = new Explode2(1000, -500);
            GameUtils.explodeList2.add(explodeObj2);
            GameUtils.removeList.add(explodeObj2);
            Explode3 explodeObj3 = new Explode3(1000, -200);
            GameUtils.explodeList3.add(explodeObj3);
            GameUtils.removeList.add(explodeObj3);
            prearranged = false;
        }
        this.add(frame); // Add the start button to the main panel
        launch();
    }

    / / start Keypoint
    public void launch(a) {
        this.setFocusable(true);
        this.setVisible(true);
        this.setBounds(0.0, width, height);
        this.setTitle("Yunlong Gun 4.0");
        this.setIconImage(GameUtils.icon); // Program icon
        this.setResizable(false);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        // Add the game object to the large collection
        GameUtils.gameObjList.add(backGroundObj);
        GameUtils.gameObjList.add(planeObj);

        // Mouse monitor
        this.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("Mouse monitor press -- >" + e.getButton());
                if (e.getButton() == 3) {
                    System.out.println("Release skill 1");   // Cast skill (attack)
                    Skill.release = true;
                    Skill.number = 1; }}});// Keypoint keyboard listener (pause, release skills)
        this.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                super.keyPressed(e);
                switch (e.getKeyCode()) {
                    case 32:  // whitespace is paused
                        switch (state) {
                            // Run to pause
                            case 1:
                                System.out.println("Game pause");
                                state = 2;
                                sound.stop();
                                sound3.stop();
                                sound4.stop();
                                break;
                            // Pause to run
                            case 2:
                                System.out.println("Keep playing.");
                                state = 1;
                                sound.start();
                                if (Plane.plane_level == 2) {
                                    sound3.start();
                                }
                                sound4.start();
                                break;
                        }
                        break;
                    case 49: // 1 Cast skill (attack)
                        if (Plane.plane_skill >= 5) {
                            System.out.println("Unleash skill 1 (Attack)");
                            Skill.release = true;
                            Skill.number = 1;
                        }
                        break;
                    case 50: // 2 Release skill (heal)
                        if (Plane.plane_skill >= 5) {
                            System.out.println("Release skill 2 (Healing)");
                            Skill.release = true;
                            Skill.number = 2;
                        }
                        break;
                    case 51: / / 3 gas storage
                        System.out.println("Release skill 3 (Air Storage)");
                        Skill.release = true;
                        Skill.number = 3;
                        break;
                    case 52: / / 4 sound
                        new Sound(GameUtils.skill_no10).start();
                        break;
                    case 53: / / 5 sound effects
                        new Sound(GameUtils.skill_no11).start();
                        break;
                    case 54: / / 6 sound
                        new Sound(GameUtils.skill_no12).start();
                        break;
                    case 55: / / 7 sound
                        new Sound(GameUtils.skill_no13).start();
                        break;
                    case 56: / / 8 sound
                        new Sound(GameUtils.skill_no14).start();
                        break;
                    case 82: // Listen for the R key
                        if (state == 2 || state == 3 || state == 4)
                            R = true;
                        break;
                    case 84: // Listen for the T key
                        if (state == 2 || state == 3 || state == 4)
                            T = true;
                        break;
                    case 79: // Listen for the O key
                        if (state == 2) {
                            new Popup_Shop();
                        }
                        break;
                    case 87: // W
                        if(mAnimalsObj ! =null) {
                            MAnimals.Direction = 1;
                        }
                        break;
                    case 83: // S
                        if(mAnimalsObj ! =null) {
                            MAnimals.Direction = 2;
                        }
                        break;
                    case 65: // A
                        if(mAnimalsObj ! =null) {
                            MAnimals.Direction = 3;
                        }
                        break;
                    case 68: // D
                        if(mAnimalsObj ! =null) {
                            MAnimals.Direction = 4;
                        }
                        break;
                    default:
                        System.out.println("Keyboard monitor press -- >" + e.getKeyCode());
                        break; }}});// Keypoint refreshes the screen
        while (true) {
            if (state > 0) {
                repaint();
                if (state == 1)
                    createObj();
            }
            try {
                Thread.sleep(10); // Refresh once for 10ms
            } catch(Exception e) { e.printStackTrace(); }}}public void init(a) {
        state = 0; // Keypoint game state 0 not started 1 Run 2 pause 3 failed to complete 4 succeeded
        score = 0; // Game score
        count = 1; // Game drawing times (timing function)
        enemyFrequency = 30;  // The frequency of enemy planes (different levels have different rates)
        enemyShellFrequency = 40;  // The frequency of enemy bullets (different levels have different rates)
        planeShellFrequency = 20;  // The frequency of bullets (different levels have different rates)
        enemyCount = 1;  // Record the number of enemy planes
        bossAppear = 50;  // Define how many enemy bosses appear
        skill_release = false; // Determine whether the skill has been released
        play_BOSS_sound = true; // Adjust the boss appearance sound to play only once
        play_warn_sound = true; // Adjust boss appearance warning sound only plays once
        end = true; // Adjust the defeat or victory sound only once
        T = false; // Press T to exit the game on defeat or victory
        play = true; // Adjust button 2 (click Play, then click Pause)
        prearranged = true; // Dynamic effects are preloaded
        MAAppear = false;  // The monster appears
        Plane.goldNumber = 0; / / the number of gold COINS
        Plane.plane_life = 100;
        Plane.plane_skill = 100;
        frame.setVisible(true); // Hide the button
        if(BOSSObj ! =null) { // Initialize the boss
            BOSSObj.setX(-500);
            BOSSObj.setY(700);
            GameUtils.removeList.add(BOSSObj);
            BOSS.number = 0;
            BOSSObj = null;
        }
        if(mAnimalsObj ! =null) { // Initialize the god beast
            mAnimalsObj.setX(-500);
            mAnimalsObj.setY(700);
            GameUtils.removeList.add(mAnimalsObj);
            mAnimalsObj = null;
            GamePanel.MAExist = false;
        }
        Popup.select = false; // Initialize the option button
        // Clear the artboard image
        GameUtils.gameObjList.clear();
        GameUtils.gameObjList.add(backGroundObj);

        // Initialize the aircraft
        Plane.plane_number = 1;
        plane_create = true;
        repaint();
    }

    / / Keypoint
    @Override
    public void paint(Graphics g) {
        // Keypoint double buffering
        // Create an Image of the same size as the container
        if (offScreenImage == null)
            offScreenImage = this.createImage(width, height);
        Graphics gImage = offScreenImage.getGraphics(); // Get the canvas for the image
        gImage.fillRect(0.0, width, height); // Fill the canvas

        // Keypoint turns off sound effects based on state
        if (state == 2 || state == 3 || state == 4) {
            sound.stop();
            sound3.stop();
            sound4.stop();
        }

        // Keypoint game state
        switch (state) {
            case 0: // The game has not started
                sound.start();
                sound.loop();
                gImage.drawImage(GameUtils.coverImg, 0.0.null);
                // Keypoint puts the button's focus method in the panel's redraw code (to prevent flickering)
                button1.requestFocus();
                button2.requestFocus();
                button3.requestFocus();
                button4.requestFocus();
                button5.requestFocus();
                button6.requestFocus();
                break;
            case 1: // Start the game
                // Keypoint creates a fighter object
                if (plane_create) {
                    GameUtils.removeList.add(planeObj);
                    Image img = null;
                    int w = 0;
                    int h = 0;
                    switch (Plane.plane_number) {
                        case 1:
                            w = 120;
                            h = 68;
                            img = GameUtils.planeImg;
                            break;
                        case 2:
                            w = 120;
                            h = 89;
                            img = GameUtils.planeImg2;
                            break;
                        case 3:
                            w = 70;
                            h = 100;
                            img = GameUtils.planeImg3;
                            break;
                    }
                    planeObj = new Plane(img, 600.550, w, h, 0.this);
                    plane_create = false;
                    GameUtils.gameObjList.add(planeObj);
                }
                sound4.start();
                sound4.loop();
                frame.setVisible(false); // Hide the button
                GameUtils.gameObjList.addAll(GameUtils.explodeList); // Dynamic effect rendering added
                GameUtils.gameObjList.addAll(GameUtils.explodeList2);
                GameUtils.gameObjList.addAll(GameUtils.explodeList3);
                // Draw all game objects
                try {
                    for (GameObject object : GameUtils.gameObjList)
                        object.paintSelf(gImage);
                } catch (Exception ignored) {  // FIXME null pointer exception
                }
                GameUtils.gameObjList.removeAll(GameUtils.removeList); // Delete the object from the list.
                /* FIXME
                 * System.out.println("removeList1111:" + GameUtils.removeList.size());
                 * System.out.println("gameObjList1111:" + GameUtils.gameObjList.size());
                 * System.out.println("removeList2222:" + GameUtils.removeList.size());
                 * System.out.println("gameObjList2222:" + GameUtils.gameObjList.size());
                 * 目前看来应该是列表GameUtils.removeList内存无法清理,导致内存堆积
                 * 下次试试全用GameUtils.gameObjList.remove(Object o);
                 * 代替GameUtils.removeList.add(); GameUtils.gameObjList.removeAll(GameUtils.removeList);
                 */

                // Boss warning
                if (enemyCount > bossAppear - 10 && enemyCount < bossAppear && BOSSObj == null) {
                    if (play_warn_sound) {
                        new Sound(GameUtils.basic_no12).start();
                        play_warn_sound = false;
                    }
                    gImage.drawImage(GameUtils.warning, 520.100.null);
                }
                break;
            case 2: // Pause the game
                gImage.drawImage(GameUtils.gamePauseImg, 5.20.null);
                gImage.setColor(Color.black);
                gImage.setFont(new Font(Microsoft Yahei, Font.BOLD, 20));
                gImage.drawString("' R 'Menu' T 'Exit' O 'Shop".430.700);
                if (T) {
                    System.exit(0);
                } // Press T to exit
                if (R) {
                    init();
                    R = false;
                } // Press R to return to the main screen
                break;
            case 3: // The game failed
                // The background music is off
                gImage.drawImage(GameUtils.gameFailureImg, 0.0.null);
                // Change the color of the brush
                gImage.setColor(Color.white);
                // Change the text size and style
                gImage.setFont(new Font(Microsoft Yahei, Font.BOLD, 60));
                // Add text
                gImage.drawString(score + "".220.268);
                gImage.drawString(Plane.plane_level + "".334.360);
                gImage.drawString(Plane.plane_life + "".334.500);
                gImage.drawString(Plane.plane_skill + "".334.575);

                gImage.setColor(Color.pink);
                gImage.drawString("Your difficulty is" + Popup.level + ",".545.348);
                gImage.drawString("Congratulations on your appointment." + Plane.plane_level + "I was blown up in grade ONE,".545.448);
                gImage.drawString("It's a very good dish!".545.548);

                gImage.setColor(Color.orange);
                gImage.setFont(new Font(Microsoft Yahei, Font.BOLD, 50));
                gImage.drawString("' R 'returns to main menu and' T 'exits the game.".200.700);
                if (end) {
                    new Sound(GameUtils.basic_no7).start();
                    end = false;
                }
                if (T) {
                    System.exit(0);
                } // Press T to exit
                if (R) {
                    init();
                    R = false;
                } // Press R to return to the main screen
                break;
            case 4: // Game win
                // Draw the victory interface text
                gImage.drawImage(GameUtils.gameVictoryImg, 5.20.null);
                gImage.setColor(Color.white);
                / / score
                gImage.setFont(new Font(Microsoft Yahei, Font.BOLD, 100));
                gImage.drawString(score + "".200.380);
                // Remaining blue/red
                gImage.setFont(new Font(Microsoft Yahei, Font.BOLD, 60));
                gImage.drawString(Plane.plane_life + "".334.535);
                gImage.drawString(Plane.plane_skill + "".334.610);
                / / evaluation
                gImage.setColor(Color.pink);
                gImage.setFont(new Font(Microsoft Yahei, Font.BOLD, 60));
                gImage.drawString("Congratulations on being here." + Popup.level + "In mode,".560.368);
                gImage.drawString("The enemy was successfully destroyed,".560.468);
                gImage.drawString("Very sharp indeed!".560.568);
                / / R exit
                gImage.setColor(Color.orange);
                gImage.setFont(new Font(Microsoft Yahei, Font.BOLD, 50));
                gImage.drawString("' R 'returns to main menu and' T 'exits the game.".200.700);
                // Play victory sound (only play once)
                if (end) {
                    new Sound(GameUtils.basic_no8).start();
                    end = false;
                }
                if (T) {
                    System.exit(0);
                } // Press T to exit
                if (R) {
                    init();
                    R = false;
                } // Press R to return to the main screen
                break;
        }

        // Keypoint draws the entire buffer onto the container's canvas
        g.drawImage(offScreenImage, 0.0.null);
        count++;   // The number of times the screen is drawn is increased
    }

    // Keypoint generates gameobjects
    public void createObj(a) {
        // Keypoint generates our bullets
        if(planeObj ! =null && count % planeShellFrequency == 0) {
            Image img = null;
            int x = planeObj.getX();
            if (Plane.plane_number == 1 || Plane.plane_number == 2) {
                x = planeObj.getX() + 22;
            }
            int y = planeObj.getY();
            int w = 0;
            int h = 0;
            int s = 0;
            switch (Plane.plane_level) {
                case 1:
                    img = GameUtils.planeShellImg;
                    x += 25;
                    y -= 10;
                    w = 21;
                    h = 40;
                    s = 8;
                    break;
                case 2:
                    planeShellFrequency = 15;
                    img = GameUtils.planeShellImg2;
                    x += 18;
                    y -= 15;
                    w = 28;
                    h = 27;
                    s = 10;
                    break;
                case 3:
                    planeShellFrequency = 12;
                    img = GameUtils.planeShellImg3;
                    x += 18;
                    y -= 15;
                    w = 45;
                    h = 27;
                    s = 13;
                    break;
                case 4:
                    planeShellFrequency = 12;
                    img = GameUtils.planeShellImg4;
                    x += 3;
                    y -= 30;
                    w = 65;
                    h = 33;
                    s = 13;
                    break;
                case 5:
                    planeShellFrequency = 12;
                    img = GameUtils.planeShellImg5;
                    x -= 36;
                    y -= 45;
                    w = 150;
                    h = 114;
                    s = 13;
                    break;
            }
            GameUtils.planeShellList.add(new PlaneShell(img, x, y, w, h, s, this));
            GameUtils.gameObjList.add(GameUtils.planeShellList.get(GameUtils.planeShellList.size() - 1));
        }
        // Keypoint generates enemy bullets
        if (count % enemyShellFrequency == 0&& BOSSObj ! =null) {
            Image img = null;
            int x = BOSSObj.getX();
            int y = BOSSObj.getY();
            int w = 0;
            int h = 0;
            int s = 0;
            switch (BOSS.number) {
                case 1:
                    img = GameUtils.enemyShellImg;
                    x += 110;
                    y += 92;
                    w = 47;
                    h = 40;
                    s = 6;
                    break;
                case 2:
                    enemyShellFrequency = 25;
                    img = GameUtils.enemyShellImg2;
                    x += 50;
                    y += 130;
                    w = 25;
                    h = 25;
                    s = 8;
                    break;
                case 3:
                    enemyShellFrequency = 25;
                    img = GameUtils.enemyShellImg3;
                    x += 60;
                    y += 145;
                    w = 51;
                    h = 51;
                    s = 8;
                    break;
                case 4:
                    enemyShellFrequency = 30;
                    img = GameUtils.enemyShellImg4;
                    x += 60;
                    y += 90;
                    w = 105;
                    h = 50;
                    s = 6;
                    break;
                case 5:
                    enemyShellFrequency = 30;
                    img = GameUtils.enemyShellImg5;
                    x += 55;
                    y += 100;
                    w = 135;
                    h = 140;
                    s = 8;
                    break;
            }
            GameUtils.enemyShellList.add(new EnemyShell(img, x, y, w, h, s, this));
            GameUtils.gameObjList.add(GameUtils.enemyShellList.get(GameUtils.enemyShellList.size() - 1));
        }
        // Keypoint generates enemy aircraft
        if (count % enemyFrequency == 0) {
            Image img = null;
            int w = 0;
            int h = 0;
            int s = 0;
            switch (Plane.plane_level) {
                case 1:
                    img = GameUtils.enemy1Img;
                    w = 128;
                    h = 128;
                    s = 6;
                    break;
                case 2:
                    sound3.start();
                    sound3.loop();
                    enemyFrequency = 22;
                    img = GameUtils.enemy2Img;
                    w = 63;
                    h = 46;
                    s = 9;
                    break;
                case 3:
                    enemyFrequency = 17;
                    img = GameUtils.enemy2Img;
                    w = 63;
                    h = 46;
                    s = 12;
                    break;
                case 4:
                    sound3.stop();
                    enemyFrequency = 25;
                    img = GameUtils.enemy3Img;
                    w = 100;
                    h = 57;
                    s = 8;
                    break;
                case 5:
                    enemyFrequency = 25;
                    img = GameUtils.enemy4Img;
                    w = 120;
                    h = 57;
                    s = 8;
                    break;
            }
            // x = (int) (Math.random() * 9) * 138; // Random x coordinates for enemy aircraft generation
            GameUtils.enemyList.add(new Enemy(img, (int) (Math.random() * 9) * 138, -100, w, h, s, this));
            GameUtils.gameObjList.add(GameUtils.enemyList.get(GameUtils.enemyList.size() - 1));
            enemyCount++;
        }
        // Keypoint generates enemy 2 (Level 3)
        if (count % 40= =0 && (BOSS.number == 4 || BOSS.number == 5)) {
            Image img;
            int w, h, s;
            if (BOSS.number == 4) {
                img = GameUtils.enemy4Img;
                w = 120;
                h = 57;
                s = 7;
            } else {
                img = GameUtils.enemy3Img;
                w = 100;
                h = 57;
                s = 6;
            }
            GameUtils.enemyList.add(new Enemy(img, (int) (Math.random() * 9) * 138, -100, w, h, s, this));
            GameUtils.gameObjList.add(GameUtils.enemyList.get(GameUtils.enemyList.size() - 1));
            enemyCount++;
        }

        // Keypoint generates BOSS
        if (enemyCount % bossAppear == 0 && BOSSObj == null) {
            play_warn_sound = true;
            BOSS.number += 1;
            Image img = null;
            int w = 0;
            int h = 0;
            int s = 0;
            switch (BOSS.number) {
                case 1:
                    if (play_BOSS_sound) {
                        new Sound(GameUtils.run_no3).start();
                        play_BOSS_sound = false;
                    }
                    img = GameUtils.bossImg;
                    w = 234;
                    h = 170;
                    s = 3;
                    bossAppear = 100;
                    break;
                case 2:
                    if(! play_BOSS_sound) {new Sound(GameUtils.run2_no2).start();
                        play_BOSS_sound = true;
                    }
                    img = GameUtils.bossImg2;
                    w = 125;
                    h = 157;
                    s = 4;
                    bossAppear = 100;
                    break;
                case 3:
                    if (play_BOSS_sound) {
                        new Sound(GameUtils.run2_no3).start();
                        play_BOSS_sound = false;
                    }
                    img = GameUtils.bossImg3;
                    w = 151;
                    h = 165;
                    s = 5;
                    bossAppear = 90;
                    break;
                case 4:
                    if(! play_BOSS_sound) {new Sound(GameUtils.run3_no3).start();
                        play_BOSS_sound = true;
                    }
                    img = GameUtils.bossImg4;
                    w = 234;
                    h = 98;
                    s = 6;
                    bossAppear = 80;
                    break;
                case 5:
                    if (play_BOSS_sound) {
                        new Sound(GameUtils.run3_no4).start();
                        play_BOSS_sound = false;
                    }
                    img = GameUtils.bossImg5;
                    w = 234;
                    h = 114;
                    s = 6;
                    break;
            }
            BOSSObj = new BOSS(img, 250.30, w, h, s, this);
            GameUtils.gameObjList.add(BOSSObj);
        }
        // Keypoint generates the gift
        if (count % 500= =0) {
            // x = (int) (Math.random() * 9) * 138; Random X coordinates for gift generation
            GameUtils.giftList.add(new Gift(GameUtils.giftImg1, (int) (Math.random() * 9) * 138, -100.60.102.4.this));
            GameUtils.gameObjList.add(GameUtils.giftList.get(GameUtils.giftList.size() - 1));
        }
        // Keypoint generates gift 2 (random skill)
        if (count % 850= =0) {
            GameUtils.giftList2.add(new Gift2(GameUtils.giftImg2, (int) (Math.random() * 9) * 138, -100.65.63.5.this));
            GameUtils.gameObjList.add(GameUtils.giftList2.get(GameUtils.giftList2.size() - 1));
        }
        // Keypoint drawing skills
        if (Skill.release) {
            Skill.release = false;
            skill_release = true;
            assertplaneObj ! =null;
            int x = planeObj.getX();
            int y = planeObj.getY();
            int w = 0;
            int h = 0;
            int s = 0;
            Image img = null;
            // Keypoint standard skills
            switch (Skill.number) {
                case 1:
                    if (Plane.plane_skill >= skillConsume) {
                        Plane.plane_skill -= skillConsume;
                        // Keypoint random skill
                        switch (Gift2.number) {
                            case 4:
                                x -= 40;
                                y -= 40;
                                w = 133;
                                h = 180;
                                s = 15;
                                img = GameUtils.skillImg4; // Lightning fire volle-1
                                new Sound(GameUtils.skill_no2).start();
                                break;
                            case 5:
                                x -= 50;
                                y -= 20;
                                w = 166;
                                h = 201;
                                s = 10;
                                img = GameUtils.skillImg5; // Dragon Scroll 1 (move with fighter X)
                                new Sound(GameUtils.skill_no7).start();
                                break;
                            case 6:
                                x -= 60;
                                y -= 20;
                                w = 201;
                                h = 166;
                                s = 20;
                                img = GameUtils.skillImg6; // Lightning Blade-1
                                new Sound(GameUtils.skill_no3).start();
                                break;
                            case 7:
                                x -= 60;
                                y -= 80;
                                w = 201;
                                h = 201;
                                s = 5;
                                img = GameUtils.skillImg7; / / black hole - 3
                                new Sound(GameUtils.skill_no4).start();
                                break;
                            case 8:
                                x -= 40;
                                y -= 80;
                                w = 157;
                                h = 165;
                                s = 10;
                                img = GameUtils.skillImg8; // Mars Sphere 2 (Tracking boss)
                                new Sound(GameUtils.skill_no6).start();
                                break;
                            case 9:
                                x -= 40;
                                y -= 50;
                                w = 166;
                                h = 201;
                                s = 15;
                                img = GameUtils.skillImg9; // Starshine aura-1
                                new Sound(GameUtils.skill_no5).start();
                                break;
                            case 10:
                            default:
                                x -= 60;
                                y -= 10;
                                w = 200;
                                h = 93;
                                s = 12;
                                img = GameUtils.skillImg1; // Do not die -1
                                new Sound(GameUtils.skill_no1).start();
                                break; }}break;
                case 2:
                    if (Plane.plane_skill >= skillConsume) {
                        Plane.plane_skill -= skillConsume;
                        x -= 60;
                        y -= 20;
                        img = null;
                        new Sound(GameUtils.skill_no8).start();
                    }
                    break;
                case 3:
                    x -= 15;
                    img = GameUtils.skillImg3;
                    new Sound(GameUtils.skill_no9).start();
                    break;
            }
            GameUtils.skillList.add(new Skill(img, x, y, w, h, s, this));
            GameUtils.gameObjList.add(GameUtils.skillList.get(GameUtils.skillList.size() - 1));
            Skill.release = false;
        }

        / / Keypoint god beast
        if (MAAppear) {
            MAAppear = false;
            Image img = null;
            int w = 63;
            int h = 63;
            int s = 0;
            switch (MAnimals.MAnimalsNumber) {
                case 1:
                    s = 5;
                    img = GameUtils.commodityImg1;
                    break;
                case 2:
                    s = 8;
                    img = GameUtils.commodityImg2;
                    break;
                case 3:
                    s = 15;
                    img = GameUtils.commodityImg3;
                    break;
            }
            assertplaneObj ! =null;
            mAnimalsObj = new MAnimals(img, planeObj.getX(), planeObj.getY(), w, h, s, this);
            GameUtils.gameObjList.add(mAnimalsObj);
            MAExist = true;
        }

        // Keypoint aircraft return health/return blue
        if (count % lifeRecovery == 0 && Plane.plane_life < Plane.record_plane_life)
            Plane.plane_life++;
        if (count % skillRecovery == 0&& Plane.plane_skill < Plane.record_plane_skill) Plane.plane_skill++; }}Copy the code

The shop class


public class Popup_Shop extends JFrame {
    boolean buy = false;
    int price1 = 500, price2 = 799, price3 = 888, price4 = 800, price5 = 800;

    public Popup_Shop(a) {
        new Sound(GameUtils.basic_no11).start();
        init();
    }

    public void init(a) {
        / / that
        JLabel jLabel = new JLabel("Choose goods to buy :");
        jLabel.setFont(new Font("acetone-family", Font.BOLD, 15));
        jLabel.setBounds(10.10.200.20);

        JLabel jLabel2 = new JLabel("-------------------- Current gold coins:" + Plane.goldNumber + "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --");
        jLabel2.setFont(new Font("acetone-family", Font.BOLD, 15));
        jLabel2.setBounds(130.150.800.20);

        // Label text
        JRadioButton option1 = new JRadioButton("Swallow the sky purple and gold sable (" + price1 + "$)");
        JRadioButton option2 = new JRadioButton("Nine Shades of phoenix (" + price2 + "$)");
        JRadioButton option3 = new JRadioButton("Tai Xu Gu Long (" + price3 + "$)");
        JRadioButton option4 = new JRadioButton("HP + 1 (" + price4 + "$)");
        JRadioButton option5 = new JRadioButton("Skill + 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);

        / / radio
        ButtonGroup group = new ButtonGroup();
        group.add(option1);
        group.add(option2);
        group.add(option3);
        group.add(option4);
        group.add(option5);

        // Tag image
        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);

        // Buy button
        JPanel jPanel = new JPanel();
        JButton button = new JButton("Buy");
        button.setFont(new Font("acetone-family", Font.BOLD, 20));
        jPanel.setLayout(null);
        button.setBounds(255.180.90.50);
        jPanel.add(button);
        jPanel.setVisible(true);

        // Add the component to the panel
        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);

        // Panel Settings
        this.setTitle("Super Mystery Store.");
        this.setVisible(true);
        this.setResizable(false);
        this.setSize(630.280);
        this.setLocationRelativeTo(null);
        this.repaint();

        / / to monitor
        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("Buy: Swallow sky Purple and Gold Mink (" + 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("Buy: Nine Shades of Phoenix (" + 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("Buy: Taixu Gulong (" + 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("Purchase :(" + 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("Purchase: Skill +1(" + price5 + "$)");
            }
            new Sound(GameUtils.basic_no10).start();

            // Prompt popup
            boolean select = (option1.isSelected() || option2.isSelected() || option3.isSelected() || option4.isSelected() || option5.isSelected());

            if(! select) { JOptionPane.showMessageDialog(null."Please select what you want!"."Super Mystery Store reminder.", JOptionPane.WARNING_MESSAGE);
            } else if(! buy) { JOptionPane.showMessageDialog(null."Not enough gold, brother!"."Super Mystery Store reminder.", JOptionPane.ERROR_MESSAGE);
            } else if ((option1.isSelected() || option2.isSelected() || option3.isSelected()) && GamePanel.MAExist) {
                JOptionPane.showMessageDialog(null."There is a beast, do not take too many."."Super Mystery Store reminder.", JOptionPane.ERROR_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(null."Purchase successful!!" + "Remaining gold:" + Plane.goldNumber, "Super Mystery Store reminder.", JOptionPane.INFORMATION_MESSAGE);
                this.dispose(); }}); }}Copy the code

conclusion

Through the realization of the game “Aircraft War III”, I have a further understanding of swing related knowledge and a deeper understanding of Java language than before.

Basic Java syntax, such as data types, operators, program flow control, and arrays, is better understood. Java is the core of the core object oriented thought, for this concept, finally realized some.

The source code for

After clicking “like” and following the blogger, the private blogger will get it for free