当前位置: 首页 > news >正文

网站建设运营协议书/百度seo泛解析代发排名

网站建设运营协议书,百度seo泛解析代发排名,下载手机软件的app,建设官网公司在游戏开发领域,坦克大战是一款经典的游戏,其简单而又耐玩的玩法吸引了无数玩家。而今,在Java编程技术的支持下,我们可以用Java Swing技术轻松实现这款经典游戏。本文将介绍如何使用Java Swing技术编写坦克大战游戏,并…

在游戏开发领域,坦克大战是一款经典的游戏,其简单而又耐玩的玩法吸引了无数玩家。而今,在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 完整代码

相关文章:

javaSwing坦克大战游戏

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

【面试题】数据底层原理:Elasticsearch写入流程解析

前言&#xff1a;本篇博客将介绍Elasticsearch的数据底层原理&#xff0c;涉及数据写入的过程以及相关概念。我们将深入探讨buffer、translog、refresh、commit、flush和merge等核心概念&#xff0c;帮助您更好地理解Elasticsearch的数据存储机制。 写入数据的基本过程 Elast…...

牛客论坛spring initializer选用的构件

spring版本&#xff1a;2.1.5.RELEASE java版本&#xff1a;8 pom文件&#xff1a; <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-i…...

【Java程序设计】【C00385】基于(JavaWeb)Springboot的员工信息管理系统(有论文)

基于&#xff08;JavaWeb&#xff09;Springboot的员工信息管理系统 项目简介项目获取开发环境项目技术运行截图 博主介绍&#xff1a;java高级开发&#xff0c;从事互联网行业六年&#xff0c;已经做了六年的毕业设计程序开发&#xff0c;开发过上千套毕业设计程序&#xff0c…...

【Linux进阶之路】理解UDP,成为TCP。

前言 学了TCP 和UDP之后&#xff0c;感觉UDP就像是初入职场的年轻人&#xff0c;两耳不闻 “窗外事”&#xff0c;只管尽力地把自己的事情做好&#xff0c;但收获的却是不可靠&#xff0c;而TCP更像是涉世极深的"职场老油条"&#xff0c;给人的感觉就是 “城府极深&a…...

Linux实用操作

一&#xff0c;各类小技巧&#xff08;快捷键&#xff09; 强制停止 ctrlc强制停止 Linux某些程序的运行&#xff0c;如果想要强制停止它&#xff0c;可以使用快捷键ctrlc 命令输入错误,也可以通过快捷键ctrlc,退出当前输入,重新输入 退出、登出 ctrld退出或登出 可以通过快…...

OpenJudge - 12:加密的病历单

总时间限制: 1000ms 内存限制: 65536kB 描述 小英是药学专业大三的学生&#xff0c;暑假期间获得了去医院药房实习的机会。 在药房实习期间&#xff0c;小英扎实的专业基础获得了医生的一致好评&#xff0c;得知小英在计算概论中取得过好成绩后&#xff0c;主任又额外交给她一…...

QGIS编译(跨平台编译)057:FastCGI编译(Windows、Linux、MacOS环境下编译)

文章目录 1、FastCGI介绍2、FastCGI下载3、Windows下编译4、linux下编译5、MacOS下编译1、FastCGI介绍 FCGI 是 FastCGI 的缩写,是一种用于改善 CGI(Common Gateway Interface)性能的协议。在传统的 CGI 中,每次请求都需要启动一个新的进程来处理,这导致了较高的资源消耗和…...

jenkins+newman+postman持续集成环境搭建

一、Newman简介 Newman是一款基于Node.js开发的&#xff0c;可以运用postman工具直接从命令运行和测试postman集合 二、Newman应用 环境准备&#xff1a;js/ cnpm或npm配置好环境&#xff0c;执行如下命令 三、安装newman 验证是否安装成功&#xff0c;命令&#xff1a;newm…...

取消自动设置的开机自启动(pywin32库)请勿仿照!否则可能对电脑造成损害。

本文使用创作助手。 要取消Python程序的开机自启动&#xff0c;可以通过删除注册表中相应的注册表项来实现。请按照以下步骤进行操作&#xff1a; 打开Windows注册表编辑器&#xff1a;按下 Windows R 键&#xff0c;输入 regedit&#xff0c;然后按下回车键。 导航到注册表…...

金融投贷通(金融投资+贷款通)项目准备

金融投贷通&#xff08;金融投资贷款通&#xff09;项目准备 专业术语投资专业术语本息专业术语还款专业术语项目介绍三个子系统技术架构核心流程发布借款标投资业务 项目实施测试流程测试步骤 专业术语 投资专业术语 案例&#xff1a;张三借给李四5W&#xff0c;约定期满1年后…...

跟我学C++中级篇——STL的中的删除

一、介绍 在STL中一般删除的方式有两类&#xff0c;一种是使用全局的std::remove(remove_if类似)&#xff0c;一种是使用容器自带的erase&#xff0c;前者其实并没有真正的删除数据&#xff0c;而后者则是在移动时&#xff0c;会有一些细节的处理&#xff0c;否则要么程序崩溃…...

js如何遍历查询一个颗树

近段时间去面试的时候&#xff0c;被面试官问到如何遍历查询一个颗树的时候&#xff0c;可能最近自己看了数据结构的书之后&#xff0c;隐隐约约就想到二叉树的三种排序&#xff08;前序、中序、后序&#xff09;&#xff0c;但是当时自己没有想起这三种排序的名字&#xff0c;…...

【面试必备】针对一个案例,怎么测试

思考角度 测试用例设计万能公式功能测试&#xff08;最重要&#xff09;界面测试易用性测试性能测试安全性测试兼容性测试容错性测试 常见案例物品类水杯笔 软件类微信发送朋友圈功能 测试用例设计万能公式 在面试中经常会遇到的一类题是&#xff0c;给你一个具体的产品&#…...

vue3 hooks之事件广播(支持跨标签页)

/**** 同源下的全局事件总线&#xff0c;支持跨标签页通信* 第一步&#xff1a;注册事件* 第二步&#xff1a;广播事件* 第三步&#xff1a;处理事件*/// source&#xff1a;消息发起源href&#xff0c;将在跨标签页通信时传入 interface callback {(data: any, source: any): …...

go中validate包使用教程

文章目录 前言安装简单使用错误处理翻译器Validator库介绍校验语法常用标记自定义校验需求【校验车身颜色】前言 在go项目中,经常有校验数据合法性的需求,比如邮箱、年龄、车牌号、网址、字符串长度、金额、枚举范围等。一个好的校验包能帮我们少写很多ifelse,提高系统的可…...

canvas画带透明度的直线和涂鸦

提示&#xff1a;canvas画线 文章目录 前言一、带透明度的直线和涂鸦总结 前言 一、带透明度的直线和涂鸦 test.html <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content…...

linux命令 curl忽略https证书

curl https://www.baidu.com 会提示需要htttps证书&#xff0c;加 -k 即可&#xff0c;如下&#xff1a; curl -k https://www.baidu.com 如果要带头部&#xff0c;认证数据&#xff0c;加-H curl -s -k -H "Authorization: Bearer 651fasgassssgjage2" https:/…...

游戏引擎中网络游戏的基础

一、前言 网络游戏所面临的挑战&#xff1a; 一致性&#xff1a;如何在所有的主机内都保持一样的表现可靠性&#xff1a;网络传输有可能出现丢包安全性&#xff1a;反作弊&#xff0c;反信息泄漏。多样性&#xff1a;不同设备之间链接&#xff0c;比如手机&#xff0c;ipad&a…...

ES6(ECMAScript 6)中常用的知识点总结(包含示例代码)

ES6(ECMAScript 6)是JavaScript语言的最新版本,它在ES5的基础上做了很多增强和扩展&#xff0c;使JavaScript的编程模式更加现代化和优雅,不仅拓展了语言表达能力,也为编程带来了全新的编程范式和思维方式。在项目中使用ES6,让代码更加简洁、方便模块化和面向对象实现等&#x…...

老师人手必备的教学神器有哪些?这5款教学软件一定要知道!

教师职业生活中有哪些“神器”&#xff1f;对老师来说堪称神器的东西有很多&#xff0c;笔者虽不是老师&#xff0c;工作内容有所不同&#xff0c;但工作给人带来的心力消耗&#xff08;心累/压力/焦虑&#xff09;、身体上的疲惫&#xff08;困&#xff09;等等&#xff0c;这…...

华为机试题-核酸检测人数

题目 为了达到新冠疫情精准防控的需要&#xff0c;为了避免全员核酸检测带来的浪费&#xff0c;需要精准圈定可能被感染的人群。现在根据传染病流调以及大数据分析&#xff0c;得到了每个人之间在时间、空间上是否存在轨迹的交叉。现在给定一组确诊人员编号 (X1, X2, X3, …, n…...

SQLAlchemy模型映射提示declarative_base() takes 0 positional arguments but 1 was given

原码&#xff1a; #SQLAlchemy模型映射表结构. from sqlalchemy import create_engine,Column,Integer,String from sqlalchemy.ext.declarative import declarative_base# 数据库的变量 HOST 127.0.0.1 PORT 3306 DATA_BASE itbz USER root PWD 123456 DB_URL fmysqlpy…...

linux系统Kubernetes工具ingress暴露服务

Ingress Ingressingress详解创建 Ingress 资源部署 Ingress 控制器&#xff08;Nginx&#xff09;下载ingress controller创建ingress-controller测试ingress创建两个应用和service配置ingress转发文件 修改ingress转发类型 Ingress 暴露服务基于域名的虚拟主机 Ingress 》ing…...

centos2anolis

我的centos7原地升级到anolis7记录 注意&#xff1a;如果是桌面版请先卸载firefox&#xff0c;否则so文件冲突。 参考&#xff1a; CentOS 7和8Linux系统迁移到国产Linux龙蜥Anolis OS 8手册_disable pam_pkcs11 module in pam configuration-CSDN博客 关于 CentOS 迁移龙蜥…...

Cesium安装部署运行

目录 1.简介 2.Cesium项目下载 3.Cesium项目运行 4.cesium运行 1.简介 Cesium是国外一个基于JavaScript编写的使用WebGL的地图引擎。Cesium支持3D,2D,2.5D形式的地图展示&#xff0c;可以自行绘制图形&#xff0c;高亮区域&#xff0c;并提供良好的触摸支持&#xff0c;且支…...

【Android 内存优化】KOOM线程泄漏监控的实现源码分析

文章目录 线程monitor的流程怎么判断线程是否泄漏AddThreadJoinThreadExitThreadDetachThread 总结 前面我们通过研究KOOM的开源代码&#xff0c;研究了关于Java层和native层内存泄漏监控的实现原理。还剩下线程泄漏这部分没有进行分析&#xff0c;今天来补全它。整体下来&…...

【爬虫基础】第1讲 网络爬虫基本知识

什么是网络爬虫 网络爬虫&#xff08;Web crawler&#xff09;是一种自动化程序&#xff0c;用于在互联网上收集信息。它可以通过扫描和解析网页的超链接&#xff0c;自动访问网页并抓取所需的数据。网络爬虫常用于搜索引擎和数据采集工具中。 作用 通过有效的爬虫手段批量采…...

scrapy爬虫框架

scrapy爬虫框架 一、scrapy的概念作用和工作流程1、scrapy的概念2、scrapy框架的作用3、scrapy的工作流程&#xff08;重点&#xff09;3.1 回顾之前的爬虫流程3.2 改写上述流程3.3 scrapy的流程3.4 scrapy的三个内置对象3.5 scrapy中每个模块的具体作用 二、scrapy的入门使用1…...

【深度学习】基础知识

吴恩达DeepLearning Python # 1.numpy c c.ravel() 将多维数组拉平 # 2.time tic time.time() toc time.time() print(str(1000*(toc- tic))"ms")...