日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java坦克大战代码

發布時間:2023/12/10 java 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java坦克大战代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

上代碼前的圖片:(爆炸效果)



請按這三張圖片的順序插入

上代碼!

MyTankGame8.java

/*** 功能:坦克游戲的7.0 * 1.畫出坦克(√)* 2.我的坦克可以上下左右移動(√)* 3.可以連發子彈(最多5).(√)* 4.當我的坦克擊中敵人的坦克時,敵人就消失(爆炸的效果)(√)* 5.我被擊中后,顯示爆炸效果(√)* 6.防止敵人坦克重疊運動(√)* 6.1.判斷是否碰撞的函數寫到EnemyTank類* 7.可以分關(√)* 7.1.做一個開始的Panel,他是一個空的* 7.2.閃爍效果* 8.可以在玩游戲的時候暫停和繼續(√)* 8.1.暫停的時候,坦克和子彈速度為0,并且坦克方向不變* 9.可以記錄玩家的成績(√)* 9.1.用文件流* 9.2.單寫一個紀錄類,完成玩家記錄* 9.3.先完成保存共擊毀了多少輛敵人的坦克的功能* 9.4.存盤退出游戲,可以記錄當時的敵人的坦克的坐標,并可以修復* 10.java如何操作聲音文件(√)*/ package lesson_49;import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.util.*; import javax.imageio.*; import java.io.*; @SuppressWarnings({"serial","unused"}) public class MyTankGame8 extends JFrame implements ActionListener {MyPanel mp =null;//定義一個開始面板MyStartPanel msp =null;//做出我需要的菜單JMenuBar jmb =null;//開始游戲JMenu jm1 =null;JMenuItem jmi1 =null;//退出系統JMenuItem jmi2 =null;//存盤退出JMenuItem jmi3 =null;public static void main(String[] args) {// TODO 自動生成的方法存根MyTankGame8 mtg =new MyTankGame8();}//構造函數public MyTankGame8(){ //創建菜單及菜單選項jmb =new JMenuBar();jm1 =new JMenu("游戲(G)");jmi1 =new JMenuItem("開始新游戲(N)");jmi2 =new JMenuItem("退出游戲(E)");jmi3 =new JMenuItem("存盤退出游戲(C)");jm1.add(jmi1);jm1.add(jmi2);jm1.add(jmi3);jmb.add(jm1);//設置快捷方式jm1.setMnemonic('G');jmi1.setMnemonic('N');jmi2.setMnemonic('E');jmi3.setMnemonic('C');//對jmi響應jmi1.addActionListener(this);jmi1.setActionCommand("newgame");jmi2.addActionListener(this);jmi2.setActionCommand("exit");jmi3.addActionListener(this);jmi3.setActionCommand("saveExit");msp =new MyStartPanel();this.add(msp);Thread th =new Thread(msp);th.start();this.setJMenuBar(jmb);this.setSize(600,500);this.setVisible(true);this.setTitle("坦克大戰");this.setResizable(false);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e) {//對用戶不同的點擊做出不同的管理if(e.getActionCommand().equals("newgame")){mp =new MyPanel();//jp1 =new JPanel();//刪除老的面板this.remove(msp);this.add(mp);//注冊監聽this.addKeyListener(mp);//啟動mp線程Thread t =new Thread(mp);t.start();this.setVisible(true);}else if(e.getActionCommand().equals("exit")){//用戶點擊了退出系統的菜單//保存擊毀敵人數量Recorder.keepRecording();System.exit(0);}else if(e.getActionCommand().equals("saveExit")){//工作new Recorder().setEts(mp.ets);//保存擊毀敵人的數量和敵人的坐標new Recorder().keepRecAndEnemyTank();//退出System.exit(0);}} }@SuppressWarnings({"serial"}) //就是一個提示的作用 class MyStartPanel extends JPanel implements Runnable {int times =0;public void paint(Graphics g){super.paint(g);g.fillRect(0,0,416,339);if(times%2==0){g.setColor(Color.YELLOW);//開關信息的字體Font myFont =new Font("微軟雅黑",Font.BOLD,30);g.setFont(myFont);//提示信息g.drawString("stage:1",150,150);}}public void run() {while(true){//休眠try {Thread.sleep(500);}catch (InterruptedException e){e.printStackTrace();}times++;this.repaint();}} }//我的面板 @SuppressWarnings({"serial"}) class MyPanel extends JPanel implements KeyListener,Runnable {//定義一個我的坦克Hero hero =null;//定義敵人的坦克組Vector<EnemyTank> ets =new Vector<EnemyTank>();//定義炸彈Vector<Bomb> bombs =new Vector<Bomb>();int enSize=3;//定義三張圖片,三張圖片才能組成一顆炸彈Image image1 =null;Image image2 =null;Image image3 =null;//構造函數public MyPanel(){//恢復記錄Recorder.getRecoring();hero =new Hero(100,100);//初始化敵人的坦克for(int i=0;i<enSize;i++){//創建一輛敵人的坦克對象EnemyTank et =new EnemyTank((i+1)*50,0);et.setColor(0);et.setDirect(2);//將MyPanel的敵人坦克向量交給該敵人坦克et.setEts(ets);//啟動敵人的坦克Thread t =new Thread(et);t.start();//給敵人坦克添加子彈Shot s =new Shot(et.x+10,et.y+30,2);//把子彈給敵人et.ss.add(s);Thread t2 =new Thread(s);t2.start();//加入ets.add(et);}try{image1 =ImageIO.read(new File("bemb_1.gif"));image2 =ImageIO.read(new File("bemb_2.gif"));image3 =ImageIO.read(new File("bemb_3.gif"));}catch(Exception e){e.printStackTrace();}//初始化圖片 // image1 =Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/bemb_1.gif")); // image2 =Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/bemb_2.gif")); // image3 =Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/bemb_3.gif"));}//畫出提示信息public void showInfo(Graphics g){ //畫出提示信息坦克(該坦克不參與戰斗)this.drawTank(80,330,g,0,0);g.setColor(Color.BLACK);g.drawString(Recorder.getEnNum()-3+"",105,350);this.drawTank(150,330,g,0,1);g.setColor(Color.BLACK);g.drawString(Recorder.getMyLife()+"",175,350);//畫出玩家的總成績Font f =new Font("宋體",Font.BOLD,20);g.setFont(f);g.setColor(Color.BLACK);g.drawString("您的總成績",420,30);this.drawTank(420,60,g,0,0);g.setColor(Color.BLACK);g.drawString(Recorder.getAllEnNum()+"",455,80);}//重新paintpublic void paint(Graphics g){super.paint(g);g.setColor(Color.BLACK);g.fillRect(0,0,400,300);//畫出提示信息this.showInfo(g);//畫出自己的坦克if(hero.isLive){this.drawTank(hero.getX(),hero.getY(),g,this.hero.direct,1);}//從ss中取出每顆子彈,并畫出for(int i=0;i<hero.ss.size();i++){Shot myShot =hero.ss.get(i);//畫出子彈,if(myShot!=null&&myShot.isLive==true){g.draw3DRect(myShot.x,myShot.y,1,1,false);}if(myShot.isLive==false){//從ss中刪除掉該子彈hero.ss.remove(myShot);}}//畫出炸彈for(int i=0;i<bombs.size();i++){//System.out.println("bombs.size()="+bombs.size());//取出炸彈Bomb b =bombs.get(i);if(b.life>6){g.drawImage(image1,b.x,b.y,30,30,this);}else if(b.life>3){g.drawImage(image2,b.x,b.y,30,30,this);}else{g.drawImage(image3,b.x,b.y,30,30,this);}//讓b的生命減小b.lifeDown();//如果炸彈生命值為0,就把該炸彈從bombs去掉if(b.life==0){bombs.remove(b);}}//畫出敵人坦克for(int i=0;i<ets.size();i++){EnemyTank et =ets.get(i);if(et.isLive){this.drawTank(et.getX(),et.getY(),g,et.getDirect(),0);//在畫出敵人的子彈for(int j=0;j<et.ss.size();j++){//取出一個子彈Shot enemyTank =et.ss.get(j);if(enemyTank.isLive){g.draw3DRect(enemyTank.x,enemyTank.y,1,1,false);}else{//如果敵人的坦克死亡就從Vector中刪掉et.ss.remove(enemyTank);}}}}}//敵人的子彈是否擊中我public void hieMe(){//取出每一個敵人的坦克for(int i=0;i<ets.size();i++){//取出坦克EnemyTank et =ets.get(i);//取出每一顆子彈for(int j=0;j<et.ss.size();j++){//取出子彈Shot enemyShot =et.ss.get(j);if(hero.isLive){if(this.hitTank(enemyShot,hero)){//Recorder.reduceEnNum();//Recorder.addEnNumRec();}}}}}//判斷我的坦克是否擊中敵人的坦克public void hitEnemyTank(){for(int i=0;i<hero.ss.size();i++){//取出子彈Shot myShot =hero.ss.get(i);//判斷子彈是否有效if(myShot.isLive){//取出每一個子彈,與他判斷for(int j=0;j<ets.size();j++){//取出坦克EnemyTank et =ets.get(j);if(et.isLive){if(this.hitTank(myShot,et)){Recorder.reduceEnNum();Recorder.addEnNumRec();}}}}}}//寫一個函數,專門判斷子彈是否擊中敵人坦克public boolean hitTank(Shot s,Tank et){boolean b2 =false;//判斷該坦克的方向switch(et.direct){//如果敵人的坦克方向是上或下case 0:case 2:if(s.x>et.x&&s.x<et.x+20&&s.y>et.y&&s.y<et.y+30){//擊中//子彈死亡s.isLive=false;//敵人坦克死亡et.isLive=false;b2=true;//創建一顆炸彈,放入VectorBomb b =new Bomb(et.x,et.y);//放入Vectorbombs.add(b);}break;case 1:case 3:if(s.x>et.x&&s.x<et.x+30&&s.y>et.y&&s.y<et.y+20){//擊中//子彈死亡s.isLive=false;//敵人坦克死亡et.isLive=false;b2=true;//創建一顆炸彈,放入VectorBomb b =new Bomb(et.x,et.y);//放入Vectorbombs.add(b);}break;}return b2;}//畫出坦克的函數(擴展)public void drawTank(int x,int y,Graphics g,int direct,int type){//判斷是什么坦克switch(type){case 0:g.setColor(Color.CYAN);break;case 1:g.setColor(Color.YELLOW);break;}//判斷方向switch(direct){//向上case 0://畫出我的坦克(到時在封裝成函數)//1.畫出左邊的矩形g.fill3DRect(x,y,5,30,false);//2.畫出右邊的矩形g.fill3DRect(x+15,y,5,30,false);//3.畫出中間矩形g.fill3DRect(x+5,y+5,10,20,false);//4.畫出圓形g.fillOval(x+5,y+10,10,10);//5.畫出線g.drawLine(x+10,y+15,x+10,y);break;case 1://炮筒向右//畫出上面的矩形g.fill3DRect(x,y,30,5,false);//畫出下面的矩形g.fill3DRect(x,y+15,30,5,false);//畫出中間的矩形g.fill3DRect(x+5,y+5,20,10,false);//畫出圓形g.fillOval(x+10,y+5,10,10);//畫出線g.drawLine(x+15,y+10,x+30,y+10);break;case 2://向下//1.畫出左邊的矩形g.fill3DRect(x,y,5,30,false);//2.畫出右邊的矩形g.fill3DRect(x+15,y,5,30,false);//3.畫出中間矩形g.fill3DRect(x+5,y+5,10,20,false);//4.畫出圓形g.fillOval(x+5,y+10,10,10);//5.畫出線g.drawLine(x+10,y+15,x+10,y+30);break;case 3://向左//1.畫出左邊的矩形g.fill3DRect(x,y,30,5,false);//2.畫出右邊的矩形g.fill3DRect(x,y+15,30,5,false);//3.畫出中間矩形g.fill3DRect(x+5,y+5,20,10,false);//4.畫出圓形g.fillOval(x+10,y+5,10,10);//5.畫出線g.drawLine(x+15,y+10,x,y+10);break;}}//鍵按下 a表示向左,s表示向下,w表示向上,d表示向右public void keyPressed(KeyEvent e) {if(e.getKeyCode()==KeyEvent.VK_W){//設置我的坦克的方向this.hero.setDirect(0);this.hero.moveUp();}else if(e.getKeyCode()==KeyEvent.VK_D){//向右this.hero.setDirect(1);this.hero.moveRight();}else if(e.getKeyCode()==KeyEvent.VK_S){//向下this.hero.setDirect(2);this.hero.moveDown();}else if(e.getKeyCode()==KeyEvent.VK_A){//向左this.hero.setDirect(3);this.hero.moveLeft();}//判斷玩家是否按下j鍵if(e.getKeyCode()==KeyEvent.VK_J){//開火if(this.hero.ss.size()<=4){this.hero.shotEnemy(); }}//必須重繪MyPanelthis.repaint();}public void keyReleased(KeyEvent e) {}public void keyTyped(KeyEvent e) {}public void run(){//每隔一百毫秒刷新一次while(true){try{Thread.sleep(100);}catch(Exception e){e.printStackTrace();}this.hitEnemyTank();//判斷敵人的坦克有沒有擊中我的坦克this.hieMe();//重繪repaint();}} }

Members.java

package lesson_49;import java.util.*; import java.io.*; //紀錄類,同時也可以保存玩家的 class Recorder {//記錄每關有多少個敵人private static int enNum=23;//設置我有多少可用的人private static int myLife=3;//記錄總共消滅了多少輛坦克private static int allEnNum=0;private static FileWriter fw =null;private static BufferedWriter bw =null;private static FileReader fr =null;private static BufferedReader br =null;private Vector<EnemyTank> ets = new Vector<EnemyTank>();//保存擊毀敵人的數量和敵人坦克坐標,方向public void keepRecAndEnemyTank(){try{fw =new FileWriter("d:\\myRecording1.txt");bw =new BufferedWriter(fw);bw.write(allEnNum+"\r\n");//保存當前活的敵人坦克的坐標和方向for(int i=0;i<ets.size();i++){//取出第一個坦克EnemyTank et =ets.get(i);if(et.isLive){//活的就保存String recode =et.x+" "+et.y+" "+et.direct;//寫入bw.write(recode+"\r\n");}}}catch(Exception e){e.printStackTrace();}finally{try{bw.close();fw.close();}catch(Exception e){e.printStackTrace();}}}//從文件中讀取,記錄public static void getRecoring(){try{fr =new FileReader("d:\\myRecording.txt");br =new BufferedReader(fr);String n =br.readLine();allEnNum =Integer.parseInt(n);}catch(Exception e){e.printStackTrace();}finally{try{br.close();fr.close();}catch(Exception e){e.printStackTrace();}}}//把玩家擊毀敵人坦克數量保存到文件中public static void keepRecording() {try{fw =new FileWriter("d:\\myRecording.txt");bw =new BufferedWriter(fw);bw.write(allEnNum+"\r\n");}catch(Exception e){e.printStackTrace();}finally{try{bw.close();fw.close();}catch(Exception e){e.printStackTrace();}}}public static int getAllEnNum() {return allEnNum;}public static void setAllEnNum(int allEnNum) {Recorder.allEnNum = allEnNum;}public static int getEnNum() {return enNum;}public static void setEnNum(int enNum) {Recorder.enNum = enNum;}public static int getMyLife() {return myLife;}public static void setMyLife(int myLife) {Recorder.myLife = myLife;}//減少敵人數量public static void reduceEnNum(){enNum--;}//消滅敵人public static void addEnNumRec(){allEnNum++;}public Vector<EnemyTank> getEts(){return ets;}public void setEts(Vector<EnemyTank> ets1){//this.ets =ets;System.out.println("ok");} }//炸彈類 class Bomb {//定義炸彈的坐標int x,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{this.isLive=false;}} }//子彈類 class Shot implements Runnable {int x;int y;int direct;int speed=1;//是否還活著boolean isLive =true;public Shot(int x,int y,int direct){this.x=x;this.y=y;this.direct=direct;}public void run(){ while(true){try{Thread.sleep(50);}catch(Exception e){e.printStackTrace();}switch(direct){case 0://向上y-=speed;break;case 1://左x+=speed;break;case 2://下y+=speed;break;case 3://右x-=speed;break;}//子彈何時死亡[???思考題???]//判斷該子彈是否碰到邊緣if(x<0||x>400||y<0||y>300){this.isLive=false;break;}}} }//坦克類 class Tank {//表示坦克的橫坐標int x=0;//坦克縱坐標int y=0;//坦克方向//0表示上,1表示右,2表示下,3表示左int direct=0;int color;boolean isLive =true;public int getColor() {return color;}public void setColor(int color) {this.color = color;}//坦克的速度int speed=1;public int getSpeed() {return speed;}public void setSpeed(int speed) {this.speed = speed;}public int getDirect() {return direct;}public void setDirect(int direct) {this.direct = direct;}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 EnemyTank extends Tank implements Runnable {//boolean isLive=true;//定義一個向量,可以訪問到MyPanel上所有敵人的坦克Vector<EnemyTank> ets =new Vector<EnemyTank>(); //定義一個向量,可以存放敵人的子彈Vector<Shot> ss =new Vector<Shot>();//敵人添加子彈,應當在剛剛創建的坦克和敵人的坦克死亡的過后int times =0;public EnemyTank(int x,int y){super(x,y);}//得到MyPanel的敵人坦克向量public void setEts(Vector<EnemyTank> vv){this.ets=vv;//isTouchOtherEnemy();}//判斷是否碰到了別的敵人坦克public boolean isTouchOtherEnemy(){boolean b=false;switch(this.direct){case 0://我的坦克在上//取出所有敵人的坦克for(int i=0;i<ets.size();i++){//取出第一個坦克EnemyTank et =ets.get(i);//如果不是自己if(et!=this){//如果敵人的方向是向下或向上if(et.direct==0||et.direct==2){if(this.x>=et.x&&this.x<=et.x+20&&this.y>=et.y&&this.y<=et.y+30){return true;}if(this.x+20>=et.x&&this.x+20<et.x+20&&this.y>=et.y&&this.y<=et.y+30){return true;}}//向左或向右if(et.direct==3||et.direct==1){if(this.x>=et.x&&this.x<=et.x+30&&this.y>=et.y&&this.y<=et.y+20){return true;}if(this.x+20>=et.x&&this.x+20<et.x+30&&this.y>=et.y&&this.y<=et.y+20){return true;}}}}break;case 1://我的坦克在右//取出所有敵人的坦克for(int i=0;i<ets.size();i++){//取出第一個坦克EnemyTank et =ets.get(i);//如果不是自己if(et!=this){//如果敵人的方向是向下或向上if(et.direct==0||et.direct==2){if(this.x+30>=et.x&&this.x+30<=et.x+20&&this.y>=et.y&&this.y<=et.y+30){return true;}if(this.x+30>=et.x&&this.x+30<=et.x+20&&this.y+20>=et.y&&this.y+20<=et.y+30){return true;}}//向左或向右if(et.direct==3||et.direct==1){if(this.x+30>=et.x&&this.x+30<=et.x+30&&this.y>=et.y&&this.y<=et.y+20){return true;}if(this.x+30>=et.x&&this.x+30<=et.x+30&&this.y+20>=et.y&&this.y+20<=et.y+20){return true;}}}}break;case 2://我的坦克在下//取出所有敵人的坦克for(int i=0;i<ets.size();i++){//取出第一個坦克EnemyTank et =ets.get(i);//如果不是自己if(et!=this){//如果敵人的方向是向下或向上if(et.direct==0||et.direct==2){if(this.x>=et.x&&this.x<=et.x+20&&this.y+30>=et.y&&this.y+30<=et.y+30){return true;}if(this.x+20>=et.x&&this.x+20<=et.x+20&&this.y+30>=et.y&&this.y+30<=et.y+30){return true;}}//向左或向右if(et.direct==3||et.direct==1){if(this.x>=et.x&&this.x<=et.x+30&&this.y+30>=et.y&&this.y+30<=et.y+20){return true;}if(this.x+20>=et.x&&this.x+20<=et.x+30&&this.y+30>=et.y&&this.y+30<=et.y+20){return true;}}}} break;case 3://我的敵人坦克向左 //取出所有敵人的坦克for(int i=0;i<ets.size();i++){//取出第一個坦克EnemyTank et =ets.get(i);//如果不是自己if(et!=this){//如果敵人的方向是向下或向上if(et.direct==0||et.direct==2){if(this.x>=et.x&&this.x<=et.x+20&&this.y>=et.y&&this.y+30<=et.y+30){return true;}if(this.x>=et.x&&this.x<=et.x+20&&this.y+20>=et.y&&this.y+20<=et.y+30){return true;}}//向左或向右if(et.direct==3||et.direct==1){if(this.x>=et.x&&this.x<=et.x+30&&this.y>=et.y&&this.y<=et.y+20){return true;}if(this.x>=et.x&&this.x<=et.x+30&&this.y+20>=et.y&&this.y+20<=et.y+20){return true;}}}}break;}return b;}public void run(){while(true){try{Thread.sleep(50);}catch(Exception e){e.printStackTrace();}switch(this.direct){case 0://說明坦克正在向上for(int i=0;i<30;i++){if(y>0&&!this.isTouchOtherEnemy()){y-=speed;}try{Thread.sleep(50);}catch(Exception e){e.printStackTrace();}}break;case 1://向右for(int i=0;i<30;i++){//保證坦克不出邊界if(x<400&&!this.isTouchOtherEnemy()){x+=speed;}try{Thread.sleep(50);}catch(Exception e){e.printStackTrace();}}break;case 2://向下for(int i=0;i<30;i++){if(y<300&&!this.isTouchOtherEnemy()){y+=speed;}try{Thread.sleep(50);}catch(Exception e){e.printStackTrace();}}break;case 3://向左for(int i=0;i<30;i++){if(x>0&&!this.isTouchOtherEnemy()){x-=speed;}try{Thread.sleep(50);}catch(Exception e){e.printStackTrace();}}break;}this.times++;if(times%2==0){if(isLive){if(ss.size()<5){Shot s =null;switch(direct){case 0:s =new Shot(x+10,y,0);ss.add(s);break;case 1:s =new Shot(x+30,y+10,1);ss.add(s);break;case 2:s =new Shot(x+10,y+30,2);ss.add(s);break;case 3:s =new Shot(x+10,y+10,3);ss.add(s);break;}Thread t =new Thread(s);t.start();}}}//讓坦克隨機長生一個新的方向this.direct=(int)(Math.random()*4);//判斷敵人坦克是否死亡if(this.isLive==false){//讓坦克死亡后,退出線程break;}}} }//定義我的坦克 class Hero extends Tank { //子彈//Shot s=null;Vector<Shot>ss =new Vector<Shot>();Shot s =null;public Hero(int x,int y){super(x,y);}//開火public void shotEnemy(){switch(this.direct){case 0://創建一顆子彈s =new Shot(x+10,y,0);//把子彈加入變量ss.add(s);break;case 1://創建一顆子彈s =new Shot(x+30,y+10,1);ss.add(s);break;case 2://創建一顆子彈s =new Shot(x+10,y+30,2);ss.add(s);break;case 3://創建一顆子彈s =new Shot(x,y+10,3);ss.add(s);break;}//啟動子彈線程Thread t =new Thread(s);t.start();}//坦克向上移動public void moveUp(){y-=speed;}//坦克向右移動public void moveRight(){x+=speed;}//坦克向下移動public void moveDown(){y+=speed;}//坦克向左移動public void moveLeft(){x-=speed;} }

完結

總結

以上是生活随笔為你收集整理的Java坦克大战代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。