Java instance-tank wars and java instance tank wars
JavaInstance-Tank warsI. sample image
Ii. class graph Structure
All classes in tank wars
Class Relationship Diagram
My tanks
Iii. Description
1. Every new thing that runs independently is a thread, like our tanks, like enemy tanks, like all bullets.
2. Each thread must implement the run method and start the thread.
3. No matter tanks or bullets, they all have life, coordinates (static), speed, and moving directions (motion)
4. The movement of tanks and bullets is achieved by the refresh coordinates after the coordinates are modified.
5. the bullets in the tank are all painted in the JPanel, And the repainting can show all the movements.
6. the continuous movement of bullets is realized through the endless loop in the run method, that is, constant coordinate transformation.
7. The keyboard action is monitored by the keyboard.
8. Multiple Threads are stored by collection classes, such as a collection of bullets and an array of enemy tanks.
9. the animation of your tank is caused by the repaint in the keyboard event. the animation of the enemy tank is caused by the call of the start function of the MyPanel thread on the Tank1 interface. The repaint function is available in the run interface.
10. The essence of running repaint is to call the paint function again, so we need to check what is in the paint.
11. In the paint function, I can draw anything with life. I can draw as many as I can, for example, our tanks, enemy tanks, our bullets, and enemy bullets.
12. drawing enemy bullets requires a dual loop. It is better to draw them together with enemy tanks.
13. A bullet can be drawn only when it is fired.
4. Code
Code on Baidu Disk: http://pan.baidu.com/s/1hrYFjxU
(1) Main Interface: TankWarUI class
(2) tanks in war zones: MyPanel
(3) Bullet: Bullet class
(4) tanks: Tank
(5) My Tank Class: MyTank class
(6) enemy tanks: EnemyTank