日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

王思聪吃热狗 - 飞机大战小游戏

發布時間:2023/12/14 编程问答 86 豆豆
生活随笔 收集整理的這篇文章主要介紹了 王思聪吃热狗 - 飞机大战小游戏 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.



這個小游戲是用java寫的,java swing, 源碼比較簡單,一般都能看懂 ,素材找不到,看著比較low,如果你找到熱狗飛機圖片,改一下就好




運行結果圖:

**

圖片素材:

**
https://blog.csdn.net/qq_40456064/article/details/84787388

分為8個class:

1. Bullet.java
2. GetImage.java
3. MyGame.java
4. Plane.java
5. SiCongPlaneFight_Main.java
6. Stone.java
7. Table.java
8. Window.java

程序入口在

SiCongPlaneFight_Main.java

  • Bullet.java:
  • /*** 子彈類 - 熱狗子彈* @ClassName: bullet* @Description: TODO* @author GatesMa* @date 2018年12月3日* @Email: gatesma@foxmail.com*/ import java.awt.*;public class Bullet {int x, y;//子彈的坐標Image i;boolean destory = false;Stone stone[];Bullet(Image img, int x,int y, Stone stone[]){this.x = x;this.y = y;this.i = img;this.stone = stone;}void shot() {y -= Table.table*2;}void draw(Graphics g) {g.drawImage(i, x, y, Table.size/2, Table.size, null);ifdestroy();shot();}void ifdestroy() {if(this.y < 0) {destory = true;}for(int i =0;i < stone.length; i++) {if(stone[i] != null) {if(stone[i].x-Table.size/2<this.x&&this.x<(stone[i].x+Table.size/2)&&this.y>stone[i].y-Table.size/2&&this.y<stone[i].y+Table.size/2) {stone[i].live--;destory = true;}}}} }
  • GetImage.java
  • /*** 圖片導入工具類* @ClassName: GetImage* @Description: TODO* @author GatesMa* @date 2018年12月3日* @Email: gatesma@foxmail.com*/ import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL;import javax.imageio.ImageIO;public class GetImage {//此類封裝了方法獲取圖片 private GetImage() {}//工具類封裝構造public static BufferedImage get(String path) {URL u= GetImage.class.getClassLoader().getResource(path);//獲取到圖片的資源BufferedImage b = null;try {b=ImageIO.read(u);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return b;} }
  • MyGame.java
  • /*** 圖片導入工具類* @ClassName: GetImage* @Description: TODO* @author GatesMa* @date 2018年12月3日* @Email: gatesma@foxmail.com*/ import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL;import javax.imageio.ImageIO;public class GetImage {//此類封裝了方法獲取圖片 private GetImage() {}//工具類封裝構造public static BufferedImage get(String path) {URL u= GetImage.class.getClassLoader().getResource(path);//獲取到圖片的資源BufferedImage b = null;try {b=ImageIO.read(u);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return b;} }
  • Plane.java
  • /*** 飛機類 - 熱狗炮彈* @ClassName: Plane* @Description: TODO* @author GatesMa* @date 2018年12月3日* @Email: gatesma@foxmail.com*/ import java.awt.*;import javax.swing.ImageIcon;public class Plane {int x, y;Image i;boolean destory = false;Stone stone[];double step = Table.table;private boolean left, right, up, down;public boolean isLeft() {return left;}public void setLeft(boolean left) {this.left = left;}public boolean isRight() {return right;}public void setRight(boolean right) {this.right = right;}public boolean isUp() {return up;}public void setUp(boolean up) {this.up = up;}public boolean isDown() {return down;}public void setDown(boolean down) {this.down = down;}Plane(Image bi1,int x,int y,Stone stone[]){this.i = bi1;this.x = x;this.y = y;this.stone = stone;}public void move() {if(MyGame.count >= 2) {step = Table.table / 1.414;}else {step = Table.table;}if(left && x > 0) {this.x -= step;}if(right && x < Table.width - Table.size) {this.x += step;}if(up && y > 0){this.y -= step;}if(down && y < Table.height - Table.size) {this.y += step;}}public void draw(Graphics g) {move();ifdestory();g.drawImage(i, x, y, Table.size, Table.size, null);}private void ifdestory() {for(int i =0;i < stone.length;i++) {if(stone[i] != null) {if(stone[i].x - Table.size/2 < this.x && this.x < (stone[i].x+Table.size/2)&&this.y>stone[i].y-Table.size/2&&this.y<stone[i].y+Table.size/2) {destory=true;}}}} }
  • SiCongPlaneFight_Main.java
  • /*** 主程序入口* @ClassName: SiCongPlaneFight_Main* @Description: TODO* @author GatesMa* @date 2018年12月3日* @Email: gatesma@foxmail.com*/ public class SiCongPlaneFight_Main {public static void main(String[] args) {// TODO Auto-generated method stubnew MyGame();}}
  • Stone.java
  • /*** 障礙物類 - 思聰頭像* @ClassName: Stone* @Description: TODO* @author GatesMa* @date 2018年12月3日* @Email: gatesma@foxmail.com*/ import java.awt.*; import java.util.Random; public class Stone {int x, y;Image i;Plane p;int live;boolean destory = false;public Stone(Image i, Plane p,int live) {this.x = getRandom();this.y = 0;this.i = i;this.p = p;this.live = live;}int getRandom() {Random r = new Random();return r.nextInt(550) + 20;}void draw(Graphics g) {g.drawImage(i, x, y, 50, 50, null);ifdestory();movegetclose();}private void movegetclose() {y += 2;}void ifdestory() {if(live <= 0) {destory = true;MyGame.score++;}if(this.y > Table.height) {destory = true;}} }
  • Table.java
  • /*** 窗口大小存儲 * @ClassName: Table* @Description: TODO* @author GatesMa* @date 2018年12月3日* @Email: gatesma@foxmail.com*/ public class Table {public static double table=10; public static int size=50;//飛機和炮彈大小public static int width=600;//窗口的大小public static int height=700; }
  • Window.java
  • /*** 失敗窗口 - 重開游戲或者退出* @ClassName: Window* @Description: TODO* @author GatesMa* @date 2018年12月3日* @Email: gatesma@foxmail.com*/ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import javax.swing.*; public class Window extends JFrame{private JTextField t1;private JButton btn1;private JButton btn2;boolean ificansee = true;Window(){super("這么快就結束了???");setBounds((400 + Table.width), (Table.height / 4), 500, 100);setVisible(ificansee);t1 = new JTextField("是否重新開始?");t1.setEnabled(false);btn1 = new JButton("重新開始");btn2 = new JButton("退出");btn1.setBounds(31, 13, 13, 13);btn2.setBounds(31, 13, 13, 13);Container c1 = getContentPane();c1.setLayout(new FlowLayout());//c1.add(t1);c1.add(btn1);c1.add(btn2);addListener();setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}private void addListener() {btn1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubMyGame.replay = true;dispose();}});btn2.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubSystem.exit(0);}});} }

    總結

    以上是生活随笔為你收集整理的王思聪吃热狗 - 飞机大战小游戏的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。