首页 坦克大战附件源码(java)

坦克大战附件源码(java)

举报
开通vip

坦克大战附件源码(java)package T1; import java.util.*; import java.io.*; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.SourceDataLine; ...

坦克大战附件源码(java)
package T1; import java.util.*; import java.io.*; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.SourceDataLine; class Tank { int x=0, y=0; int fangxiang=0; int sudu=5; int color; boolean shengming=true; public int getColor() { return color; } public void setColor(int color) { this.color = color; } public int getSudu() { return sudu; } public void setSudu(int sudu) { this.sudu = sudu; } public int getFangxiang() { return fangxiang; } public void setFangxiang(int fangxiang) { this.fangxiang = fangxiang; } public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY() { return y; } public void setY(int y) { this.y = y; } public Tank(int x,int y) { this.x=x; this.y=y; } } class DiTank extends Tank implements Runnable { int sudu=1; int time=0; int fangxiang; Vector dzd=new Vector(); Vector dtk=new Vector(); public DiTank(int x, int y) { super(x, y); } public void dtkxl(Vector dxl) { this.dtk=dxl; } public boolean huxiangpengzhuang() { boolean b=false; switch(this.fangxiang) { case 0: for(int i=0;i=dt.x && this.x<=dt.x+20 && this.y>=dt.y && this.y<=dt.y+30) { return true; } if(this.x+20>=dt.x && this.x+20<=dt.x+20 && this.y>=dt.y && this.y<=dt.y+30) { return true; } } if(dt.fangxiang==3||dt.fangxiang==1) { if(this.x>=dt.x && this.x<=dt.x+30 && this.y>=dt.y && this.y<=dt.y+20) { return true; } if(this.x+20>=dt.x && this.x+20<=dt.x+30 && this.y>=dt.y && this.y<=dt.y+20) { return true; } } } } break; case 1: for(int i=0;i=dt.x&&this.x<=dt.x+20&&this.y>=dt.y&&this.y<=dt.y+30) { return true; } //下一点 if(this.x>=dt.x&&this.x<=dt.x+20&&this.y+20>=dt.y&&this.y+20<=dt.y+30) { return true; } } if(dt.fangxiang==3||dt.fangxiang==1) { if(this.x>=dt.x&&this.x<=dt.x+30&&this.y>=dt.y&&this.y<=dt.y+20) { return true; } if(this.x>=dt.x&&this.x<=dt.x+30&&this.y+20>=dt.y&&this.y+20<=dt.y+20) { return true; } } } } break; case 2: for(int i=0;i=dt.x&&this.x<=dt.x+20&&this.y+30>=dt.y&&this.y+30<=dt.y+30) { return true; } if(this.x+20>=dt.x&&this.x+20<=dt.x+20&&this.y+30>=dt.y&&this.y+30<=dt.y+30) { return true; } } if(dt.fangxiang==3||dt.fangxiang==1) { if(this.x>=dt.x&&this.x<=dt.x+30&&this.y+30>=dt.y&&this.y+30<=dt.y+20) { return true; } if(this.x+20>=dt.x&&this.x+20<=dt.x+30&&this.y+30>=dt.y&&this.y+30<=dt.y+20) { return true; } } } } break; case 3: for(int i=0;i=dt.x && this.x+30<=dt.x+20 && this.y>=dt.y && this.y<=dt.y+30) { return true; } //下点 if(this.x+30>=dt.x && this.x+30<=dt.x+20 && this.y+20>=dt.y && this.y+20<=dt.y+30) { return true; } } if(dt.fangxiang==3||dt.fangxiang==1) { if(this.x+30>=dt.x && this.x+30<=dt.x+30 && this.y>=dt.y && this.y<=dt.y+20) { return true; } if(this.x+30>=dt.x && this.x+30<=dt.x+30 && this.y+20>=dt.y && this.y+20<=dt.y+20) { return true; } } } } break; } return b; } public void run() { while(true) { switch(this.fangxiang) { case 0: for(int i=0;i<30;i++) { if(y>0 && !huxiangpengzhuang()) {y-=sudu;} try { Thread.sleep(50); } catch (Exception e){} } break; case 1: for(int i=0;i<30;i++) { if(x>0 && !huxiangpengzhuang()) {x-=sudu;} try { Thread.sleep(50); } catch (Exception e){} } break; case 2: for(int i=0;i<30;i++) { if(y<250 && !huxiangpengzhuang()) {y+=sudu;} try { Thread.sleep(50); } catch (Exception e){} } break; case 3: for(int i=0;i<30;i++) { if(x<360 && !huxiangpengzhuang()) {x+=sudu;} try { Thread.sleep(50); } catch (Exception e){} } break; } this.fangxiang=(int)(Math.random()*4); if(this.shengming==false) { break; } this.time++; if(time%2==0) { if(shengming) { if(dzd.size()<5) { Zidan zd=null; switch(fangxiang) { case 0: zd=new Zidan(x+10,y,0); dzd.add(zd); break; case 1: zd=new Zidan(x,y+10,1); dzd.add(zd); break; case 2: zd=new Zidan(x+10,y+30,2); dzd.add(zd); break; case 3: zd=new Zidan(x+30,y+10,3); dzd.add(zd); break; } Thread t5=new Thread(zd); t5.start(); } } } } } } class MyTank extends Tank { Vectoraa=new Vector(); Zidan zd=null; public MyTank(int x,int y) { super(x,y); } public void fszd() { switch(this.fangxiang) { case 0: zd=new Zidan(x+10,y,0); aa.add(zd); break; case 1: zd=new Zidan(x,y+10,1); aa.add(zd); break; case 2: zd=new Zidan(x+10,y+30,2); aa.add(zd); break; case 3: zd=new Zidan(x+30,y+10,3); aa.add(zd); break; } Thread t=new Thread(zd); t.start(); } public void xiangshang() { y-=sudu; } public void xiangzuo() { x-=sudu; } public void xiangxia() { y+=sudu; } public void xiangyou() { x+=sudu; } } class Zidan implements Runnable { int x; int y; int fangxiang; int sudu=5; boolean shengming=true; public Zidan(int x,int y,int fangxiang) { this.x=x; this.y=y; this.fangxiang=fangxiang; } public void run() { while(true) { try { Thread.sleep(50);} catch (Exception e) {} switch(fangxiang) { case 0: y-=sudu; break; case 1: x-=sudu; break; case 2: y+=sudu; break; case 3: x+=sudu; break; } if(x<0||x>400||y<0||y>300) { this.shengming=false; break; } } } } class Baozha { int x,y; int shengcunqi=9; boolean shengming=true; public Baozha(int x,int y) { this.x=x; this.y=y; } public void scqjd() { if(shengcunqi>0) { shengcunqi--; } else { this.shengming=false; } } } class Jilu { private static int dtsl=10; private static int mtsl=2; private static int sdtj=0; private static FileWriter fw=null; private static BufferedWriter bw=null; private static FileReader fr=null; private static BufferedReader br=null; private static Vector dtk=new Vector(); static Vector wzjh=new Vector(); public Vector getDtk() { return dtk; } public void setDtk(Vector dtk) { this.dtk = dtk; } public static Vector dupan() { try { fr=new FileReader("e:/TKDZ/cpjl.txt"); br=new BufferedReader(fr); String s=""; s=br.readLine(); sdtj=Integer.parseInt(s); while((s=br.readLine())!=null) { String[] sz=s.split(" "); Weizhi wz=new Weizhi(Integer.parseInt(sz[0]),Integer.parseInt(sz[1]),Integer.parseInt(sz[2])); wzjh.add(wz); } }catch (Exception e){} finally{ try { br.close(); fr.close(); }catch (Exception e){} } return wzjh; } public static void bcjl() { try { fw=new FileWriter("e:/TKDZ/cpjl.txt"); bw=new BufferedWriter(fw); bw.write(sdtj+"\r\n"); }catch (Exception e){} finally{ try { bw.close(); fw.close(); }catch (Exception e){} } } public void cunpan() { try { fw=new FileWriter("e:/TKDZ/cpjl.txt"); bw=new BufferedWriter(fw); bw.write(sdtj+"\r\n"); for(int i=0;i= 0) aqsj.write(hczj, 0, zjtj ); } } catch (Exception e){} finally { aqsj.drain();//将残留部分处理干净 aqsj.close(); } } }
本文档为【坦克大战附件源码(java)】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_977556
暂无简介~
格式:doc
大小:56KB
软件:Word
页数:0
分类:互联网
上传时间:2019-08-18
浏览量:13