坦克大战java版Word文档格式.docx
《坦克大战java版Word文档格式.docx》由会员分享,可在线阅读,更多相关《坦克大战java版Word文档格式.docx(25页珍藏版)》请在冰豆网上搜索。
JMenujm=null;
JMenuItemjmi1,jmi2;
inti=1;
booleanover=false;
publicstaticvoidmain(String[]args){
//TODOAuto-generatedmethodstub
Mytankmytank=newMytank();
Threadt1=newThread(mytank);
t1.start();
}
publicMytank()
{
jmb=newJMenuBar();
jm=newJMenu("
游戏(G)"
);
jm.setMnemonic('
G'
jmi1=newJMenuItem("
开始游戏"
jmi2=newJMenuItem("
退出"
jmi1.setActionCommand("
newgame"
jmi2.setActionCommand("
exit"
jmi1.addActionListener(this);
jmi2.addActionListener(this);
jm.add(jmi1);
jm.add(jmi2);
jmb.add(jm);
msp=newmystartpanel(i);
Threadt=newThread(msp);
t.start();
this.add(msp);
this.setJMenuBar(jmb);
this.setSize(400,320);
this.setUndecorated(true);
this.setResizable(false);
this.setIconImage((newImageIcon("
image/tankicon.jpg"
)).getImage());
this.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
this.setTitle("
Tank3.0"
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
publicvoidactionPerformed(ActionEvente){
if(e.getActionCommand().equals("
))
{
mp=newmypanel();
Threadt=newThread(mp);
t.start();
this.remove(msp);
msp.islive=false;
this.add(mp);
jmi1.setEnabled(false);
this.addKeyListener(mp);
this.setVisible(true);
}elseif(e.getActionCommand().equals("
System.exit(0);
}
publicvoidrun(){
while(true)
try{
Thread.sleep(500);
}catch(InterruptedExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
if(msp.islive==false&
&
mp.ets.size()==0)
{
if(i==9)
{
gameovergameover=newgameover("
YES!
"
Threadt=newThread(gameover);
t.start();
this.remove(mp);
this.add(gameover);
this.setVisible(true);
break;
}
i++;
msp=newmystartpanel(i);
Threadt=newThread(msp);
t.start();
jmi1.setEnabled(true);
this.remove(mp);
this.add(msp);
this.setVisible(true);
if(!
msp.islive&
!
mp.hero.islive)
gameovergameover=newgameover("
GameOver!
Threadt=newThread(gameover);
this.add(gameover);
break;
}
classmystartpanelextendsJPanelimplementsRunnable
{
inttime=0;
booleanislive=true;
inti;
publicmystartpanel(inti)
this.i=i;
shuliang.setEnnum(i*3);
publicvoidpaint(Graphicsg)
super.paint(g);
g.fillRect(0,0,390,265);
if(time%2==0)
{
g.setColor(Color.yellow);
Fontmyfont=newFont("
隶书"
Font.BOLD,30);
g.setFont(myfont);
g.drawString("
stage:
"
+i,120,140);
Thread.sleep(1000);
time++;
islive)break;
this.repaint();
classgameoverextendsJPanelimplementsRunnable
Stringname=null;
publicgameover(Stringname)
this.name=name;
g.setColor(Color.black);
g.drawString(name,130,150);
if(time==5)System.exit(0);
classmypanelextendsJPanelimplementsKeyListener,Runnable
Herohero=null;
Vector<
enemytank>
ets=newVector<
();
intensize=shuliang.getEnnum();
Imageimage1=null;
Imageimage2=null;
Imageimage3=null;
bonb>
bonbs=newVector<
publicmypanel()
hero=newHero(200,230);
for(inti=0;
i<
ensize;
i++)
{
intx=(i+1)*50;
if(x>
300)x=x%300;
enemytanket=newenemytank(x,0);
shots=newshot(et.x+10,et.y+30,2);
Threadt2=newThread(s);
t2.start();
et.ss.add(