Good programmers develop Java learning routes Share FlappyBird help documentation

Good programmers develop Java learning routes Share FlappyBird help documentation, project requirements:

FlappyBird complete game.

1. Function:

After the game starts, intermittent click of a mouse, and let the bird fly up, not fall, and through the gap to the column, the column can not be met, hit it dead, and passed through a column of one point

2. The interface requirements:

Begin interface:

Click the mouse to start the game, the game interface:

At the end of the game interface:

 

3. Performance requirements:

Each game requires a mouse click, real-time response must be specified for the birds fly up height and speed of the birds have been declining, and the pillars have been circulating appeared, finally making birdie flexibility coherent shuttle to the post between.

4. development steps:

Project contains the main class Game.java, custom panel class BirdGame.java, small bird: Bird.java, pillar class Column.java, ground categories: Ground.java,

(1) Create a column class Column.java

Properties include:

Image BufferedImage, coordinates x, y, width and height of the image width, height

The number of column count (up to initialize the object two columns).

Constructor Column ():

Method moving column move ():

(2) Create Ground.java class

Load picture constructor to initialize the coordinates (0,500), create a method move

(3) Create Bird.java class

Load picture constructor to initialize the coordinates (190, 220), create up and down method

Create points addScore (Column c) method, when a bird principle abscissa abscissa equal to the column width of the column, i.e. when adding a plus points.

Create a ground collision method hitGround methods, principles tips, compare bird ordinate and ground ordinate.

 

Create a post collision detection method hitColumn

(4) Create BirdGame.java panel class that extends JPanel

state variable represents the state of the game, 0 is the start state, one that the state of the game, 2 game over state.

Constructor loading bg.png, start.png, gameover.png, initialization state = 0, initialization ground, bird, column1 column2 and objects.

重写paint方法public void paint(Graphics g)

利用g.drawImage方法绘制界面

显示分数

定义内部类MyMouseAdapter 继承MouseAdapter

重写mousePressed方法public void mousePressed(MouseEvent e)

根据当前游戏状态,更改鼠标点击后状态及对应对象坐标。

创建action方法,添加鼠标监听事件

无限循环(while(true))根据不同游戏状态调用bird,ground,column对象中的方法(利用switch case),然后利用线程延迟实现重复绘制

(5).创建Game.java作为运行主类,原理:

Main方法中创建JFrame对象,将BirdGame面板实例化后添加进JFrame对象中,最后调用BirdGame对象的action方法。

 

Guess you like

Origin www.cnblogs.com/gcghcxy/p/11352760.html