Home >Java >javaTutorial >Recommended source code courseware for Horse Soldier JAVA tank game video
Tank Battle Game is a very classic JAVASE basic project. You can comprehensively practice each chapter of the "Horse Soldier JAVA Tank Game Video Tutorial" to lay a solid foundation for future work and study. Learn Java step by step from entry to The Mastery of Medium Tank Battle project is fully explained, and the topic is accompanied by the materials used and the source code in the video. The video first starts with the swing interface and introduces the event processing method and the implementation principle of the io interface in Java.
Course playback address: http://www.php.cn/course/513.html
The teacher’s teaching style:
The teacher’s lectures are simple, clear, layer-by-layer analysis, interlocking, rigorous argumentation, rigorous structure, using the logical power of thinking to attract people Students' attention and rational control of the classroom teaching process. By listening to teachers' lectures, students not only learn knowledge, but also receive thinking training, and are also influenced and influenced by teachers' rigorous academic attitude.
The more difficult part in this video is to add the explosion:
1. Write the Bomb class, Since the dynamic effect of the explosion is formed by rapid switching of multiple pictures, the life of the explosion is set here, and the life is reduced sequentially to achieve the switching of pictures
class Bomb { int x; int y; //*的生命 int life = 9; boolean isLive = true; public Bomb(int x,int y){ this.x=x; this.y=y; } //减少生命值 public void lifeDown(){ if(life>0){ life--; } else{ isLive = false; } } }
##2. Define the explosion collection in MyPanel and initialize the explosion pictures
Vector<Bomb> bombs = new Vector<Bomb>(); Image image1 = null; Image image2 = null; Image image3 = null; Image image4 = null; Image image5 = null; Image image6 = null; Image image7 = null; Image image8 = null; // 初始化图片 image1 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/blast1.gif")); image2 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/blast2.gif")); image3 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/blast3.gif")); image4 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/blast4.gif")); image5 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/blast5.gif")); image6 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/blast6.gif")); image7 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/blast7.gif")); image8 = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/blast8.gif"));3. Draw *. Since the screen repaint is very fast, the picture switches to form an explosion effect
for(int i=0;i<bombs.size();i++){ //取出* Bomb b = bombs.get(i); //System.out.format("%d",++num); if(b.life>8){ g.drawImage(image1, b.x, b.y, 30, 30, this); }else if(b.life>7){ g.drawImage(image2, b.x, b.y, 30, 30, this); }else if(b.life>6){ g.drawImage(image3, b.x, b.y, 30, 30, this); }else if(b.life>5){ g.drawImage(image4, b.x, b.y, 30, 30, this); }else if(b.life>4){ g.drawImage(image5, b.x, b.y, 30, 30, this); }else if(b.life>3){ g.drawImage(image6, b.x, b.y, 30, 30, this); }else if(b.life>2){ g.drawImage(image7, b.x, b.y, 30, 30, this); }else if(b.life>1){ g.drawImage(image8, b.x, b.y, 30, 30, this); } b.lifeDown(); System.out.format("1+%d\n",i); //如果life为 0 酒吧*从bombs向量去掉 if(b.life==0){ bombs.remove(b); } }
Here I give it to everyone It is recommended to download source code resources: http://www.php.cn/xiazai/learn/1942
This video courseware is shared with everyone: 1. Shangxuetang Horse Soldier Tank Battle Video Tutorial Notes.pdfThe above is the detailed content of Recommended source code courseware for Horse Soldier JAVA tank game video. For more information, please follow other related articles on the PHP Chinese website!