Java坦克大战

画图基础

先定义画板类, 用于画图

// 定义画板类画板,用于画图
class MyPanel extends JPanel{// Graphics g是一只画笔// Graphics 提供了绘画方法public void paint(Graphics g){super.paint(g);g.drawOval(0,0,100,100);}}

定义窗口类,用于显示画板

// public类继承JFrame,用于定义窗口
public class Painting extends JFrame {public static void main(String[] args) {new Painting();}private MyPanel myPanel = null;public Painting(){myPanel = new MyPanel();// 窗口加入画布this.add(myPanel);this.setSize(500,500);// 设置窗口退出方式this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 显示窗口this.setVisible(true);}
}

paint方法被调用情况

  1. 组件第一次在屏幕显示的时候
  2. 窗口大小改变的时候
  3. repaint()方法被调用的时候

Graphics类常用方法

// 画直线
drawLine(int x1, int y1, int x2, int y2)
// 画矩形边框
drawRect(int x, int y, int width, int height)
// 画椭圆边框
drawOval(int x, int y, int width, int height)
// 填充矩形
fillRect(int x, int y, int width, int height)
// 填充椭圆
fillOval(int x, int y, int width, int height)
// 画图片
drawImage(Image img, int x, int y, ImageObserver observer)
g.drawImage(imgae, 0 , 0,889,500,this);
// 获得图片资源
Image image = Toolkit.getDefaultToolkit().getImage(MyPanel.class.getResource("/vertin.png"));
// 画字符串
drawString(String str, int x, int y)
// 设置画笔颜色
setColor(Color c)
// 设置字体
setFont(Font font)
setFont(new Font("宋体",Font.BOLD,20))
// 设置背景色
setBackground(Color c)

Java事件处理

事件源:产生事件的对象,比如按钮,窗口,文本框等
事件监听器:负责监听事件源所发生的事件,当事件发生时,事件监听器会自动调用相应的方法来处理事件
事件:事件源上发生的事情,比如单击,双击,键盘按下,鼠标移动等
事件发生时,事件源创建对象交给事件监听器,事件监听器调用相应的方法处理事件

事件处理流程:

  1. 组件.addXXXListener(监听器对象)
  2. 监听器对象实现接口
  3. 重写接口中的方法

事件监听器接口

  1. 鼠标事件监听器接口:MouseListener
  2. 键盘事件监听器接口:KeyListener
  3. 窗口事件监听器接口:WindowListener

事件监听器适配器

  1. 鼠标事件监听器适配器:MouseAdapter
  2. 键盘事件监听器适配器:KeyAdapter

坦克大战

MyPanel类,用于完成游戏界面绘制

package TankGame;import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;public class MyPanel extends JPanel implements KeyListener {public Player player = null;static Vector<RedEnemy> enemies = new Vector<>();private int enemiesNum = 6;private int points = 0;private int startMode = 0;private String saveAddress  = "d:\\save.dat";public int getPoints() {return points;}public void setPoints(int points) {this.points = points;}public static Vector<RedEnemy> getEnemies() {return enemies;}public static void setEnemies(Vector<RedEnemy> enemies) {MyPanel.enemies = enemies;}public MyPanel(){player = new Player(500, 500);for (int i = 0; i < enemiesNum; ++i) {RedEnemy e = new RedEnemy(10 + 100 * i, 10);enemies.add(e);}}public MyPanel(int startMode){File file = new File(saveAddress);if(startMode == 1 && file.exists()){try {ObjectInputStream oi = new ObjectInputStream(new FileInputStream(saveAddress));this.points = oi.readInt();player = (Player)oi.readObject();int N = oi.readInt();for(int i = 0;i < N;++i){RedEnemy e = (RedEnemy) oi.readObject();enemies.add(e);}} catch (IOException | ClassNotFoundException e) {throw new RuntimeException(e);} finally {}}else if(startMode == 0){player = new Player(500, 500);for (int i = 0; i < enemiesNum; ++i) {RedEnemy e = new RedEnemy(10 + 100 * i, 10);enemies.add(e);}}}@Overridepublic void paint(Graphics g) {super.paint(g);g.fillRect(0,0,1000,750);g.setColor(Color.CYAN);g.setFont(new Font("宋体",Font.BOLD,20));g.drawString("当前得分:" + points,  800, 700);// 绘制坦克if(player.isAlived())drawTank(player.getX(),player.getY(),g,player.getDir(),0);synchronized (player.getBullets()){// 绘制子弹Vector<Bullet> bullets = player.getBullets();for(Bullet b : bullets){switch (b.getType()){case 0:g.setColor(Color.yellow);break;case 1:g.setColor(Color.RED);break;}g.fillOval(b.getX(),b.getY(),10,10);}}synchronized (enemies) {for (Tank e : enemies) {drawTank(e.getX(), e.getY(), g, e.getDir(), 1);}}}public void drawTank(int x,int y,Graphics g,int dir, int type){// type决定颜色switch (type){case 0:// 玩家坦克g.setColor(Color.cyan);break;case 1:// 敌人坦克g.setColor(Color.magenta);break;default:g.setColor(Color.GRAY);}// dir决定方向 0上,1左,2右,3下switch (dir){case 0:g.fill3DRect(x,y,10,60,false);g.fill3DRect(x + 30,y,10,60,false);g.fill3DRect(x + 10,y + 10,20,40,false);g.fillOval(x + 10,y + 20,20,20);g.drawLine(x + 20,y + 30,x + 20,y);break;case 1:g.fill3DRect(x,y,60,10,false);g.fill3DRect(x,y + 30,60,10,false);g.fill3DRect(x + 10,y + 10,40,20,false);g.fillOval(x + 20,y + 10,20,20);g.drawLine(x + 30,y + 20,x ,y + 20);break;case 2:g.fill3DRect(x,y,60,10,false);g.fill3DRect(x,y + 30,60,10,false);g.fill3DRect(x + 10,y + 10,40,20,false);g.fillOval(x + 20,y + 10,20,20);g.drawLine(x + 30,y + 20,x + 60,y + 20);break;case 3:g.fill3DRect(x,y,10,60,false);g.fill3DRect(x + 30,y,10,60,false);g.fill3DRect(x + 10,y + 10,20,40,false);g.fillOval(x + 10,y + 20,20,20);g.drawLine(x + 20,y + 30,x + 20,y + 60);}}@Overridepublic void keyTyped(KeyEvent e) {}@Overridepublic void keyPressed(KeyEvent e) {if(!player.isAlived())return;if(e.getKeyCode() == KeyEvent.VK_J){//System.out.println("射击!");player.shoot();}//dir决定方向 0上,1左,2右,3下if(e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_A){player.setDir(1);player.moveLeft();}if(e.getKeyCode() == KeyEvent.VK_RIGHT || e.getKeyCode() == KeyEvent.VK_D){player.setDir(2);player.moveRight();}if(e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_W){player.setDir(0);player.moveUp();}if(e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_S){player.setDir(3);player.moveDown();}this.repaint();}@Overridepublic void keyReleased(KeyEvent e) {}
}

TankGame类,用于创建坦克大战游戏的窗口,并让用户在控制台选择是新游戏还是继续上一局游戏

package TankGame;import javax.swing.*;
import java.util.Scanner;public class TankGame extends JFrame {MyPanel myPanel = null;Timer timer = null;Checker checker = null;Saver saver = null;int startMode = 0;public TankGame(int startMode){myPanel = new MyPanel(startMode);timer = new Timer(myPanel.player.getBullets(),myPanel);checker = new Checker(myPanel.player.getBullets(),myPanel);saver = new Saver(myPanel);saver.setDaemon(true);timer.setDaemon(true);checker.setDaemon(true);timer.start();checker.start();saver.start();// 窗口加入画布this.add(myPanel);this.setSize(1000,750);// 设置窗口退出方式this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.addKeyListener(myPanel);// 显示窗口this.setVisible(true);}public static void main(String[] args) {Scanner scanner = new Scanner(System.in);//while(true){System.out.println("选择你想要开始的方式:");System.out.println("1. 新游戏");System.out.println("2. 上一次自动存档游戏");int input = scanner.nextInt();switch (input){case 1:new TankGame();break;case 2:new TankGame(1);break;default:new TankGame();break;}//}}public TankGame(){myPanel = new MyPanel();timer = new Timer(myPanel.player.getBullets(),myPanel);checker = new Checker(myPanel.player.getBullets(),myPanel);saver = new Saver(myPanel);saver.setDaemon(true);timer.setDaemon(true);checker.setDaemon(true);timer.start();checker.start();saver.start();// 窗口加入画布this.add(myPanel);this.setSize(1000,750);// 设置窗口退出方式this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.addKeyListener(myPanel);// 显示窗口this.setVisible(true);}
}

Tank类,用于实现坦克有关的所有行为,包括坦克的移动、发射子弹、判断是否碰撞等

package TankGame;import java.io.Serializable;
import java.util.Vector;public class Tank implements Collied , Serializable {private int x;private int y;private int dir = 3;     dir决定方向 0上,1左,2右,3下private int speed = 3;private int shootType = 0;private boolean isAlived = true;private boolean restricted = false;public boolean isRestricted() {return restricted;}public void setRestrict(boolean restricted) {this.restricted = restricted;}public boolean isAlived() {return isAlived;}public void setAlived(boolean alived) {isAlived = alived;}public boolean AinB(Tank t1, Tank t2){if(t1.getX() < t2.getX() || t1.getY() < t2.getY()){return false;}int t1x = t1.getX() + (t1.dir == 1 || t1.dir == 2 ? 0 : 20);int t1y = t1.getY() + (t1.dir == 1 || t1.dir == 2 ? 20 : 0);if(t2.dir == 0 || t2.dir == 3){return ((t1x - t2.getX() < 40 && t1y - t2.getY() < 60));}else{return t1x - t2.getX() < 60 &&  t1y - t2.getY() < 40;}}@Overridepublic boolean onCollision(Object o1, Object o2) {if(o1 instanceof Tank && o2 instanceof Tank){Tank t1 = (Tank) o1;Tank t2 = (Tank) o2;return AinB(t1,t2) || AinB(t2,t1);}return false;}public int getShootType() {return shootType;}public void setShootType(int shootType) {this.shootType = shootType;}private static Vector<Bullet> bullets= new Vector<>();public static Vector<Bullet> getBullets() {return bullets;}public void shoot(){//bullets.add(new Bullet(x,y,0,dir,10));switch (dir){case 0:bullets.add(new Bullet(x + 15,y,shootType,dir,10));break;case 1:bullets.add(new Bullet(x ,y + 15,shootType,dir,10));break;case 2:bullets.add(new Bullet(x + 60,y + 15,shootType,dir,10));break;case 3:bullets.add(new Bullet(x + 15,y + 60,shootType,dir,10));break;}} dir决定方向 0上,1左,2右,3下public void moveLeft(){x -= speed;if(x < 0 ){dir = 2;x += speed;}if(restricted){x += (int)(1.5 * speed);}}public void moveRight(){x += speed;if(x >= 930){dir = 1;x -= speed;}if(restricted){x -=  (int)(1.5 * speed);}}public void moveUp(){y -= speed;if(y < 0 ){dir = 3;y += speed;}if(restricted){y += (int)(1.5 * speed);}}public void moveDown(){y += speed;if(y >= 680 ){dir = 0;y -=  speed;}if(restricted){y -= (int)(1.5 * speed);}}public int getDir() {return dir;}public void setDir(int dir) {this.dir = dir;}public int getSpeed() {return speed;}public void setSpeed(int speed) {this.speed = speed;}public Tank(int x, int y) {this.x = x;this.y = y;}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;}
}

Player类,作为Tank类的子类,用于定义一些玩家坦克特有的属性和方法

package TankGame;public class Player extends Tank{public Player(int x,int y){super(x,y);setSpeed(5);}
}

RedEnemy类,作为Tank类的子类,用于定义一些敌方坦克特有的属性和方法

package TankGame;public class RedEnemy extends Tank{public RedEnemy(int x, int y) {super(x, y);setShootType(1);}public int moveTime = 500;public int shootTime = 1000;public final int MOVETIME = 500;public final int SHOOTTIME = 1000;
}

Bullet类,用于定义坦克发射的子弹的相关属性和方法

package TankGame;public class Bullet implements Collied{private int x;private int y;private int type;private int dir;private int speed;@Overridepublic boolean onCollision(Object o1, Object o2) {if(o2 instanceof Tank){Tank t = (Tank) o2;Bullet b = (Bullet) o1;if(b.getX() < t.getX() || b.getY() < t.getY()) return false;if(t.getDir() == 0 || t.getDir() == 3){return (b.getX() - t.getX() < 40 && b.getY() - t.getY() < 60);}else{return b.getX() - t.getX() < 60 && b.getY() - t.getY() < 40;}}return false;}public int getSpeed() {return speed;}public void setSpeed(int speed) {this.speed = speed;}public Bullet(int x, int y, int type, int dir, int speed) {this.x = x;this.y = y;this.type = type;this.dir = dir; // dir决定方向 0上,1左,2右,3下this.speed = speed;}public Bullet(int x, int y) {this.x = x;this.y = y;}public int getDir() {return dir;}public void setDir(int dir) {this.dir = dir;}public Bullet(int x, int y, int type, int dir) {this.dir = dir;this.type = type;this.y = y;this.x = x;}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 int getType() {return type;}public void setType(int type) {this.type = type;}public void moveLeft(){x -= speed;}public void moveRight(){x += speed;}public void moveUp(){y -= speed;}public void moveDown(){y += speed;}
}

Checker类,用于实现碰撞检测、游戏资源回收等功能

package TankGame;import java.util.Vector;public class Checker extends Thread{private Vector<Bullet> bullets = null;private MyPanel panel = null;private Vector<Bullet> removeBulletArr = new Vector<>();private Vector<RedEnemy> removeEnemiesArr = new Vector<>();private Vector<RedEnemy> enemies;public Checker(Vector<Bullet> bullets) {this.bullets = bullets;}public Checker(Vector<Bullet> bullets,MyPanel panel) {this.bullets = bullets;this.panel = panel;this.enemies = panel.getEnemies();}@Overridepublic void run() {while(true){try {Thread.sleep(10);} catch (InterruptedException e) {throw new RuntimeException(e);}//碰撞判断synchronized (bullets){//System.out.print("A");synchronized (enemies){//System.out.println("B");//检查碰撞for(Bullet b : bullets){if(b.getType() != 0 && b.onCollision(b,panel.player)){panel.player.setAlived(false);//panel.setPoints(panel.getPoints());}if(b.getType() == 1) continue;for(RedEnemy e : enemies) {if (!e.isAlived()) continue;if (b.onCollision(b, e)) {removeBulletArr.add(b);e.setAlived(false);removeEnemiesArr.add(e);panel.setPoints(panel.getPoints() + 10);}}}}}synchronized (enemies){boolean plCanMove = true;for(int i = 0;i < enemies.size();++i){RedEnemy e1 = enemies.get(i);boolean e1CanMove = true;for(int j = 0;j < enemies.size();++j) {if(j == i) continue;RedEnemy e2 = enemies.get(j);if (e1.onCollision(e1, e2)) {e1.setRestrict(true);e2.setRestrict(true);e1CanMove = false;}}Tank t = panel.player;if (e1.onCollision(e1, t)) {e1.setRestrict(true);t.setRestrict(true);e1CanMove = false;plCanMove = false;}if(e1CanMove){e1.setRestrict(false);}}if(plCanMove){panel.player.setRestrict(false);}}synchronized (bullets){//System.out.println(bullets.size());for(Bullet b : removeBulletArr){bullets.remove(b);}removeBulletArr.clear();}synchronized (enemies){//System.out.println(bullets.size());for(RedEnemy e : removeEnemiesArr){enemies.remove(e);}removeEnemiesArr.clear();}//无敌//panel.player.setAlived(true);//检查子弹是否超出边界synchronized (bullets){//System.out.println(bullets.size());for(Bullet b : bullets){if(b.getY() <= 0 || b.getY() >= 750 || b.getX() <= 0 || b.getX() >= 1000){removeBulletArr.add(b);}}for(Bullet b : removeBulletArr){bullets.remove(b);}removeBulletArr.clear();}panel.repaint();}}
}

Collied类,用于定义一个碰撞检测的类,其中包含一个方法,可以检测两个对象是否碰撞

package TankGame;public interface Collied {// 判断是否碰撞的方法boolean onCollision(Object o1,Object o2);
}

Timer类,用于模拟游戏时间流逝,然后根据时间的流逝更新子弹和坦克的位置

package TankGame;import java.awt.*;
import java.util.Vector;public class Timer extends Thread{private Vector<Bullet> bullets= new Vector<>();private MyPanel panel = null;private int deltaTime = 25;Vector<RedEnemy> enemies =  null;public Timer(Vector<Bullet> bullets) {this.bullets = bullets;}public Timer(Vector<Bullet> bullets,MyPanel panel) {this.bullets = bullets;this.panel = panel;enemies =  panel.enemies;}public int getDeltaTime() {return deltaTime;}public void setDeltaTime(int deltaTime) {this.deltaTime = deltaTime;}@Overridepublic void run() {while(true){// 40帧左右try {Thread.sleep(deltaTime);} catch (InterruptedException e) {throw new RuntimeException(e);}// 子弹运动synchronized (bullets){for(Bullet b : bullets){switch (b.getDir()){ dir决定方向 0上,1左,2右,3下case 0:b.moveUp();break;case 1:b.moveLeft();break;case 2:b.moveRight();break;case 3:b.moveDown();break;}}}// 敌人运动int nextDir = 0;synchronized (bullets) {synchronized (enemies) {for (RedEnemy t : enemies) {if (!t.isAlived()) {continue;}t.moveTime -= deltaTime;t.shootTime -= deltaTime;if (t.shootTime < 0) {t.shoot();t.shootTime = t.SHOOTTIME;}if (t.moveTime < 0) {t.moveTime = t.MOVETIME;nextDir = (int) (Math.random() * 4);} else {nextDir = t.getDir();}t.setDir(nextDir);switch (nextDir) {case 0:t.moveUp();break;case 1:t.moveLeft();break;case 2:t.moveRight();break;case 3:t.moveDown();break;}}//System.out.println("release e");}}panel.repaint();}}
}

Saver类,用于保存游戏状态到指定文件中去

package TankGame;import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.util.Vector;public class Saver extends Thread{private MyPanel panel = null;private int saveInterval = 10000;private String saveAddress  = "d:\\save.dat";private Tank player = null;private Vector<RedEnemy> enemies = null;public Saver(MyPanel panel) {this.panel = panel;this.player = panel.player;this.enemies = panel.getEnemies();}@Overridepublic void run() {while(true){try {Thread.sleep(saveInterval);} catch (InterruptedException e) {throw new RuntimeException(e);}try {ObjectOutputStream op = new ObjectOutputStream(new FileOutputStream(saveAddress));op.writeInt(panel.getPoints());op.writeObject(player);op.writeInt(enemies.size());synchronized (enemies ){for(int i = 0;i < enemies.size();++i){op.writeObject(enemies.get(i));}}op.close();} catch (IOException e) {throw new RuntimeException(e);} finally {}}}
}

项目源于视频:https://www.bilibili.com/video/BV1fh411y7R8?spm_id_from=333.788.videopod.episodes&vd_source=16bf0c507e4a78c3ca31a05dff1bee4e&p=569

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

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

相关文章

1.26学习

misc buuctf-神秘龙卷风 下载附件后打开&#xff0c;果然是一个加密的压缩包&#xff0c;用工具对这个压缩包进行破解&#xff0c;根据题目的四位数字我们可以知道密码是四位数字&#xff0c;所以破解得到密码解压后看到的是一串密文&#xff0c;是Brainfuck密文&#xff0c;…

把本地搭建的hexo博客部署到自己的服务器上

配置远程服务器的git 安装git 安装依赖工具包 yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel安装编译工具 yum install -y gcc perl-ExtUtils-MakeMaker package下载git&#xff0c;也可以去官网下载了传到服务器上 wget https://www.ke…

Ollama 运行从 ModelScope 下载的 GGUF 格式的模型

本文系统环境 Windows 10 Ollama 0.5.7 Ollama 是什么&#xff1f; Ollama 可以让你快速集成和部署本地 AI 模型。它支持各种不同的 AI 模型&#xff0c;并允许用户通过简单的 API 进行调用 Ollama 的安装 Ollama 官网 有其下载及安装方法&#xff0c;非常简便 但如果希…

【LLM】deepseek多模态之Janus-Pro和JanusFlow框架

note 文章目录 note一、Janus-Pro&#xff1a;解耦视觉编码&#xff0c;实现多模态高效统一技术亮点模型细节 二、JanusFlow&#xff1a;融合生成流与语言模型&#xff0c;重新定义多模态技术亮点模型细节 Reference 一、Janus-Pro&#xff1a;解耦视觉编码&#xff0c;实现多模…

【C++】特殊类设计、单例模式与类型转换

目录 一、设计一个类不能被拷贝 &#xff08;一&#xff09;C98 &#xff08;二&#xff09;C11 二、设计一个类只能在堆上创建对象 &#xff08;一&#xff09;将构造函数私有化&#xff0c;对外提供接口 &#xff08;二&#xff09;将析构函数私有化 三、设计一个类只…

【漫话机器学习系列】064.梯度下降小口诀(Gradient Descent rule of thume)

梯度下降小口诀 为了帮助记忆梯度下降的核心原理和关键注意事项&#xff0c;可以用以下简单口诀来总结&#xff1a; 1. 基本原理 损失递减&#xff0c;梯度为引&#xff1a;目标是让损失函数减少&#xff0c;依靠梯度指引方向。负梯度&#xff0c;反向最短&#xff1a;沿着负…

Autogen_core 测试代码:test_cache_store.py

目录 原始代码测试代码代码中用到的typing注解 原始代码 from typing import Dict, Generic, Optional, Protocol, TypeVarT TypeVar("T")class CacheStore(Protocol, Generic[T]):"""This protocol defines the basic interface for store/cache o…

文件上传2

BUUCTF 你传你&#x1f40e;呢 先上传.htaccess 修改格式 即可上传成功 返回上传图片格式的木马 用蚁剑连接 5ecf1cca-59a1-408b-b616-090edf124db5.node5.buuoj.cn:81/upload/7d8511a847edeacb5385299396a96d91/rao.jpg 即可得到flag [GXYCTF2019]BabyUpload

挂载mount

文章目录 1.挂载的概念(1)挂载命令&#xff1a;mount -t nfs(2)-t 选项&#xff1a;指定要挂载的文件系统类型(3)-o选项 2.挂载的目的和作用(1)跨操作系统访问&#xff1a;将Windows系统内容挂载到Linux系统下(2)访问外部存储设备(3)整合不同的存储设备 3.文件系统挂载要做的事…

UE求职Demo开发日志#15 思路与任务梳理、找需要的资源

1 思路梳理 因为有点无从下手&#xff0c;就梳理下最终形态. 基地的建设我是想单独一个场景&#xff0c;同一个关卡中小怪会每次来都会刷&#xff0c;小解密一次性的&#xff0c;关键的Boss和精英怪不会重复刷&#xff0c;同时场景里放一些资源可收集&#xff0c;基地建设锁定区…

vulfocus/thinkphp:6.0.12 命令执行

本次测试是在vulfocus靶场上进行 漏洞介绍 在其6.0.13版本及以前,存在一处本地文件包含漏洞。当多语言特性被开启时,攻击者可以使用lang参数来包含任意PHP文件。 虽然只能包含本地PHP文件,但在开启了register_argc_argv且安装了pcel/pear的环境下,可以包含/usr/local/lib/…

洛谷P3884 [JLOI2009] 二叉树问题(详解)c++

题目链接&#xff1a;P3884 [JLOI2009] 二叉树问题 - 洛谷 | 计算机科学教育新生态 1.题目解析 1&#xff1a;从8走向6的最短路径&#xff0c;向根节点就是向上走&#xff0c;从8到1会经过三条边&#xff0c;向叶节点就是向下走&#xff0c;从1走到6需要经过两条边&#xff0c…

如何获取小程序的code在uniapp开发中

如何获取小程序的code在uniapp开发中&#xff0c;也就是本地环境&#xff0c;微信开发者工具中获取code&#xff0c;这里的操作是页面一进入就获取code登录&#xff0c;没有登录页面的交互&#xff0c;所以写在了APP.vue中&#xff0c;也就是小程序一打开就获取用户的code APP.…

k8s支持自定义field-selector spec.hostNetwork过滤

好久没写博客啦&#xff0c;年前写一个博客就算混过去啦&#x1f602; 写一个小功能&#xff0c;对于 Pod&#xff0c;在没有 label 的情况下&#xff0c;支持 --field-selector spec.hostNetwork 查询 Pod 是否为 hostNetwork 类型&#xff0c;只为了熟悉 APIServer 是如何构…

olloama下载deepseek-r1大模型本地部署

1.登录olloama&#xff0c;选择models&#xff0c;选择deepseek-r1模型&#xff0c;选择1.5b(核显电脑) 2.选择1.5b&#xff0c;复制命令&#xff0c;打开CMD控制台&#xff1b; 3.控制台输入ollama run deepseek-r1:1.5b自动下载 4.部署完成 5.退出【Ctrl d】or 【/bye】 …

C语言初阶力扣刷题——349. 两个数组的交集【难度:简单】

1. 题目描述 力扣在线OJ题目 给定两个数组&#xff0c;编写一个函数来计算它们的交集。 示例&#xff1a; 输入&#xff1a;nums1 [1,2,2,1], nums2 [2,2] 输出&#xff1a;[2] 输入&#xff1a;nums1 [4,9,5], nums2 [9,4,9,8,4] 输出&#xff1a;[9,4] 2. 思路 直接暴力…

python学opencv|读取图像(四十九)使用cv2.bitwise()系列函数实现图像按位运算

【0】基础定义 按位与运算&#xff1a;两个等长度二进制数上下对齐&#xff0c;全1取1&#xff0c;其余取0。 按位或运算&#xff1a;两个等长度二进制数上下对齐&#xff0c;有1取1&#xff0c;其余取0。 按位异或运算&#xff1a; 两个等长度二进制数上下对齐&#xff0c;相…

ZZNUOJ(C/C++)基础练习1011——1020(详解版)

1011 : 圆柱体表面积 题目描述 输入圆柱体的底面半径r和高h&#xff0c;计算圆柱体的表面积并输出到屏幕上。要求定义圆周率为如下宏常量 #define PI 3.14159 输入 输入两个实数&#xff0c;表示圆柱体的底面半径r和高h。 输出 输出一个实数&#xff0c;即圆柱体的表面积&…

HTML特殊符号的使用示例

目录 一、基本特殊符号的使用 1、空格符号&#xff1a; 2、小于号 和 大于号&#xff1a; 3、引号&#xff1a; 二、版权、注册商标符号的使用 1、版权符号&#xff1a;© 2、注册商标符号&#xff1a; 三、数学符号的使用 四、箭头符号的使用 五、货币符号的使用…

java基础-容器

一、集合基础 1、集合 Collection接口下&#xff0c;主要用于存放单一元素Map接口下&#xff0c;用于存放键值对 2、常见集合的比较 List 存储的元素是有序的、可重复的。Set: 存储的元素不可重复的。Queue: 按特定的排队规则来确定先后顺序&#xff0c;存储的元素是有序的、…