资源描述:
《坦克大战程序代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、--importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;importjava.util.EventListener;classfextendsJFrame{f(Stringtitle){this.setTitle(title);this.setSize(608,630);this.setLocation(300,100);this.setBackground(Color.BLACK);MyTankmp=newMyTank();this.add(mp);t
2、his.addKeyListener(mp);newThread(mp).start();}publicstaticvoidmain(String[]args){fh=newf("坦克大战(版本1.0)");--.可修编-.--h.setVisible(true);}}//主战坦克classMyTankextendsJPanelimplementsKeyListener,Runnable{intx=280,y=280;//坦克的初始位置intop=1;//坦克的移动方向intcolor=0;inttankspeed=8;
3、//坦克的速度inttankbullet=8;//坦克的子弹速度inttankfbullet=4;//敌军的子弹速度intshengming=100;//生命intfenshu=0;intnandu=5;//设置游戏难度//子弹intdx=295,dy=295;intdx1=295,dy1=-10;intdx2=600,dy2=295;--.可修编-.--intdx3=295,dy3=600;intdx4=-10,dy4=295;//敌军坦克intnum=10;//敌军坦克数量,不能修改int[]xf=newint[nu
4、m];int[]yf=newint[num];int[]opf=newint[num];int[]dxf=newint[num];int[]dyf=newint[num];int[]dxf1=newint[num];int[]dyf1=newint[num];int[]dxf2=newint[num];int[]dyf2=newint[num];int[]dxf3=newint[num];int[]dyf3=newint[num];int[]dxf4=newint[num];int[]dyf4=newint[num];/
5、/构造函数,初始化敌军坦克的位置和状态--.可修编-.--MyTank(){for(inti=0;i6、f4[i]=295;}}//主面版publicvoidpaint(Graphicsg){super.paint(g);this.setBackground(Color.YELLOW);g.setColor(Color.red);--.可修编-.--g.drawString("生命:",10,20);g.fillRect(50,10,shengming*5,10);g.drawRect(50,10,500,10);g.drawString("得分:"+fenshu,10,40);if(op==1){g.setColor(C
7、olor.red);g.fillRect(x,y,40,40);switch(color%6){case0:g.setColor(Color.blue);break;case1:g.setColor(Color.yellow);break;case2:g.setColor(Color.red);break;case3:g.setColor(Color.orange);break;case4:g.setColor(Color.green);break;case5:g.setColor(Color.black);break;
8、}g.fillOval(x-5,y-5,10,10);g.fillOval(x-5,y+5,10,10);g.fillOval(x-5,y+15,10,10);--.可修编-.--g.fillOval(x-5,y+25,10,10);g.fillOval(x-5,y+35,10,10);g.fillOval(x+35