Java mini-game airplane (i)
20150809
Afternoon wrote an afternoon, the basic structure of the fight plane has been written, the following to specify the function and source code:
Let's look at the running interface:
Game run in pictures
The upper left corner is a hero machine, yellow is bullets, Hero Machine's task is to hide bullets, Hero machine can move through the keyboard in all directions to hide bullets, the more bullets, the higher the level. Bullets can bounce when they encounter walls.
End of Game interface
Once the hero machine is hit by a bullet, there will be an explosion effect, then the game ends, the print level and the total game time.
Project Structure diagram:
Deep Analysis:
From the interface can be seen, there is a hero machine class, bullets, and then a main interface class, the specific processing time, due to the extension of the program and data encapsulation, built a toolkit, the common methods and constants to encapsulate, facilitate the invocation of other classes and code reuse.
The constant class encapsulates the constants used in the game, which only encapsulates the width and height of the main interface, and if the project is larger, it can encapsulate more constants and make it easier for other classes to invoke.
The Gameutil class encapsulates the methods used in the game, and this is just a way to load a picture.
The MyFrame class encapsulates the interface-related properties and methods, and if there are other interfaces, inherit the class directly.
Hero Machine class and bullets have a common part of the properties, such as the case, coordinates, moving speed, the width and height of the picture, etc., so encapsulate a gameobject class, the basic attributes are encapsulated, so that the subsequent addition of other objects, the extension of the program becomes better.
Plane class is the Hero machine class, there is a hero machine to move the method, through the keyboard can control the movement in all directions, follow-up want to change to mouse control.
Bullet class is a bullet class, which encapsulates the movement angle, trajectory, speed and other methods of bullets.
Expode class is mainly to achieve a bullet hit hero machine An explosion effect, is to draw a series of continuous explosion pictures.
Due to the time problem, there are some bugs in the program is not resolved, will be resolved tomorrow after the specific details of the problem and the various types of source issued, please look forward to ...
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java mini-game airplane (i)