• 期末设计(十三周)


    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    
    import javax.swing.JFrame;
    
    package cumin.planewar;
    
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    
    import javax.swing.JFrame;
    
    public class MainFrame extends JFrame {
    
        /**
         * @param args
         */
        public static final int FRAME_HEIGHT = 800;
        public static final int FRAME_WIDIH = 480;
    
        Image cacheImage = null;
        private Image background = null;
        private Image wait = null;
        private Image result = null;
        
        //手柄控制类
        Handle controller = null;
    
        /**
         * 游戏窗口显示构造函数
         */
        public MainFrame() {
            // 游戏窗口
            this.setLocation(0, 0);
            this.setSize(FRAME_WIDIH, FRAME_HEIGHT);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            background = Toolkit.getDefaultToolkit().createImage("res/背景.png");
            wait = Toolkit.getDefaultToolkit().createImage("res/暂停界面.png");
            result = Toolkit.getDefaultToolkit().createImage("res/result_t.png");
    
            // 游戏窗口监听器
            this.addKeyListener(new MyKeyListener());
    
            // 游戏开始
            this.setVisible(true);
            
        }
    
    
    @Override
        public void paint(Graphics g) {
            if (controller.getGameState() == Handle.GAMESTATE_START)
                controller.onDraw(g);
            else if (controller.getGameState() == Handle.GAMESTATE_STOP) {
    
                g.drawImage(result, FRAME_WIDIH / 2 - 160, FRAME_HEIGHT / 2 - 115, null);
                g.drawString("" + controller.getScore(), FRAME_WIDIH / 2 - 10, FRAME_HEIGHT / 2);
            }
        }
    
        @Override
        public void update(Graphics g) {
            // super.update(g);
            if (cacheImage == null)
                cacheImage = this.createImage(FRAME_WIDIH, FRAME_HEIGHT);
    
            Graphics gCacheImage = cacheImage.getGraphics();
            gCacheImage.drawImage(background, 0, 0, FRAME_WIDIH, FRAME_HEIGHT, null);
            this.paint(gCacheImage);
            g.drawImage(cacheImage, 0, 0, null);
        }
    
        public static void main(String[] args) {
            // 主游戏开启
            MainFrame mf = new MainFrame();
        }
    
    }

  • 相关阅读:
    Es索引优化
    Echarts-JAVA
    黑客容易攻击的端口
    基于流数据挖掘的网络流量异常检测及分析研究
    大数据可视化分析-绿盟
    Cron
    spring mvc 使用及json 日期转换解决方案
    PIXLCLOUND
    Moloch
    MySQL JDBC的setFetchSize
  • 原文地址:https://www.cnblogs.com/gentleman-g/p/5534927.html
Copyright © 2020-2023  润新知