介绍
这篇文章主要介绍java怎么实现飞扬的小鸟游戏,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
具体内容如下
/* 2017/7/23 */, import java.awt.Graphics;//import java.util.Timer; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import java.awt.event.KeyListener; import java.awt.event.KeyEvent; import java.awt.Rectangle; import java.awt。*; , import java.util。*; , import javax.swing.JFrame; import javax.swing.Timer; import javax.swing。*; , , import javax.swing.JPanel; , class Renderer  extends JPanel { , ,private static  final long  serialVersionUID =, 1 l; , ,protected void  paintComponent (Graphics g) ,{ ,super.paintComponent (g); , ,FlappyBird.flappyBird.repaint (g); ,} , } public class  FlappyBird implements  ActionListener,, MouseListener, KeyListener { ,public static  FlappyBird flappyBird; , ,public final  int WIDTH =, 900年,HEIGHT =, 800; , ,public Renderer 渲染器; , 鸟,public Rectangle ; , ,public ArrayList< Rectangle>,列,, , ,public int ,蜱虫,yMotion,,分数; , public boolean 败阵,大敌;开始; , ,public Random 兰德; , ,public FlappyBird () ,{ ,JFrame JFrame =, new JFrame (); ,Timer Timer =, new 计时器(20日); ,=,,renderer  new 渲染器();=,,rand  new 随机(); , ,jframe.add(渲染器); ,jframe.setTitle (“Flappy Bird"); ,jframe.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); ,jframe.setSize(宽度、高度); ,jframe.addMouseListener(这个); ,jframe.addKeyListener(这个); ,jframe.setResizable(假); ,jframe.setVisible(真正的); ,=,,bird  new 矩形(时间/WIDTH 2,安康,10日,HEIGHT /, 2,安康;10,20日,20); ,=,,columns  new ArrayList(); , ,addColumn(真正的); ,addColumn(真正的); ,addColumn(真正的); ,addColumn(真正的); , ,timer.start (); ,} , ,public void  addColumn (boolean 开始) ,{ ,int space =, 300; ,int width =, 100; 50,int height =,, +, rand.nextInt (300); , ,如果(开始) ,{ ,columns.add (new 矩形(WIDTH +, WIDTH +, columns.size(), *, 300年,HEIGHT 作用;HEIGHT 作用;120年,宽度,高度)); ,columns.add (new 矩形(WIDTH +, WIDTH +, (columns.size() 1) * 300, 0,,宽度,,HEIGHT 作用;HEIGHT 作用;空间)); ,} 其他的, ,{ ,columns.add (new 矩形(columns.get (columns.size(),安康;1).x +, 600年,HEIGHT 作用;HEIGHT 作用;120年,宽度,高度)); ,columns.add (new 矩形(columns.get (columns.size(),安康;1).x ,, 0,,宽度,,HEIGHT 作用;HEIGHT 作用;空间)); ,} , ,} , ,public void  paintColumn (Graphics g, Rectangle 列) ,{ ,g.setColor (Color.green.darker ()); ,g.fillRect (column.x, column.y,, column.width,, column.height); ,} , ,public void 跳() ,{ ,if (游戏结束) ,{=,,bird  new 矩形(时间/WIDTH 2,安康,10日,HEIGHT /, 2,安康;10,20日,20); , ,columns.clear (); ,=,yMotion 0;=,score 0; , ,addColumn(真正的); ,addColumn(真正的); ,addColumn(真正的); ,addColumn(真正的); ,=,gameOver 假; ,} , ,如果开始(!) ,{=,started 真实; ,} ,else 如果(!游戏结束) ,{ ,如果(yMotion 祝辞,0) ,{=,yMotion 0; ,} , -=,yMotion 10; ,} ,} , ,public void  actionPerformed (ActionEvent e) ,{ , ,int speed =, 10; , ,蜱虫+ +; , ,如果(started ) ,{ ,(,int 小姐:=,0;,小姐:& lt;, columns.size();,我+ +) ,{ ,Rectangle column =, columns.get(我); , -=,column.x 速度; ,} , %,如果(ticks 2,==0,,,, yMotion & lt;, 15) ,{ +=,yMotion 2; ,} , ,for (int 小姐:=,0;,小姐:& lt;, columns.size();,我+ +) ,{ ,Rectangle column =, columns.get(我); , null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null java怎么实现飞扬的小鸟游戏