javaSwing坦克大战游戏

在游戏开发领域,坦克大战是一款经典的游戏,其简单而又耐玩的玩法吸引了无数玩家。而今,在Java编程技术的支持下,我们可以用Java Swing技术轻松实现这款经典游戏。本文将介绍如何使用Java Swing技术编写坦克大战游戏,并简要介绍其实现过程和关键代码。

一、游戏简介

坦克大战是一款双人对战的游戏,玩家控制着一辆坦克在游戏地图中移动、射击,目标是摧毁对方坦克。游戏地图通常由障碍物组成,增加了游戏的难度和挑战性。通过不断躲避敌方的攻击、寻找机会进行反击,玩家可以获胜。

二、技术选型

在这个项目中,我们选择使用Java Swing技术来实现游戏的界面和交互逻辑。Java Swing是Java语言的一个GUI库,提供了丰富的组件和功能,非常适合用于开发图形化应用程序。

实现过程

  1. 游戏界面设计
    首先,我们需要设计游戏的界面。通过Java Swing提供的组件,我们可以轻松地创建游戏地图、坦克、子弹等元素,并实现它们的显示和交互。

  2. 游戏逻辑实现
    游戏逻辑是游戏开发的核心部分。在坦克大战中,我们需要实现坦克的移动、射击、碰撞检测等功能。通过Java Swing提供的事件监听器和定时器,我们可以实现这些功能,并确保游戏的流畅性和可玩性。

  3. 用户交互实现
    最后,我们需要实现用户交互功能,包括键盘控制坦克的移动和射击、显示游戏信息等。Java Swing提供了丰富的事件处理机制,我们可以利用这些机制来实现用户交互功能,并提升游戏的体验。

三、关键代码

BeginFrame.java

package hjzgg.main;import hjzgg.layer.TheLayer;
import hjzgg.map.TankMap;
import hjzgg.set.MySet;
import hjzgg.size.TheSize;
import hjzgg.tank.MyTank;
import hjzgg.tank.ShellThread;
import hjzgg.tank.EnemyTankThread;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneLayout;class MapDialog extends JDialog{public static int chooseMap = -1;public MapDialog(Dialog owner, String title, boolean modal){super(owner, title, modal);int len = TankMap.tankmap.length;setSize(500, 500);setResizable(false);JPanel mapPane = new JPanel();mapPane.setLayout(new BoxLayout(mapPane, BoxLayout.Y_AXIS));JScrollPane scrollpane = new JScrollPane(mapPane);add(scrollpane);for(int i=1; i<=len; ++i){JPanel p = new JPanel();ShapePane tankmap = new ShapePane("tankmap/map" + i + ".jpg", 350, 350);tankmap.setPreferredSize(new Dimension(350, 350));JButton btnChoose = new JButton("地图"+i);final int choose = i-1;btnChoose.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent arg0) {chooseMap = choose;MapDialog.this.dispose();}});p.add(tankmap);p.add(btnChoose);mapPane.add(p);}setVisible(true);}
}class BeginPanel extends JPanel{private String img_path = null;private int width, height;private boolean isBorder = false;public BeginPanel(String path, int w, int h){this.img_path = path;this.width = w;this.height = h;}protected void paintComponent(Graphics g) {super.paintComponent(g);	if(img_path==null) return;g.drawImage(new ImageIcon(img_path).getImage(), 0, 0, width, height, this);}@Overrideprotected void paintBorder(Graphics g) {if(isBorder){float lineWidth = 5.0f;((Graphics2D)g).setStroke(new BasicStroke(lineWidth));((Graphics2D)g).setColor(Color.RED);((Graphics2D)g).drawRect(0, 0, 100, 50);}}public void setIsBorder(boolean f){this.isBorder = f;}public void setImgPath(String path){this.img_path = path;}
}public class BeginFrame extends Frame{private int index = 0;private BeginPanel pic1 = new BeginPanel("tank_battle.png", 800, 200);private BeginPanel[] tank = new BeginPanel[2];private BeginPanel begin = new BeginPanel("begin.png", 100, 50);private BeginPanel continuing = new BeginPanel("continue.png", 100, 50);private JPanel pmenu1 = new JPanel();private JPanel pmenu2 = new JPanel();private JLabel l1 = new JLabel("");private JLabel l2 = new JLabel("");private JLabel l3 = new JLabel("");private JLabel l4 = new JLabel("");private JLabel l5 = new JLabel("");private void changTank(int i){tank[i].setImgPath("tank/mytank_right.gif");tank[i].updateUI();tank[i^1].setImgPath(null);tank[i^1].updateUI();}private void borderPaint(BeginPanel x, boolean f){x.setIsBorder(f);x.updateUI();}class BorderChange implements Runnable{private BeginPanel tmp = null;private int index = 0;public BorderChange(BeginPanel x, int index){tmp = x;this.index = index;}public void run() {try {borderPaint(tmp, true);Thread.sleep(300);borderPaint(tmp, false);Thread.sleep(300);borderPaint(tmp, true);} catch (InterruptedException e) {e.printStackTrace();}if(index == 0){//选择地图MapDialog md = new MapDialog(null, "请选择地图!", true);TankFrame tf = new TankFrame(TankMap.tankmap[MapDialog.chooseMap]);ShellThread st = new ShellThread();new Thread(st).start();//炮弹线程MySet.getInstance().setSt(st);EnemyTankThread ett = new EnemyTankThread(tf);new Thread(ett).start();//坦克出现 线程MySet.getInstance().setEtt(ett);JLayeredPane jlp = tf.getJlp();MyTank mt = new MyTank("mytank", "tank/mytank_up.gif", 0, tf);MySet.getInstance().getTankSet().add(mt);mt.setBounds(280, 630, TheSize.tank_width, TheSize.tank_height);jlp.add(mt);jlp.setLayer(mt, TheLayer.tank);tf.setVisible(true);mt.requestFocus();//在窗口显示之后将焦点移到MyTank上,否则不能监听键盘消息} else {SelfConfigFrame scf = new SelfConfigFrame();scf.setResizable(false);scf.setVisible(true);}BeginFrame.this.dispose();}}public BeginFrame(){addWindowListener(new WindowAdapter() {@Overridepublic void windowClosing(WindowEvent arg0) {System.exit(0);}});addKeyListener(new KeyAdapter() {@Overridepublic void keyPressed(KeyEvent arg0) {switch(arg0.getKeyCode()){case KeyEvent.VK_UP:index = (index+1)%2;changTank(index);break;case KeyEvent.VK_DOWN:index = (index-1 + 2)%2;changTank(index);break;case KeyEvent.VK_ENTER:if(index==0){borderPaint(continuing, false);new Thread(new BorderChange(begin, index)).start();}else{borderPaint(begin, false);new Thread(new BorderChange(continuing, index)).start();}break;default:break;}}});tank[0] = new BeginPanel("tank/mytank_right.gif", 50, 50);tank[1] = new BeginPanel(null, 50, 50);setBackground(Color.BLACK);setSize(800,600);setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));pic1.setBackground(Color.BLACK);pic1.setPreferredSize(new Dimension(800, 200));add(pic1);pmenu1.setPreferredSize(new Dimension(800, 50));tank[0].setBackground(Color.BLACK);tank[0].setPreferredSize(new Dimension(100, 50));begin.setBackground(Color.BLACK);begin.setPreferredSize(new Dimension(100, 50));pmenu1.setBackground(Color.BLACK);pmenu1.add(tank[0]);pmenu1.add(begin);add(pmenu1);pmenu2.setBackground(Color.BLACK);pmenu2.setPreferredSize(new Dimension(800, 50));tank[1].setBackground(Color.BLACK);tank[1].setPreferredSize(new Dimension(100, 50));continuing.setBackground(Color.BLACK);continuing.setPreferredSize(new Dimension(100, 50));pmenu2.add(tank[1]);pmenu2.add(continuing);add(pmenu2);l1.setFont(new Font("华文彩云", Font.BOLD, 25));l1.setForeground(Color.RED);JPanel px = new JPanel();px.setBackground(Color.BLACK);px.add(l1);add(px);l2.setFont(new Font("黑体", Font.BOLD, 15));px = new JPanel();px.setBackground(Color.BLACK);px.add(l2);add(px);l3.setFont(new Font("黑体", Font.BOLD, 15));px = new JPanel();px.setBackground(Color.BLACK);px.add(l3);add(px);l4.setFont(new Font("宋体", Font.ITALIC, 15));l4.setForeground(Color.green);px = new JPanel();px.setBackground(Color.BLACK);px.add(l4);add(px);l5.setFont(new Font("黑体", Font.ITALIC, 15));l5.setForeground(Color.green);px = new JPanel();px.setBackground(Color.BLACK);px.add(l5);add(px);}public static void main(String[] args){BeginFrame bf = new BeginFrame();bf.setVisible(true);}
}

SelfConfigFrame.java

package hjzgg.main;import hjzgg.id.IDblock;
import hjzgg.layer.TheLayer;
import hjzgg.set.MySet;
import hjzgg.size.TheSize;
import hjzgg.tank.EnemyTankThread;
import hjzgg.tank.MyTank;
import hjzgg.tank.ShellThread;import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener;
import java.util.Arrays;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;class MyLayeredPane extends JLayeredPane{private SelfConfigFrame scf = null;public MyLayeredPane(SelfConfigFrame f){this.scf = f;addMouseListener(new MouseAdapter() {@Overridepublic void mouseExited(MouseEvent e) {scf.getSp().setVisible(false);}});}
}class BlockPanel extends JPanel{private String img_path = null;private int height=0, width=0;private SelfConfigFrame scf = null;private void fillShape(MouseEvent e){int x = e.getX();int y = e.getY();Point ptf = SwingUtilities.convertPoint(BlockPanel.this, new Point(x, y), getParent());//块索引int j = ptf.x / TheSize.block_height;int i = ptf.y / TheSize.block_width;ShapePane sp = scf.getSp();MyLayeredPane parent = scf.getMyLayeredPane();String path = null;if(scf.getSta()[i][j] != IDblock.home && scf.getSta()[i][j] != IDblock.tank_appear && SelfConfigFrame.choose != -1){switch(SelfConfigFrame.choose){case IDblock.grass:path = "草地.png";break;case IDblock.steel_wall:path = "钢墙.jpg";break;case IDblock.wall:path = "砖墙.jpg";break;case IDblock.water:path = "水.jpg";break;case IDblock.not:path = null;break;default:}scf.getSta()[i][j] = SelfConfigFrame.choose;//当前 块 填充的类型scf.getBlock()[i][j].setImgPath(path);scf.getBlock()[i][j].update(scf.getBlock()[i][j].getGraphics());sp.setBounds(ptf.x+5, ptf.y+5, TheSize.shapepane_width, TheSize.shapepane_height);}}public BlockPanel(SelfConfigFrame f, String path, int w, int h){this.img_path = path;height = h;width = w;scf = f;addMouseMotionListener(new MouseMotionListener() {@Overridepublic void mouseMoved(MouseEvent e) {int x = e.getX();int y = e.getY();Point ptf = SwingUtilities.convertPoint(BlockPanel.this, new Point(x, y), getParent());ShapePane sp = scf.getSp();MyLayeredPane parent = scf.getMyLayeredPane();String path = null;if(SelfConfigFrame.choose != -1){if(!sp.isVisible()){switch(SelfConfigFrame.choose){case IDblock.grass:path = "草地.png";break;case IDblock.steel_wall:path = "钢墙.jpg";break;case IDblock.wall:path = "砖墙.jpg";break;case IDblock.water:path = "水.jpg";break;case IDblock.not:path = null;break;default:}sp.setVisible(true);sp.setImgPath(path);}sp.setBounds(ptf.x+5, ptf.y+5, TheSize.shapepane_width, TheSize.shapepane_height);parent.updateUI();}}@Overridepublic void mouseDragged(MouseEvent e) {fillShape(e);}});addMouseListener(new MouseAdapter() {@Overridepublic void mouseClicked(MouseEvent e) {fillShape(e);}});}protected void paintComponent(Graphics g) {super.paintComponent(g);	if(img_path==null) return;g.drawImage(new ImageIcon(img_path).getImage(), 0, 0, width, height, this);}@Overrideprotected void paintBorder(Graphics g) {float lineWidth = 2.0f;((Graphics2D)g).setStroke(new BasicStroke(lineWidth));((Graphics2D)g).setColor(Color.GREEN);((Graphics2D)g).drawRect(0, 0, width, height);}public void setImgPath(String path){this.img_path = path;}
}class ShapeButton extends JButton{private String img_path = null;public ShapeButton(String path){this.img_path = path;addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {SelfConfigFrame.choose = Integer.parseInt(e.getActionCommand());}});}protected void paintComponent(Graphics g) {super.paintComponent(g);	if(img_path==null) return;g.drawImage(new ImageIcon(img_path).getImage(), 0, 0, TheSize.shapebtn_width, TheSize.shapebtn_height, this);}}public class SelfConfigFrame extends JFrame{public static int choose = -1;private ShapePane sp = new ShapePane(null, TheSize.shapepane_width, TheSize.shapepane_height);private MyLayeredPane p = null;private JPanel pl = null;private JPanel pr = null;private JPanel pu = null;private JButton beginGame = new JButton("开始游戏");private JButton reset = new JButton("重置自定义");public ShapePane getSp() {return sp;}public MyLayeredPane getMyLayeredPane() {return p;}public  int[][] getSta() {return sta;}private JPanel pd = null;private JPanel home = null;public  int[][] sta = new int[20][28];private BlockPanel[][] block = new BlockPanel[20][28];public BlockPanel[][] getBlock() {return block;}public void staInit(){//家所在的位置不能填充sta[17][12]=sta[17][13]=sta[17][14]=sta[17][15]=sta[18][12]=sta[18][13]=sta[18][14]=sta[18][15]=sta[19][12]=sta[19][13]=sta[19][14]=sta[19][15]=IDblock.home;//坦克出现的位置不能填充sta[0][0]=sta[0][1]=sta[1][1]=sta[1][0]=IDblock.tank_appear;sta[0][26]=sta[0][27]=sta[1][27]=sta[1][26]=IDblock.tank_appear;sta[18][9]=sta[19][9]=sta[19][8]=sta[18][8]=IDblock.tank_appear;}public void init(){for(int i=0; i<block.length; ++i)for(int j=0; j<block[i].length; ++j){block[i][j] = new BlockPanel(this, null, TheSize.block_width, TheSize.block_height);block[i][j].setBounds(j*TheSize.block_width, i*TheSize.block_height, TheSize.block_width, TheSize.block_height);block[i][j].setBackground(Color.BLACK);p.add(block[i][j]);p.setLayer(block[i][j], 1);}//图片随鼠标移动sp.setVisible(false);sp.setBounds(0, 0, TheSize.shapepane_width, TheSize.shapepane_height);p.add(sp);p.setLayer(sp, 3);//home图片home = new BlockPanel(this, "家.jpg", TheSize.block_width*4, TheSize.block_height*3);home.setBounds(12*TheSize.block_width, 17*TheSize.block_height, TheSize.block_width*4, TheSize.block_height*3);p.add(home);p.setLayer(home, 2);staInit();}public SelfConfigFrame(){p = new MyLayeredPane(this);pl = new JPanel();pr = new JPanel();pu = new JPanel();pd = new JPanel();setSize(1127, 800);p.setOpaque(true);p.setBackground(Color.BLACK);pl.setPreferredSize(new Dimension(0, 0));pr.setPreferredSize(new Dimension(130, 0));pu.setPreferredSize(new Dimension(0, 20));pd.setPreferredSize(new Dimension(0, 30));p.setPreferredSize(new Dimension(990, 700));p.setLayout(null);//添加障碍物图片JPanel title = new JPanel();title.setPreferredSize(new Dimension(100,50));title.add(new JLabel("自定义障碍物:"));pr.add(title);ShapeButton btn = new ShapeButton("草地.png");btn.setPreferredSize(new Dimension(TheSize.shapebtn_width, TheSize.shapebtn_height));btn.setActionCommand("2");pr.add(btn);pr.add(new JLabel("草地"));btn = new ShapeButton("钢墙.jpg");btn.setPreferredSize(new Dimension(TheSize.shapebtn_width, TheSize.shapebtn_height));btn.setActionCommand("3");pr.add(btn);pr.add(new JLabel("钢墙"));btn = new ShapeButton("水.jpg");btn.setPreferredSize(new Dimension(TheSize.shapebtn_width, TheSize.shapebtn_height));btn.setActionCommand("5");pr.add(btn);pr.add(new JLabel("    水"));btn = new ShapeButton("砖墙.jpg");btn.setPreferredSize(new Dimension(TheSize.shapebtn_width, TheSize.shapebtn_height));btn.setActionCommand("4");pr.add(btn);pr.add(new JLabel("   砖墙     "));btn = new ShapeButton(null);btn.setBackground(Color.BLACK);btn.setText("擦      除");btn.setPreferredSize(new Dimension(TheSize.shapebtn_width, TheSize.shapebtn_height/2));btn.setActionCommand("0");pr.add(btn);beginGame.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent arg0) {TankFrame tf = new TankFrame(sta);//将创建的地图传递到游戏中去ShellThread st = new ShellThread();new Thread(st).start();//炮弹线程MySet.getInstance().setSt(st);EnemyTankThread ett = new EnemyTankThread(tf);new Thread(ett).start();//坦克出现 线程MySet.getInstance().setEtt(ett);JLayeredPane jlp = tf.getJlp();MyTank mt = new MyTank("mytank", "tank/mytank_up.gif", 0, tf);MySet.getInstance().getTankSet().add(mt);mt.setBounds(280, 630, TheSize.tank_width, TheSize.tank_height);jlp.add(mt);jlp.setLayer(mt, TheLayer.tank);tf.setVisible(true);mt.requestFocus();//在窗口显示之后将焦点移到MyTank上,否则不能监听键盘消息SelfConfigFrame.this.dispose();}});reset.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent arg0) {for(int i=0; i<sta.length; ++i) Arrays.fill(sta[i], 0);staInit();for(int i=0; i<block.length; ++i)for(int j=0; j<block[i].length; ++j){block[i][j].setImgPath(null);block[i][j].updateUI();}}});pr.add(beginGame);pr.add(reset);setLayout(new BorderLayout());add(pl, BorderLayout.WEST);add(pr, BorderLayout.EAST);add(pd, BorderLayout.SOUTH);add(pu, BorderLayout.NORTH);add(p, BorderLayout.CENTER);init();}//	public static void main(String[] args){
//		SelfConfigFrame scf = new SelfConfigFrame();
//		scf.setResizable(false);
//		scf.setVisible(true);
//	}
}

ShapePane.java

package hjzgg.main;import java.awt.Color;
import java.awt.Graphics;import javax.swing.ImageIcon;
import javax.swing.JPanel;public class ShapePane extends JPanel implements Comparable{private String img_path = null;private int w, h, id=-1;public ShapePane(String path, int w, int h){this.img_path = path;this.w = w;this.h = h;}protected void paintComponent(Graphics g) {super.paintComponent(g);if(img_path != null)g.drawImage(new ImageIcon(img_path).getImage(), 0, 0, w, h, this);else{g.setColor(Color.BLACK);g.fillRect(0, 0, w, h);}}public void setImgPath(String path){this.img_path = path;}@Overridepublic int compareTo(Object o) {return o.hashCode() - this.hashCode();}public int getId() {return id;}public void setId(int id) {this.id = id;}
}

TankFrame.java

package hjzgg.main;import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;import hjzgg.id.IDblock;
import hjzgg.layer.TheLayer;
import hjzgg.set.MySet;
import hjzgg.size.TheSize;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;public class TankFrame extends JFrame{public static int ID = 0;public  int[][] sta = null;//地图状态标记public int[][] getSta() {return sta;}public void setSta(int[][] sta) {this.sta = sta;}private JLayeredPane jlp = null;private ShapePane pl = null;private JPanel pr = null;private JPanel pu = null;private JPanel pd = null;public JLayeredPane getJlp(){return jlp;}public JPanel getPr(){return pr;}public void initMap(JLayeredPane xjlp){//home图片ShapePane home = new ShapePane("家.jpg", TheSize.block_width*4, TheSize.block_height*3);home.setBounds(12*TheSize.block_width, 17*TheSize.block_height, TheSize.home_width, TheSize.home_height);home.setId(IDblock.home);xjlp.add(home, TheLayer.wall, -1);MySet.getInstance().getOtherSet().add(home);if(sta != null){for(int i=0; i<sta.length; ++i){//System.out.print("{");//打印生成的地图for(int j=0; j<sta[i].length; ++j){ShapePane sp = null;int layer = -1;
//					System.out.print(sta[i][j]);
//					if(j==sta[i].length-1) System.out.print("}");
//					System.out.print(",");switch(sta[i][j]){case IDblock.grass:sp = new ShapePane("草地.png", TheSize.block_width, TheSize.block_height);sp.setOpaque(false);sp.setId(IDblock.grass);layer = TheLayer.grass;break;case IDblock.steel_wall:sp = new ShapePane("钢墙.jpg", TheSize.block_width, TheSize.block_height);sp.setId(IDblock.steel_wall);layer = TheLayer.wall;break;case IDblock.wall:sp = new ShapePane("砖墙.jpg", TheSize.block_width, TheSize.block_height);sp.setId(IDblock.wall);layer = TheLayer.wall;break;case IDblock.water:sp = new ShapePane("水.jpg", TheSize.block_width, TheSize.block_height);sp.setId(IDblock.water);layer = TheLayer.water;break;default:}if(sp != null){MySet.getInstance().getOtherSet().add(sp);sp.setBounds(j*TheSize.block_width, i*TheSize.block_height, TheSize.block_width, TheSize.block_height);;xjlp.add(sp, layer, -1);}}//System.out.println();}}}public TankFrame(int[][] sta){super("HJZGG-TankBattle");this.sta = sta;jlp = new JLayeredPane();pl = new ShapePane("左标题.png", 100, 700);pr = new JPanel();pu = new JPanel();pd = new JPanel();pu.add(new JLabel("坦克大战-------hjzg"));JLabel tankCnt = new JLabel("击杀坦克数量:");pr.add(tankCnt);setSize(1217, 800);jlp.setOpaque(true);jlp.setBackground(Color.BLACK);initMap(jlp);pl.setPreferredSize(new Dimension(100, 0));pr.setPreferredSize(new Dimension(120, 0));pu.setPreferredSize(new Dimension(0, 20));pd.setPreferredSize(new Dimension(0, 20));jlp.setPreferredSize(new Dimension(980, 700));jlp.setLayout(null);setLayout(new BorderLayout());add(pl, BorderLayout.WEST);add(pr, BorderLayout.EAST);add(pd, BorderLayout.SOUTH);add(pu, BorderLayout.NORTH);add(jlp, BorderLayout.CENTER);addWindowListener(new WindowAdapter() {@Overridepublic void windowClosing(WindowEvent arg0) {System.exit(0);// 终止当前正在运行的 Java 虚拟机。}});}}

Rect.java

package hjzgg.Rect;public class Rect {public int x1,x2, y1,y2;public Rect(int x1, int y1, int x2, int y2){this.x1 = x1;this.x2 = x2;this.y1 = y1;this.y2 = y2;}public static boolean isCorss(Rect r1, Rect r2){int cx1 = Math.max(r1.x1, r2.x1);int cy1 = Math.max(r1.y1, r2.y1);int cx2 = Math.min(r1.x2, r2.x2);int cy2 = Math.min(r1.y2, r2.y2);if(cx1 > cx2) return false;if(cy1 > cy2) return false;if( (cx2-cx1)*(cy2-cy1) == 0) return false;return true;}
}

四、游戏截图

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

五、联系与交流

q:969060742 完整代码

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/774597.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Java程序设计】【C00352】基于Springboot的疫情隔壁酒店管理系统(有论文)

基于Springboot的疫情隔壁酒店管理系统&#xff08;有论文&#xff09; 项目简介项目获取开发环境项目技术运行截图 项目简介 项目获取 &#x1f345;文末点击卡片获取源码&#x1f345; 开发环境 运行环境&#xff1a;推荐jdk1.8&#xff1b; 开发工具&#xff1a;eclipse以…

VS code中安装了git插件,报错无法使用怎么办?

你好&#xff0c;我是云桃桃。 一个希望帮助更多朋友快速入门 WEB 前端程序媛。 1枚程序媛&#xff0c;2年时间从1800到月入过万&#xff0c;工作5年买房。 分享成长心得❤️&#xff0c;和你一起慢慢变富。 后台回复“前端工具”可获取开发工具&#xff0c;持续更新中 后台…

如何在Linux Ubuntu系统安装Nginx服务并实现无公网IP远程连接

文章目录 1. 安装Docker2. 使用Docker拉取Nginx镜像3. 创建并启动Nginx容器4. 本地连接测试5. 公网远程访问本地Nginx5.1 内网穿透工具安装5.2 创建远程连接公网地址5.3 使用固定公网地址远程访问 在开发人员的工作中&#xff0c;公网远程访问内网是其必备的技术需求之一。对于…

【Java程序设计】【C00387】基于(JavaWeb)Springboot的校园食堂订餐系统(有论文)

基于&#xff08;JavaWeb&#xff09;Springboot的校园食堂订餐系统&#xff08;有论文&#xff09; 项目简介项目获取开发环境项目技术运行截图 博主介绍&#xff1a;java高级开发&#xff0c;从事互联网行业六年&#xff0c;已经做了六年的毕业设计程序开发&#xff0c;开发过…

【LeetCode: 2580. 统计将重叠区间合并成组的方案数 + 合并区间】

&#x1f680; 算法题 &#x1f680; &#x1f332; 算法刷题专栏 | 面试必备算法 | 面试高频算法 &#x1f340; &#x1f332; 越难的东西,越要努力坚持&#xff0c;因为它具有很高的价值&#xff0c;算法就是这样✨ &#x1f332; 作者简介&#xff1a;硕风和炜&#xff0c;…

基于Springboot的疫情隔离酒店管理系统(有报告)。Javaee项目,springboot项目。

演示视频&#xff1a; 基于Springboot的疫情隔离酒店管理系统&#xff08;有报告&#xff09;。Javaee项目&#xff0c;springboot项目。 项目介绍&#xff1a; 采用M&#xff08;model&#xff09;V&#xff08;view&#xff09;C&#xff08;controller&#xff09;三层体系…

4个AI智能写作平台,为你解决文章写作问题

在信息时代&#xff0c;写作是一项重要的技能&#xff0c;无论是在学术领域还是商务环境中。然而&#xff0c;对于许多人来说&#xff0c;写作并不是一件轻松的事情。但是&#xff0c;随着人工智能的发展&#xff0c;有许多AI智能写作平台可以帮助我们解决文章写作问题。在本文…

外包干了5年,技术退步明显.......

先说一下自己的情况&#xff0c;大专生&#xff0c;18年通过校招进入杭州某软件公司&#xff0c;干了接近4年的功能测试&#xff0c;今年年初&#xff0c;感觉自己不能够在这样下去了&#xff0c;长时间呆在一个舒适的环境会让一个人堕落! 而我已经在一个企业干了四年的功能测…

【MySQL】11. 复合查询(重点)

4. 子查询 子查询是指嵌入在其他sql语句中的select语句&#xff0c;也叫嵌套查询 4.1 单行子查询 返回一行记录的子查询 显示SMITH同一部门的员工 mysql> select * from emp where deptno (select deptno from emp where ename SMITH); -----------------------------…

Google AI 肺癌筛查的计算机辅助诊断

每周跟踪AI热点新闻动向和震撼发展 想要探索生成式人工智能的前沿进展吗&#xff1f;订阅我们的简报&#xff0c;深入解析最新的技术突破、实际应用案例和未来的趋势。与全球数同行一同&#xff0c;从行业内部的深度分析和实用指南中受益。不要错过这个机会&#xff0c;成为AI领…

计算机网络21-40

计算机网络21-40 以下是本文参考的资料 欢迎大家查收原版 本版本仅作个人笔记使用21、HTTPS是如何保证数据传输的安全&#xff0c;整体的流程是什么&#xff1f;&#xff08;SSL是怎么工作保证安全&#xff09;对称加密非对称加密消息认证码 (MAC)数字证书 22、如何保证公钥不被…

ABC346 A-G 题解

ABC346 A-G题解 A题目AC Code&#xff1a;时间复杂度 B题目时间复杂度AC Code&#xff1a; C题目时间复杂度AC Code&#xff1a; D题目时间复杂度AC Code&#xff1a; E题目时间复杂度AC Code&#xff1a; F题目时间复杂度AC Code&#xff1a; G题目时间复杂度AC Code&#xff…

Learn OpenGL 32 PBR光照

光照 在本章节中&#xff0c;我们把重点放在将之前讨论的理论转化为实际的渲染器&#xff0c;这个渲染器将使用直接的&#xff08;或解析的&#xff09;光源&#xff1a;比如点光源&#xff0c;定向灯或聚光灯。 我们先来看看上一个章提到的反射方程的最终版&#xff1a; 我们…

红楼梦人物关系知识图谱构建及推理研究

红楼梦人物关系知识图谱构建及推理研究 前言数据爬取与处理知识图谱构建可视化分析与推理研究总结 前言 《红楼梦》是中国古典文学巅峰之作&#xff0c;其中丰富的人物关系构成了一幅错综复杂的社会画卷。本文将介绍如何利用Python编写爬虫代码&#xff0c;使用Requests库进行…

字符串常量池

特点 1 只要是双引号引起来的字符串都存储在常量池中 2 每次存储字符串的时候&#xff0c;先检查常量池是否有该字符串&#xff0c;如果没有则存储&#xff0c;有则直接使用常量池中的字符串。 示例一&#xff1a; 字符串String由两部分组成&#xff0c;value(存储常量池中的…

Unity-C#进阶——3.27更新中

文章目录 数据结构类ArrayListStackQueueHashtable 泛型泛型类、泛型方法、泛型接口ListDictionaryLinkedList泛型栈&#xff0c;泛型队列 委托和事件委托事件匿名函数Lambad 表达式**闭包** List 排序逆变协变多线程进程线程多线程方法&#xff1a;线程之间共享数据&#xff1…

Java智慧工地源码 智慧工地的价值体现 开发一套智慧工地系统需要多少钱

智慧工地是智慧地球理念在工程领域的行业具现&#xff0c;是一种崭新的工程全生命周期管理理念。它运用信息化手段&#xff0c;通过三维设计平台对工程项目进行精确设计和施工模拟&#xff0c;围绕施工过程管理&#xff0c;建立互联协同、智能生产、科学管理的施工项目信息化生…

一键掌控:Shell脚本自动化安装与管理Conda环境的艺术

前面写了个博客《conda&#xff1a;解决多项目开发环境配置的神器&#xff01;》简单介绍了 Conda 的安装和基本命令&#xff0c;在做开发时经常会使用 Conda 建立多个应用环境&#xff0c;Conda 的命令虽不复杂&#xff0c;但还是有时会弄混&#xff0c;所以就考虑写个脚本&am…

day5-QT

widget.h #ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include<QFontDialog> //字体对话框类 #include<QFont> //字体类 #include<QMessageBox> //消息对话框类 #include<QColorDialog> //颜色对话框类 #include<QColor> //颜…

2024年腾讯云4核8G12M轻量服务器并发数测试,支持多少人?

腾讯云4核8G服务器价格&#xff1a;轻量4核8G12M优惠价格646元15个月、CVM S5服务器4核8G配置1437元买1年送3个月。腾讯云4核8G服务器支持多少人同时在线&#xff1f;支持30个并发数&#xff0c;可容纳日均1万IP人数访问。腾讯云百科txybk.com整理4核8G服务器支持多少人同时在线…