Tank版2016Java

  • O5_143133
    了解作者
  • 107KB
    文件大小
  • 7z
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-02 11:26
    上传日期
Tank版2016Java,Tank版2016Java,供参考
Tank2016.7z
  • Tank2016
  • 1.map
    6.3KB
  • bin
  • images
  • missileL.gif
    839B
  • 5.gif
    1.1KB
  • missileR.gif
    839B
  • 2.gif
    936B
  • missileLU.gif
    863B
  • 1.gif
    868B
  • 8.gif
    1.3KB
  • 3.gif
    1KB
  • 6.gif
    1.2KB
  • 0.gif
    824B
  • missileRU.gif
    863B
  • 9.gif
    1.3KB
  • 7.gif
    1.2KB
  • missileRD.gif
    861B
  • MissileD.gif
    855B
  • 4.gif
    1.1KB
  • missileLD.gif
    864B
  • Thumbs.db
    55.5KB
  • 10.gif
    1.2KB
  • missileU.gif
    852B
  • tank
  • GunC.class
    1.1KB
  • GunA.class
    836B
  • RectangleBox.class
    1.5KB
  • Steel.class
    1.3KB
  • GunB.class
    1.7KB
  • Direction.class
    1005B
  • King.class
    2.3KB
  • Explode.class
    1.7KB
  • Gun.class
    666B
  • MapEditor.class
    4.7KB
  • Bullet.class
    3.7KB
  • Stone.class
    1.3KB
  • PlayerTank.class
    4KB
  • Earth.class
    1.3KB
  • MapEditor$1.class
    640B
  • EnemyTank.class
    3.4KB
  • TankClient$1.class
    646B
  • GameMap.class
    4.5KB
  • Tank.class
    3.2KB
  • TankClient$PaintThread.class
    899B
  • TankClient.class
    4.4KB
  • TankClient$KeyMonitor.class
    1.1KB
  • MapEditor$MapKeyMonitor.class
    3.1KB
  • images
  • T2_Bom01.bmp
    7.1KB
  • T2_bao01.bmp
    15.1KB
  • T2_jz001.bmp
    15.1KB
  • T2_zd001.bmp
    1.1KB
  • Tank001.bmp
    51.1KB
  • T2_OVER.BMP
    8.2KB
  • Thumbs.db
    78KB
  • Tank002.BMP
    5.1KB
  • T2_fj01.bmp
    4.1KB
  • background.bmp
    10.1KB
  • src
  • images
  • missileL.gif
    839B
  • 5.gif
    1.1KB
  • missileR.gif
    839B
  • 2.gif
    936B
  • missileLU.gif
    863B
  • 1.gif
    868B
  • 8.gif
    1.3KB
  • 3.gif
    1KB
  • 6.gif
    1.2KB
  • 0.gif
    824B
  • missileRU.gif
    863B
  • 9.gif
    1.3KB
  • 7.gif
    1.2KB
  • missileRD.gif
    861B
  • MissileD.gif
    855B
  • 4.gif
    1.1KB
  • missileLD.gif
    864B
  • Thumbs.db
    55.5KB
  • 10.gif
    1.2KB
  • missileU.gif
    852B
  • tank
  • MapEditor.java
    6.4KB
  • GunA.java
    393B
  • GunC.java
    905B
  • Stone.java
    761B
  • Bullet.java
    3KB
  • TankClient.java
    5.1KB
  • GameMap.java
    3.3KB
  • GunB.java
    1.1KB
  • Explode.java
    1.6KB
  • Direction.java
    59B
  • King.java
    1.5KB
  • Gun.java
    459B
  • Earth.java
    873B
  • EnemyTank.java
    2.8KB
  • Tank.java
    1.8KB
  • PlayerTank.java
    3.7KB
  • RectangleBox.java
    1.3KB
  • Steel.java
    765B
内容介绍
package tank; import java.awt.Color; import java.awt.Graphics; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; public class MapEditor extends JFrame { private static final long serialVersionUID = 1L; private static int x = 0; private static int y = 0; private static int GAME_LEVEL = 1; private static boolean VK_1_PRESSED = false; private static boolean VK_2_PRESSED = false; private static boolean VK_3_PRESSED = false; private static boolean VK_DELETE_PRESSED = false; private static final King king = new King(); private MapEditor(){ super.setBounds(0, 0, TankClient.WINDOW_WIDTH, TankClient.WINDOW_HEIGHT); super.setResizable(false); super.setUndecorated(true); super.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { System.exit(0); } }); super.addKeyListener(new MapKeyMonitor()); GameMap.loadMapCache(GAME_LEVEL); setVisible(true); } public static void main(String[] args) { MapEditor editor = new MapEditor(); GameMap.drawMap(editor.getFrameGriphics()); king.draw(editor.getFrameGriphics()); } private class MapKeyMonitor extends KeyAdapter { public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); switch(key) { case KeyEvent.VK_1 : VK_1_PRESSED = true; Earth earth = new Earth(x, y, GameMap.wallWidth, GameMap.wallWidth); earth.draw(getFrameGriphics()); drawFocusRec(x, y); GameMap.put(generateMapKey(x, y), earth); break; case KeyEvent.VK_2 : VK_2_PRESSED = true; Stone stone = new Stone(x, y, GameMap.wallWidth, GameMap.wallWidth); stone.draw(getFrameGriphics()); drawFocusRec(x, y); GameMap.put(generateMapKey(x, y), stone); break; case KeyEvent.VK_3 : VK_3_PRESSED = true; Steel steel = new Steel(x, y, GameMap.wallWidth, GameMap.wallWidth); steel.draw(getFrameGriphics()); drawFocusRec(x, y); GameMap.put(generateMapKey(x, y), steel); break; case KeyEvent.VK_DELETE : VK_DELETE_PRESSED = true; GameMap.remove(generateMapKey(x, y)); drawBlankRec(x, y); drawFocusRec(x, y); break; case KeyEvent.VK_UP : paint(x, y); if((y - GameMap.wallWidth) < 0) { y = 0; } else { y -= GameMap.wallWidth; } drawFocusRec(x, y); break; case KeyEvent.VK_DOWN : paint(x, y); if((y + GameMap.wallWidth + GameMap.wallWidth) > TankClient.WINDOW_HEIGHT) { y = TankClient.WINDOW_HEIGHT - GameMap.wallWidth; } else { y += GameMap.wallWidth; } drawFocusRec(x, y); break; case KeyEvent.VK_LEFT : paint(x, y); if((x - GameMap.wallWidth) < 0) { x = 0; } else { x -= GameMap.wallWidth; } drawFocusRec(x, y); break; case KeyEvent.VK_RIGHT : paint(x, y); if((x + GameMap.wallWidth + GameMap.wallWidth) > TankClient.WINDOW_WIDTH) { x = TankClient.WINDOW_WIDTH - GameMap.wallWidth; } else { x += GameMap.wallWidth; } drawFocusRec(x, y); break; case KeyEvent.VK_PAGE_UP : if(GAME_LEVEL > 1) { --GAME_LEVEL; GameMap.loadMapCache(GAME_LEVEL); clearScreen(); GameMap.drawMap(getFrameGriphics()); king.draw(getFrameGriphics()); } break; case KeyEvent.VK_PAGE_DOWN : if(GAME_LEVEL < 10) { ++GAME_LEVEL; GameMap.loadMapCache(GAME_LEVEL); clearScreen(); GameMap.drawMap(getFrameGriphics()); king.draw(getFrameGriphics()); } break; case KeyEvent.VK_F1 : GameMap.saveMap(); break; case KeyEvent.VK_F2 : GameMap.drawMap(getGraphics()); break; case KeyEvent.VK_ESCAPE : System.exit(0); break; } } @Override public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); switch(key) { case KeyEvent.VK_1 : VK_1_PRESSED = false; break; case KeyEvent.VK_2 : VK_2_PRESSED = false; break; case KeyEvent.VK_3 : VK_3_PRESSED = false; break; case KeyEvent.VK_DELETE : VK_DELETE_PRESSED = false; break; } } } private void paint(int x, int y) { if(VK_1_PRESSED || VK_2_PRESSED || VK_3_PRESSED || VK_DELETE_PRESSED) { if(VK_1_PRESSED) { Earth earth = new Earth(x, y, GameMap.wallWidth, GameMap.wallWidth); earth.draw(getFrameGriphics()); GameMap.put(generateMapKey(x, y), earth); } else if(VK_2_PRESSED) { Stone stone = new Stone(x, y, GameMap.wallWidth, GameMap.wallWidth); stone.draw(getFrameGriphics()); GameMap.put(generateMapKey(x, y), stone); } else if(VK_3_PRESSED) { Steel steel = new Steel(x, y, GameMap.wallWidth, GameMap.wallWidth); steel.draw(getFrameGriphics()); GameMap.put(generateMapKey(x, y), steel); } else if(VK_DELETE_PRESSED) { GameMap.remove(generateMapKey(x, y)); drawBlankRec(x, y); } } else { if(GameMap.get(generateMapKey(x, y)) != null) { GameMap.get(generateMapKey(x, y)).draw(getGraphics()); } else { drawBlankRec(x, y); } } } private Graphics getFrameGriphics() { return super.getGraphics(); } private void drawBlankRec(int x, int y) { Graphics frameGraph = getFrameGriphics(); Color c = frameGraph.getColor(); frameGraph.setColor(Color.WHITE); frameGraph.fillRect(x, y, GameMap.wallWidth, GameMap.wallWidth); frameGraph.setColor(c); } private void drawFocusRec(int x, int y) { Graphics frameGraph = getFrameGriphics(); Color c = frameGraph.getColor(); frameGraph.setColor(Color.BLUE); frameGraph.drawRect(x, y, GameMap.wallWidth - 1, GameMap.wallWidth - 1); frameGraph.setColor(c); } private void clearScreen() { Graphics frameGraph = getFrameGriphics(); Color c = frameGraph.getColor(); frameGraph.setColor(Color.WHITE); frameGraph.fillRect(0, 0, TankClient.WINDOW_WIDTH, TankClient.WINDOW_HEIGHT); frameGraph.setColor(c); } public static String generateMapKey(int x, int y) { return x + "_" + y; } }
评论
    相关推荐
    • Java
      Java
    • java
      Java
    • Java
      Java
    • Java
      Java项目
    • Java
      Java 对于Java练习
    • java
      Java 此回购包括我学习Java的旅程。
    • java
      Java Java基础
    • Java
      Java
    • Java
      Java 我创建的Java项目
    • Java
      Java 2021/02/19 .java Main.java 学生.java Bmi.java 。班级 Bmi类 主类 MyBmi.class 学生班 学生样本类 2021/02/20 .java DeleteFile.java WriteFile.java MyDataPrint.java 。班级 DeleteFile.class ...