欢迎来到天天文库
浏览记录
ID:15431925
大小:25.85 KB
页数:41页
时间:2018-08-03
《java坦克大战.(java tank war .)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、java坦克大战3.61(Javatankwar3.61)/**Battleoftanks3.61BothtankscanmoveandshootbulletsEnemytankscanbehitanddisappear*explosioneffectsTheeffectofexplosionisreplacedbyellipsedrawing**/PackageTankGame4;//packageMyTankGame4;Importjava.util.Vector;Importjava.awt.*;Impor
2、tjava.awt.event.KeyEvent;Importjava.awt.event.KeyListener;Importjava.util.*;Importjavax.swing.*;PublicclassMyTankGame4extendsJFrame{MyPanelmp=null;Publicstaticvoidmain(String[]args){MyTankGame4mytankgame1=newMyTankGame4();}PublicMyTankGame4(){Mp=newMyPanel();
3、Start//MPthreadThreadt=newThread(MP);T.start();This.add(MP);This.addKeyListener(MP);This.setSize(400300);This.setVisible(true);This.setDefaultCloseOperation(EXIT_ON_CLOSE);}}ClassMyPanelextendsJPanelimplementsKeyListener,Runnable{//definemytanks,membervariabl
4、esHerohero=null;Thedefinitionoftheenemytank/groupVectorets=newVector();IntenSize=5;Thedefinitionofabombset//Vectorbombs=newVector();Publicvoidrun(){Everyonehundredmillisecondstoredrawthebullet//While(true){{tryThread.sleep(10
5、0);}catch(InterruptedExceptionE){Auto-generatedcatchblock//TODOE.printStackTrace();}For(inti=0;i6、emyTanket=ets.get(J);If(et.isLive){This.hitTank(myShot,et);}}}}This.repaint();Whetherornottojointhetank/newbulletsFor(inti=0;i75{//everytankbulletlessthan5words/7、/addShots=null;Switch(et.direct){Case0:S=newShot(et.x+9,et.y-1,0);Et.ss.add(s);Break;Case1:S=newShot(et.x+30,et.y+10,1);Et.ss.add(s);Break;Case2:S=newShot(et.x+9,et.y+30,2);Et.ss.add(s);Break;Case3:S=newShot(et.x-1,et.y+9,3);Et.ss.add(s);Break;}Thebullet/star8、tthreadThreadt=newThread(s);T.start();}}}}}公共空白漆(图形G){超级油漆(G);g.fillrect(0,0400300);//画出自己的坦克这个drawtank(英雄。getx(),英雄。gety(),G,this.hero.direct,1);//从矢量SS中取出每一颗子弹,并画出为(inti=0;i<这。英雄。SS。siz
6、emyTanket=ets.get(J);If(et.isLive){This.hitTank(myShot,et);}}}}This.repaint();Whetherornottojointhetank/newbulletsFor(inti=0;i75{//everytankbulletlessthan5words/
7、/addShots=null;Switch(et.direct){Case0:S=newShot(et.x+9,et.y-1,0);Et.ss.add(s);Break;Case1:S=newShot(et.x+30,et.y+10,1);Et.ss.add(s);Break;Case2:S=newShot(et.x+9,et.y+30,2);Et.ss.add(s);Break;Case3:S=newShot(et.x-1,et.y+9,3);Et.ss.add(s);Break;}Thebullet/star
8、tthreadThreadt=newThread(s);T.start();}}}}}公共空白漆(图形G){超级油漆(G);g.fillrect(0,0400300);//画出自己的坦克这个drawtank(英雄。getx(),英雄。gety(),G,this.hero.direct,1);//从矢量SS中取出每一颗子弹,并画出为(inti=0;i<这。英雄。SS。siz
此文档下载收益归作者所有