王者小游戏作业

一、创建好文件、包、类、插入图片文件夹

二、beast包

1、Bear类

package beast;
import sxt.GameFrame;
public class Bear extends Beast {
    public Bear(int x, int y, GameFrame gameFrame) {
        super(x, y, gameFrame);
        setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\beast\\bear.jpg");
        width = 85;
        height = 112;
        setDis(65);
    }
 
}

2、Beast类

package beast;
 
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.ArrayList;
 
import sxt.*;
 
public class Beast extends GameObject {
 
    public ArrayList<Beast> beastList = new ArrayList<>();
    int width;
    int height;
    // 复活的元素
    Beast beast = null;
 
    public Beast(GameFrame gameFrame) {
        super(gameFrame);
        beastList.add(new RedBuff(3045, 3170, gameFrame));
        beastList.add(new Bear(2800, 2855, gameFrame));
        beastList.add(new Bird(3570, 3380, gameFrame));
        beastList.add(new Xiyi(4585, 2365, gameFrame));
        beastList.add(new BlueBuff(4025, 2295, gameFrame));
        beastList.add(new Wolf(4235, 1945, gameFrame));
    }
 
    public Beast(int x, int y, GameFrame gameFrame) {
        super(x, y, gameFrame);
        setHp(1000);
        setCurrentHp(getHp());
        beast = this;
    }
 
 
    @Override
    public void paintSelf(Graphics g) {
        if (getCurrentHp() <= 0) {
            System.out.println("beast die");
            setAlive(false);
            gameFrame.removeList.add(this);
            gameFrame.beast.beastList.remove(this);
            new ReviveCD().start();
        } else {
            // 添加生命值
            addHp(g, width / 2, 80, width, 20, Color.GREEN);
            g.drawImage(getImg(), getX() - width / 2, getY() - height / 2, null);
            g.setColor(Color.RED);
            g.fillOval(getX(), getY(), 10, 10);
            g.drawOval(getX() - getDis(), getY() - getDis(), 2 * getDis(), 2 * getDis());
        }
    }
 
    @Override
    public Rectangle getRec() {
        return new Rectangle(getX() - width / 2, getY() - height / 2, width, height);
    }
    //野怪复活
    class ReviveCD extends Thread {
        public void run() {
            // 线程休眠
            try {
                Thread.sleep(5000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            Beast reviveBeast;
            if (beast instanceof RedBuff) {
                reviveBeast = new RedBuff(3045, 3170, gameFrame);
            } else if (beast instanceof Bear) {
                reviveBeast = new Bear(2800, 2855, gameFrame);
            } else if (beast instanceof Bird) {
                reviveBeast = new Bird(3570, 3380, gameFrame);
            } else if (beast instanceof Xiyi) {
                reviveBeast = new Xiyi(4585, 2365, gameFrame);
            } else if (beast instanceof BlueBuff) {
                reviveBeast = new BlueBuff(4025, 2295, gameFrame);
            } else {
                reviveBeast = new Wolf(4235, 1945, gameFrame);
            }
            gameFrame.objList.add(reviveBeast);
            gameFrame.beast.beastList.add(reviveBeast);
        }
    }
 
}

3、Bird类

package beast;
import sxt.GameFrame;
public class Bird extends Beast {
    public Bird(int x, int y, GameFrame gameFrame) {
        super(x, y, gameFrame);
        setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\beast\\红隼.jpg");
        width = 122;
        height = 98;
        setDis(125);
    }
 
}

4、BlueBuff类

package beast;
import sxt.GameFrame;
public class BlueBuff extends Beast {
    public BlueBuff(int x, int y, GameFrame gameFrame) {
        super(x, y, gameFrame);
        setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\beast\\blueBuff.jpg");
        width = 142;
        height = 176;
        setDis(70);
    }
 
}

5、RedBuff类

package beast;
import sxt.GameFrame;
public class RedBuff extends Beast {
    public RedBuff(int x, int y, GameFrame gameFrame) {
        super(x, y, gameFrame);
        setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\beast\\redBuff.jpg");
        width = 103;
        height = 150;
        setDis(70);
    }
}

6、Wolf类

package beast;
import sxt.GameFrame;
public class Wolf extends Beast {
 
    public Wolf(int x, int y, GameFrame gameFrame) {
        super(x, y, gameFrame);
        setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\beast\\wolf.jpg");
        width = 145;
        height = 140;
        setDis(65);
    }
 
}

7、Xiyi类

package beast;
import sxt.GameFrame;
public class Xiyi extends Beast {
 
    public Xiyi(int x, int y, GameFrame gameFrame) {
        super(x, y, gameFrame);
        setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\beast\\蜥蜴.jpg");
        width = 111;
        height = 65;
        setDis(125);
    }
}

二、sxt包

1、Background类

package sxt;
 
import java.awt.*;
//背景类
public  class Background extends GameObject{
    public Background(GameFrame gameFrame) {
        super(gameFrame);
    }
 
    Image bg = Toolkit.getDefaultToolkit().getImage("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\Map.jpg");
 
    public void paintSelf(Graphics g){
        g.drawImage(bg,0,0,null);
 
    }
    @Override
    public Rectangle getRec() {
        return null;
    }
}

2、Bullet类

package sxt;
 
import java.awt.*;
 
//子弹类
public  class Bullet extends GameObject {
 
    //发射子弹的游戏元素
    GameObject attacker;
    //目标
    GameObject target;
    //攻击力
    int ad;
 
    public Bullet(GameFrame gameFrame, GameObject attacker, GameObject target, int ad, int spd) {
        super(attacker.getX(), attacker.getY(), gameFrame);
        this.attacker = attacker;
        this.target = target;
        setAd(ad);
        setSpd(spd);
    }
 
    public Bullet(GameFrame gameFrame, GameObject attacker, GameObject target, int ad, int spd, String img) {
        super(attacker.getX(), attacker.getY(), gameFrame);
        this.attacker = attacker;
        this.target = target;
        setImg(img);
        setAd(ad);
        setSpd(spd);
    }
 
    public Bullet() {
        super();
    }
 
    public void move() {
        //子弹与目标碰撞,子弹消失,目标减血
        if (recIntersectsRec(getRec(), target.getRec())) {
            target.setCurrentHp(target.getCurrentHp() - getAd());
            gameFrame.removeList.add(this);
        }
        int dis = (int) getDis(getX(), getY(), target.getX(), target.getY());
        if (dis != 0) {
            int xSpeed =  (getSpd() * (target.getX() - getX()) / dis);
            int ySpeed =  (getSpd() * (target.getY() - getY()) / dis);
            setX(getX() + xSpeed);
            setY(getY() + ySpeed);
        }
    }
 
    @Override
    public void paintSelf(Graphics g) {
        g.drawImage(getImg(), getX()-16, getY()-16, null);
        g.setColor(Color.BLACK);
        g.fillOval(getX()-5, getY()-5, 10, 10);
        g.drawRect(getX()-5, getY()-5, 10, 10);
        move();
    }
 
    @Override
    public Rectangle getRec() {
        return new Rectangle(getX()-5, getY()-5, 10, 10);
    }
    public int getAd() {
        return ad;
    }
 
    public void setAd(int ad) {
        this.ad = ad;
    }
}

3、Champion类

package sxt;
 
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
 
import javax.swing.JButton;
 
//游戏英雄类
public abstract class Champion extends GameObject {
    // 移动
    public boolean up, down, left, right;
    // 移动图集
    static String[] imgs = new String[8];
    // 第几张图片
    int moveCount = 1;
    //技能图片
    Image abilityOne;
    Image abilityTwo;
    Image abilityThree;
    //技能冷却时间
    int coolDownTimeOne;
    int coolDownTimeTwo;
    int coolDownTimeThree;
    //三个技能是否处于冷却状态
    boolean coolDownOne = true;
    boolean coolDownTwo = true;
    boolean coolDownThree = true;
 
    static {
        for (int i = 1; i < 8; i++) {
            imgs[i] = "C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\move\\" + i + ".png";
        }
    }
    public Champion(GameFrame gameFrame) {
        super(gameFrame);
 
        //定义英雄的图片和坐标
        setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\stand.png");
        setX(700);
        setY(3800);
        setSpd(75);
        setHp(24000);
        setDis(250);
        setAttackCoolDownTime(100);
        setCurrentHp(getHp());
    }
 
    public void keyPressed(KeyEvent e) {
        int key = e.getKeyCode();
        if (key == KeyEvent.VK_D) {
            right = true;}
        if (key == KeyEvent.VK_A) {
            left = true;}
        if (key == KeyEvent.VK_W) {
            up = true;}
        if (key == KeyEvent.VK_S) {
            down = true;}
    }
 
    public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();
        if (key == KeyEvent.VK_D) {
            right = false;}
        if (key == KeyEvent.VK_A) {
            left = false;}
        if (key == KeyEvent.VK_W) {
            up = false;}
        if (key == KeyEvent.VK_S) {
            down = false;}
    }
    public void move() {
        if (up) {
            setY(getY() - getSpd());
        }
        if (down) {
            setY(getY() + getSpd());
        }
        if (left) {
            setX(getX() - getSpd());
        }
        if (right) {
            setX(getX() + getSpd());
        }
        if (up || down || left || right) {
            setImg(imgs[moveCount]);
            moveCount++;
            if (moveCount == 8) {
                moveCount = 1;
            }
        } else {
            setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\stand.png");
        }
    }
 
    //添加三个技能按钮
 
    public void addButton() {
        JButton button1 = new JButton();
        button1.setSize(100, 100);
        button1.setLocation(1056, 513);
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                abilityOne();
            }
        });
        JButton button2 = new JButton();
        button2.setSize(100, 100);
        button2.setLocation(1090, 370);
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                abilityTwo();
            }
        });
        JButton button3 = new JButton();
        button3.setSize(100, 100);
        button3.setLocation(1220, 300);
        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                abilityThree();
            }
        });
        gameFrame.add(button1);
        gameFrame.add(button2);
        gameFrame.add(button3);
    }
 
    public abstract void abilityOne();
    public abstract void abilityTwo();
    public abstract void abilityThree();
    public abstract void abilityEffect(Graphics g);
 
    @Override
    public void paintSelf(Graphics g) {
        // 生命值为0
        if (getCurrentHp() <= 0) {
            setAlive(false);
            gameFrame.removeList.add(this);
 
        } else {
            // 添加生命值
            addHp(g, 30, 80, 80, 20, Color.GREEN);
            //绘制技能图片
            g.drawImage(abilityOne, getX() + 360, getY() + 180, null);
            g.drawImage(abilityTwo, getX() + 400, getY() + 40, null);
            g.drawImage(abilityThree, getX() + 520, getY() - 30, null);
            // 绘制图片
            g.drawImage(this.getImg(), getX() - 33, getY() - 50, null);
            // 改变画笔颜色
            g.setColor(Color.GREEN);
            // 绘制中心圆点
            g.fillOval(getX(), getY(), 10, 10);
            // 绘制矩形边框
            g.drawRect(getX() - 23, getY() - 50, 60, 120);
            move();
            abilityEffect(g);
        }
    }
 
    @Override
    public Rectangle getRec() {
        return new Rectangle(getX() - 30, getY() - 60, 60, 120);
    }
 
}

4、ChampionDaji类

package sxt;
 
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Random;
 
 
 
public class ChampionDaji extends Champion {
 
    // 技能是否处于释放状态
    boolean ifAbilityOne = false;
    boolean ifAbilityTwo = false;
    // 鼠标监视器
   MouseMonitor m;
    // 一技能多边形
    Polygon p;
    // 一技能三角函数
    double sin;
    double cos;
    // 一技能已经攻击过的目标
    ArrayList<GameObject> attacked;
    // 一技能移动次数
    int step = 0;
    // 技能二目标
    GameObject abilityTwoTarget;
    // 技能二子弹
    Bullet abilityTwoBullet;
    // 三技能的五个子弹,释放三技能后重新定义
    Bullet[] bulletList = { new Bullet(), new Bullet(), new Bullet(), new Bullet(), new Bullet() };
 
    public ChampionDaji(GameFrame gameFrame) {
        super(gameFrame);
        abilityOne = Toolkit.getDefaultToolkit().getImage("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\Daji\\abilityOne.jpg");
        abilityTwo = Toolkit.getDefaultToolkit().getImage("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\Daji\\abilityTwo.jpg");
        abilityThree = Toolkit.getDefaultToolkit().getImage("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\Daji\\abilityThree.jpg");
        // 三个技能冷却时间
        coolDownTimeOne = 3000;
        coolDownTimeTwo = 5000;
        coolDownTimeThree = 8000;
    }
 
    public void exit() {
        this.gameFrame.removeMouseListener(m);
    }
 
    public void abilityOneMove() {
        p.translate((int) (50 * cos), -(int) (50 * sin));
        for (GameObject redObj : gameFrame.redList) {
            // 是红色方小兵 && 发生碰撞 && 没在attacked列表里
            if (redObj instanceof MinionRed && p.intersects(redObj.getRec()) && attacked.indexOf(redObj) == -1) {
                // 小兵扣血,添加到attacked里
                redObj.setCurrentHp(redObj.getCurrentHp() - 400);
                attacked.add(redObj);
            }
        }
    }
 
    @Override
    public void abilityOne() {
        if (coolDownOne) {
            m = new MouseMonitor();
            p = new Polygon();
            gameFrame.addMouseListener(m);
            attacked = new ArrayList<GameObject>();
        }
    }
 
 
    public void abilityTwo() {
        if (coolDownTwo) {
            boolean find = false;
            for (GameObject redObj : gameFrame.objList) {
                // 是红色小兵 && 距离小于250 && 存活
                if (redObj instanceof MinionRed && recIntersectsCir(redObj.getRec(), getX(), getY(), 250)
                        && redObj.isAlive()) {
                    // 添加子弹
                    abilityTwoBullet = new Bullet(gameFrame, this, redObj, 250, 60, "C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\Daji\\abilityTwoBullet.png");
                    gameFrame.objList.add(abilityTwoBullet);
                    // 给目标赋值
                    abilityTwoTarget = redObj;
                    // 释放二技能
                    ifAbilityTwo = true;
                    find = true;
                    break;
                }
            }
            if (find) {
                new AbilityTwoCD().start();
                find = false;
            }
        }
    }
 
    /**
     * 点击技能三释放技能 先将技能范围内目标储存到targetList里 提前定义五个子弹 技能释放时初始化五个子弹 子弹目标从targetList里随机选择
     * 如果期间目标死亡,制作一个目标替身,生命值设置为true 子弹与目标或替身碰撞后消失
     */
    @Override
    public void abilityThree() {
        if (coolDownThree) {
            // 创建列表来储存目标
            ArrayList<GameObject> targetList = new ArrayList<GameObject>();
            // 遍历redList,找到符合条件的目标,储存到列表里
            for (int i = 0; i < gameFrame.objList.size(); i++) {
                GameObject target = gameFrame.objList.get(i);
                // 是红色小兵 && 在技能范围里 && 存活
                if (target instanceof MinionRed && recIntersectsCir(target.getRec(), getX(), getY(), 250)
                        && target.isAlive()) {
                    targetList.add(target);
                }
            }
            // 找到目标
            if (targetList.size() != 0) {
                // 创建五个子弹,随机攻击列表里的目标
                Random random = new Random();
                int count = 0; // 统计三技能发射子弹数量
                while (count < 5) {
                    int r = random.nextInt(targetList.size());
                    if (!targetList.get(r).isAlive()) {
                        GameObject substitute = targetList.get(r);
                        substitute.setAlive(true);
                        bulletList[count] = new Bullet(gameFrame, this, substitute, 150, 60,
                                "C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\Daji\\abilityTwoBullet.png");
                    } else {
                        bulletList[count] = new Bullet(gameFrame, this, targetList.get(r), 150, 60,
                                "C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\Daji\\abilityTwoBullet.png");
                    }
                    count++;
                }
                new AbilityThreeBulletCD().start();
                // 三技能进入冷却
                new AbilityThreeCD().start();
            }
        }
    }
 
    @Override
    public void abilityEffect(Graphics g) {
        if (ifAbilityOne) {
            g.setColor(Color.RED);
            g.fillPolygon(p);
            abilityOneMove();
            step++;
            if (step == 10) {
                step = 0;
                ifAbilityOne = false;
            }
        }
        if (ifAbilityTwo) {
            System.out.println(abilityTwoTarget.beControlled);
            if (abilityTwoBullet.getRec().intersects(abilityTwoTarget.getRec())) {
                new AbilityControllCD().start();
                ifAbilityTwo = false;
            }
        }
    }
 
    // 技能一冷却时间
    class AbilityOneCD extends Thread {
        public void run() {
            // 将技能一设置为冷却状态
            coolDownOne = false;
            // 线程休眠
            try {
                // one来表示一技能冷却时间
                int one = coolDownTimeOne;
                while (one > 0) {
                    Thread.sleep(1000);
                    System.out.println("一技能冷却时间: " + one / 1000);
                    one -= 1000;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            // 将技能一设置为攻击状态
            coolDownOne = true;
            // 线程终止
            this.interrupt();
        }
    }
 
    // 技能二冷却时间
    class AbilityTwoCD extends Thread {
        public void run() {
            // 将技能二设置为冷却状态
            coolDownTwo = false;
            // 线程休眠
            try {
                // one来表示二技能冷却时间
                int two = coolDownTimeTwo;
                while (two > 0) {
                    Thread.sleep(1000);
                    System.out.println("二技能冷却时间: " + two / 1000);
                    two -= 1000;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            // 将技能二设置为攻击状态
            coolDownTwo = true;
            // 线程终止
            this.interrupt();
        }
    }
 
    // 技能二控制时间
    class AbilityControllCD extends Thread {
        public void run() {
            abilityTwoTarget.beControlled = true;
            // 线程休眠
            try {
                Thread.sleep(20000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            abilityTwoTarget.beControlled = false;
            this.interrupt();
        }
 
    }
    //技能三冷却状态
    class AbilityThreeCD extends Thread {
        public void run() {
            // 将攻击功能设置为冷却状态
            coolDownThree = false;
            // 休眠
            try {
                int three = coolDownTimeThree;
                while (coolDownTimeThree > 0) {
                    Thread.sleep(1000);
                    System.out.println("技能三冷却时间: " + coolDownTimeThree / 1000);
                    coolDownTimeThree -= 1000;
                }
                coolDownTimeThree = three;
            } catch (Exception e) {
                e.printStackTrace();
            }
            // 将攻击功能解除冷却状态
            coolDownThree = true;
            // 线程终止
            this.interrupt();
        }
    }
 
    class AbilityThreeBulletCD extends Thread {
        public void run() {
            // 休眠
            try {
                System.out.println("Thread start");
                gameFrame.objList.add(bulletList[0]);
                Thread.sleep(100);
                gameFrame.objList.add(bulletList[1]);
                Thread.sleep(100);
                gameFrame.objList.add(bulletList[2]);
                Thread.sleep(100);
                gameFrame.objList.add(bulletList[3]);
                Thread.sleep(100);
                gameFrame.objList.add(bulletList[4]);
            } catch (Exception e) {
                e.printStackTrace();
            }
            // 线程终止
            this.interrupt();
        }
    }
 
    // 鼠标监视器
    private class MouseMonitor extends MouseAdapter {
        @Override
        public void mousePressed(MouseEvent e) {// 当鼠标点击时
            int mouseX = e.getX(), mouseY = e.getY(), playerX = 700, playerY = 350;
            double dis = getDis(mouseX, mouseY, playerX, playerY);
            // 三角函数
            cos = (mouseX - playerX) / dis;
            sin = -(mouseY - playerY) / dis;
            // 坐标差
            int difX = (int) (60 * sin);
            int difY = (int) (60 * cos);
            p.addPoint(getX() - difX, getY() - difY);
            p.addPoint(getX() + difX, getY() + difY);
            p.addPoint(getX() + difX + (int) (20 * cos), getY() + difY - (int) (20 * sin));
            p.addPoint(getX() - difX + (int) (20 * cos), getY() - difY - (int) (20 * sin));
            exit();
            new AbilityOneCD().start();
            ifAbilityOne = true;
        }
    }
}

5、GameFrame类

package sxt;
 
import beast.Beast;
 
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.ArrayList;
 
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.FloatControl;
import javax.swing.JButton;
import javax.swing.JFrame;
 
public class GameFrame extends JFrame {
    // 游戏开始 0, 游戏胜利1,游戏失败2
    int state = 0;
    // 窗口尺寸
    final int windowWidth = 1400;
    final  int windowHeight = 700;
    // 双缓冲图片
    private Image offScreenImage = null;
    // 攻击图片
    private Image attack = Toolkit.getDefaultToolkit().getImage("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\attack.jpg");
    //游戏胜利失败图片
    private Image gameWin = Toolkit.getDefaultToolkit().getImage("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\gameWin.png");
    private Image gameLose = Toolkit.getDefaultToolkit().getImage("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\gameLose.png");
    // 游戏背景
    Background background = new Background(this);
    // 游戏玩家
    Champion player = new ChampionDaji(this);
    // 双方小兵
    MinionBlue mb = new MinionBlue(this);
    MinionRed mr = new MinionRed(this);
    //野怪
    public Beast beast = new Beast(this);
    // 防御塔
    Turret turret = new Turret(this);
    // 游戏元素列表
   public ArrayList<GameObject> objList = new ArrayList<>();
    ArrayList<GameObject> redList = new ArrayList<>();// 红色方
    ArrayList<GameObject> blueList = new ArrayList<>();// 蓝色方
    public ArrayList<GameObject> removeList = new ArrayList<>();// 存放将要删除的元素
 
    public void launch() {
        // 设置尺寸
        setSize(windowWidth, windowHeight);
        // 窗口居中
        setLocationRelativeTo(null);
        // 关闭事件
        setDefaultCloseOperation(3);
        // 用户不能调整窗口大小
        setResizable(false);
        // 标题
        setTitle("王者荣耀");
        // 窗口可见
        setVisible(true);
        // 添加键盘监视器
        this.addKeyListener(new GameFrame.KeyMonitor());
        // 添加游戏元素
        objList.add(background);
        objList.add(player);
        objList.addAll(beast.beastList);
        objList.addAll(turret.turretList);
        playMusic();
       for (int i = 0; i < 4; i++) {
            blueList.add(turret.turretList.get(i));
        }
        for (int i = 4; i < 8; i++) {
            redList.add(turret.turretList.get(i));
        }
 
 
        /**
         * 攻击按钮
         */
        JButton button = new JButton();
        button.setSize(130, 132);
        button.setLocation(1150, 430);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 按钮事件
                player.attack(redList);
            }
        });
        this.add(button);
        player.addButton();
        while (true) {
 
            mb.createMinion(this, blueList);
            mr.createMinion(this, redList);
            repaint();
            try {
                Thread.sleep(25);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
    public void paint(Graphics g) {
        if (offScreenImage == null) {
            offScreenImage = this.createImage(5984, 4452);
        }
        Graphics gImage = offScreenImage.getGraphics();
       if(state==0){
           turret.isLive();
            for (int i = 0; i < objList.size(); i++) {
                objList.get(i).paintSelf(gImage);
            }
            // 绘制攻击图片
           gImage.drawImage(attack, player.getX() + 500, player.getY() + 100, null);
 
            objList.removeAll(removeList);
        } else if (state ==1) {//游戏胜利
 
            gImage.drawImage(gameWin, player.getX()-700, player.getY()-300 , null);
        } else if (state == 2) {//游戏失败
            gImage.drawImage(gameLose, player.getX()-700, player.getY()-300, null);
        }
        g.drawImage(offScreenImage, -player.getX() + 700, -player.getY() + 350, null);
         // 添加按钮后不能调用键盘事件 因为程序的焦点变成了按钮 this.requestFocus() 把焦点重新改变到游戏界面上
 
        this.requestFocus();
    }
 
    // main方法
    public static void main(String[] args) {
        GameFrame gameFrame = new GameFrame();
        gameFrame.launch();
 
    }
    // 键盘事件
    private class KeyMonitor extends KeyAdapter {
        @Override
        public void keyPressed(KeyEvent e) {
            int key = e.getKeyCode();
            player.keyPressed(e);
        }
 
        @Override
        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            player.keyReleased(e);
        }
    }
    static Clip clip;
    public static void playMusic() {
        try
        {
            //这里面放 绝对路径,音频必须是wav格式,用音频转换软件 把mp3 转成wav格式
            File musicPath = new File("");
 
            if(musicPath.exists())
            {
                AudioInputStream audioInput = AudioSystem.getAudioInputStream(musicPath);
                clip = AudioSystem.getClip();
                clip.open(audioInput);
                FloatControl gainControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
                gainControl.setValue(-20.0f);//设置音量,范围为 -60.0f 到 6.0f
                clip.start();
                clip.loop(Clip.LOOP_CONTINUOUSLY);
            }
            else
            {
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
 
}

6、GameObject类

package sxt;
 
import java.awt.*;
import java.util.ArrayList;
 
//游戏元素的父类
public abstract class GameObject {
    // 坐标
    private int x;
    private int y;
    // 图片
    private Image img;
    // 游戏界面
    public GameFrame gameFrame;
    // 速度
    private int spd;
    // 初始生命值
    private int hp;
    // 当前生命值
    private int currentHp;
    // 攻击目标
    private GameObject target;
    // 是否有目标
    private boolean hasTarget = false;
    // 攻击距离
    private int dis;
    // 攻击时间间隔
    private int attackCoolDownTime;
    // 攻击是否冷却
    private boolean attackCoolDown = true;
    // 是否存活
    private boolean alive = true;
    //是否被控制
    boolean beControlled = false;
 
    public GameObject(GameFrame gameFrame) {
        this.gameFrame = gameFrame;
    }
 
    public GameObject(int x, int y, GameFrame gameFrame) {
        this.x = x;
        this.y = y;
        this.gameFrame = gameFrame;
    }
 
    public GameObject() {
    }
    public void addHp(Graphics g, int difX, int difY, int width, int height, Color color) {
        // 绘制外部轮廓
        g.setColor(Color.black);
        g.drawRect(getX() - difX, getY() - difY, width, height);
        // 填充矩形
        g.setColor(color);
        g.fillRect(getX() - difX, getY() - difY, (int) (width * getCurrentHp() / getHp()), height);
    }
 
    public double getDis(int x1, int y1, int x2, int y2) {
        return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
    }
 
    // 矩形矩形碰撞检测
    public boolean recIntersectsRec(Rectangle r1, Rectangle r2) {
        return r1.intersects(r2);
    }
 
    public boolean recIntersectsCir(Rectangle rec, int x, int y, int r) {
        // 矩形于圆相交: 圆心到至少一个矩形定点的距离小于r
        if ((getDis(x, y, rec.x, rec.y) < r) || (getDis(x, y, rec.x, rec.y + rec.height) < r)
                || (getDis(x, y, rec.x + rec.width, rec.y) < r)
                || (getDis(x, y, rec.x + rec.width, rec.y + rec.height) < r)) {
            return true;
        }
        return false;
    }
 
    // 攻击方法
    public void attack(ArrayList<GameObject> gameObjList) {
        if (hasTarget) {
            // 目标离开范围后寻找新的目标
            if (!recIntersectsCir(target.getRec(), getX(), getY(), getDis())) {
                setHasTarget(false);
            }
            // 目标死亡,寻找新目标
            else if (!target.isAlive()) {
                setHasTarget(false);
            } else if (isAttackCoolDown() && isAlive()) {
                Bullet bullet = null;
                // 防御塔攻击
                if (Turret.class.isAssignableFrom(getClass())) {
                    bullet = new Bullet(gameFrame, this, getTarget(), 500, 50);
                }
                // 小兵攻击
                else if (Minion.class.isAssignableFrom(getClass())) {
                    bullet = new Bullet(gameFrame, this, getTarget(), 50, 30);
                }
                // 玩家攻击
                else if (this instanceof Champion) {
                    bullet = new Bullet(gameFrame, this, getTarget(), 500, 50);
                }
                gameFrame.objList.add(bullet);
                // 线程开始
                new AttackCD().start();
            }
        } else {
            // 遍历列表
            for (GameObject obj : gameObjList) {
                // 判断攻击范围(圆形)与敌方(矩形)是否相交
                if (recIntersectsCir(obj.getRec(), getX(), getY(), getDis())) {
                    // 找到目标
                    setTarget(obj);
                    setHasTarget(true);
                    // 跳出循环
                    break;
                }
            }
            // 玩家是否在攻击范围内
            if (!hasTarget && gameObjList == gameFrame.blueList) {
                if (recIntersectsCir(gameFrame.player.getRec(), getX(), getY(), getDis())) {
                    // 找到目标
                    setTarget(gameFrame.player);
                    setHasTarget(true);
                }
            }
            else {
                //野怪是否在攻击范围内
                for (GameObject obj : gameFrame.beast.beastList) {
                    // 判断攻击范围(圆形)与敌方(矩形)是否相交
                    if (recIntersectsCir(obj.getRec(), getX(), getY(), getDis())) {
                        // 找到目标
                        setTarget(obj);
                        setHasTarget(true);
                        // 跳出循环
                        break;
                    }
                }
            }
        }
    }
 
    //public abstract void addTurret();
 
    class AttackCD extends Thread {
        public void run() {
            // 将攻击功能设置为冷却状态
            setAttackCoolDown(false);
            // 线程休眠
            try {
                Thread.sleep(attackCoolDownTime);
            } catch (Exception e) {
                e.printStackTrace();
            }
            // 将攻击功能设置为攻击状态
            setAttackCoolDown(true);
            // 线程终止
            this.interrupt();
        }
    }
 
    // 绘制元素
    public abstract void paintSelf(Graphics g);
 
    // 返回矩形
    public abstract Rectangle getRec();
    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 Image getImg() {
        return img;
    }
    public void setImg(String img) {
        this.img = Toolkit.getDefaultToolkit().getImage(img);
    }
    public int getSpd() {
        return spd;
    }
    public void setSpd(int spd) {
        this.spd = spd;
    }
    public int getHp() {
        return hp;
    }
    public void setHp(int hp) {
        this.hp = hp;
    }
    public int getCurrentHp() {
        return currentHp;
    }
    public void setCurrentHp(int currentHp) {
        this.currentHp = currentHp;
    }
    public GameObject getTarget() {
        return target;
    }
    public void setTarget(GameObject target) {
        this.target = target;
    }
    public boolean isHasTarget() {
        return hasTarget;
    }
    public void setHasTarget(boolean hasTarget) {
        this.hasTarget = hasTarget;
    }
    public int getDis() {
        return dis;
    }
    public void setDis(int dis) {
        this.dis = dis;
    }
    public int getAttackCoolDownTime() {
        return attackCoolDownTime;
    }
    public void setAttackCoolDownTime(int attackCoolDownTime) {
        this.attackCoolDownTime = attackCoolDownTime;
    }
    public boolean isAttackCoolDown() {
        return attackCoolDown;
    }
    public void setAttackCoolDown(boolean attackCoolDown) {
        this.attackCoolDown = attackCoolDown;
    }
    public boolean isAlive() {
        return alive;
    }
    public void setAlive(boolean alive) {
        this.alive = alive;
    }
}

7、Minion类

package sxt;
 
import java.awt.*;
import java.util.ArrayList;
 
public abstract class Minion extends GameObject{
 
    // 是否生成下一个小兵
    private boolean nextMinion = true;
    // 是否生成下一波小兵
    private boolean nextLine = true;
    // 生成小兵数量
    private int minionCount = 0;
    // 是否检测到目标
    private boolean ifFindTarget = false;
 
    public Minion(GameFrame gameFrame) {
        super(gameFrame);
        setHp(800);
        setCurrentHp(getHp());
        setDis(100);
        setAttackCoolDownTime(2000);
    }
 
    /**
     * (1325, 3750) (4425, 3750) (5050, 3125) (5050, 1125)
     */
 
    public abstract void move(ArrayList<GameObject> objList);
 
    public void findTarget(ArrayList<GameObject> objList) {
        for (GameObject obj : objList) {
            if (recIntersectsCir(obj.getRec(), getX(), getY(), 200)) {
                setTarget(obj);
                setIfFindTarget(true);
            }
        }
        if (objList == gameFrame.blueList) {
            if (recIntersectsCir(gameFrame.player.getRec(), getX(), getY(), 200)) {
                setTarget(gameFrame.player);
                setIfFindTarget(true);
            }
        }
    }
 
    public void moveToTarget() {
        int dis = (int) getDis(getX(), getY(), getTarget().getX(), getTarget().getY());
        if(dis!=0) {
            int xSpeed =  (getSpd() * (getTarget().getX() - getX()) / dis);
            int ySpeed = (getSpd() * (getTarget().getY() - getY()) / dis);
            setX(getX() + xSpeed);
            setY(getY() + ySpeed);
        }
    }
 
    public void createMinion(GameFrame gameFrame, ArrayList<GameObject> minionList) {
        if (nextLine) {
            if (nextMinion) {
                // 蓝色方小兵
                if (minionList == this.gameFrame.blueList) {
                    MinionBlue mb = new MinionBlue(gameFrame);
                    gameFrame.objList.add(mb);
                    minionList.add(mb);
                }
                // 红色方小兵
                else {
                    MinionRed mr = new MinionRed(gameFrame);
                    gameFrame.objList.add(mr);
                    minionList.add(mr);
                }
                minionCount++;
                new NextMinion().start();
            }
            if (minionCount == 3) {
                minionCount = 0;
                new NextLine().start();
            }
        }
    }
 
    // 每个小兵生成时间
    class NextMinion extends Thread {
        public void run() {
            nextMinion = false;
            // 休眠1.5s
            try {
                Thread.sleep(1500);
            } catch (Exception e) {
                e.printStackTrace();
            }
            nextMinion = true;
            // 线程终止
            this.interrupt();
        }
    }
 
    // 每波小兵生成时间
    class NextLine extends Thread {
        public void run() {
            nextLine = false;
            // 休眠15s
            try {
                Thread.sleep(15000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            nextLine = true;
            // 线程终止
            this.interrupt();
        }
    }
 
    @Override
    public void paintSelf(Graphics g) {
        // 生命值为0
        if (getCurrentHp() <= 0) {
            setAlive(false);
            gameFrame.removeList.add(this);
            if (this instanceof MinionBlue) {
                gameFrame.blueList.remove(this);
            } else {
                gameFrame.redList.remove(this);
            }
        } else {
            // 添加生命值
            if (this instanceof MinionBlue) {
                this.addHp(g, 17, 28, 45, 10, Color.GREEN);
            } else {
                this.addHp(g, 17, 28, 45, 10, Color.RED);
            }
            g.drawImage(getImg(), getX() - 16, getY() - 16, null);
            g.setColor(Color.RED);
            g.fillOval(getX(), getY(), 10, 10);
            g.drawRect(getX() - 16, getY() - 16, 45, 45);
            g.drawOval(getX() - 200, getY() - 200, 400, 400);
            // 小兵移动
            if (!beControlled) {
                if (this instanceof MinionBlue) {
                    move(gameFrame.redList);
                } else {
                    move(gameFrame.blueList);
                }
            }
        }
    }
 
    @Override
    public Rectangle getRec() {
        return new Rectangle(getX() - 16, getY() - 16, 45, 45);
    }
 
    public boolean isIfFindTarget() {
        return ifFindTarget;
    }
    public void setIfFindTarget(boolean ifFindTarget) {
        this.ifFindTarget = ifFindTarget;
    }
 
}

8、MinionBlue类

package sxt;
 
import java.util.ArrayList;
 
public  class MinionBlue extends Minion{
 
    public MinionBlue(GameFrame gameFrame) {
        super(gameFrame);
        setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\minion\\blue.jpg");
        setX(1325);
        setY(3750);
    }
 
    @Override
    public void move(ArrayList<GameObject> objList) {
        if(isIfFindTarget()) {
            //离开检测范围
            if(!recIntersectsCir(getTarget().getRec(), getX(), getY(), 200)) {
                setIfFindTarget(false);
            }else {
                if(!isHasTarget()) {
                    moveToTarget();
                }
                attack(objList);
            }
        }else {
            findTarget(objList);
            //原路线移动
            if(getX() < 4425) {
                setSpd(5);
                setX(getX() + getSpd());
            }else if(getX() < 5100 && getX() >= 4425) {
                setSpd(20);
                setX(getX() + getSpd());
                setY(getY() - getSpd());
            }else if(getX() >= 4900) {
                setSpd(18);
                setY(getY() - getSpd());
            }
        }
    }
}

9、MinionRed类

package sxt;
 
import java.util.ArrayList;
 
public  class MinionRed extends Minion {
    public MinionRed(GameFrame gameFrame) {
        super(gameFrame);
        setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\minion\\red.jpg");
        setX(5050);
        setY(1125);
    }
 
    @Override
    public void move(ArrayList<GameObject> objList) {
        if (isIfFindTarget()) {
            // 离开检测范围
            if (!recIntersectsCir(getTarget().getRec(), getX(), getY(), 200)) {
                setIfFindTarget(false);
            } else {
                if (!isHasTarget()) {
                    moveToTarget();
                }
                attack(objList);
            }
        } else {
            findTarget(objList);
            // 原路线移动
            if (getY() < 3125) {
                setSpd(28);
                setY(getY() + getSpd());
            } else if (getY() < 3750 && getY() >= 3125) {
                setSpd(20);
                setY(getY() + getSpd());
                setX(getX() - getSpd());
            } else if (getY() >= 3750) {
                setSpd(25);
                setX(getX() - getSpd());
            }
        }
    }
 
 
 
 
}

10、Turret类

package sxt;
 
import java.awt.*;
import java.util.ArrayList;
//防御塔类
public  class Turret extends GameObject{
 
    ArrayList<Turret> turretList = new ArrayList<>();
    public Turret turretBlueOne;
    public Turret turretBlueTwo;
    public Turret turretBlueThree;
    public Turret turretBlueBase;
    public Turret turretRedOne;
    public Turret turretRedTwo;
    public Turret turretRedThree;
    public Turret turretRedBase;
 
    public Turret(GameFrame gameFrame) {
        super(gameFrame);
        setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\turret.png");
 
        // 初始化八个防御塔
        turretList.add(turretBlueOne = new TurretBlue(1860, 3790, gameFrame));
        turretList.add(turretBlueTwo = new TurretBlue(2650, 3820, gameFrame));
        turretList.add(turretBlueThree = new TurretBlue(3995, 3830, gameFrame));
        turretList.add(turretBlueBase = new TurretBlue(1130, 3650, gameFrame));
        turretList.add(turretRedOne = new TurretRed(5100, 3030, gameFrame));
        turretList.add(turretRedTwo = new TurretRed(5120, 2100, gameFrame));
        turretList.add(turretRedThree = new TurretRed(5060, 1570, gameFrame));
        turretList.add(turretRedBase = new TurretRed(4850, 1100, gameFrame));
 
    }
 
    public Turret(int x, int y, GameFrame gameFrame) {
        super(x, y, gameFrame);
        setImg("C:\\Users\\陆先生\\Desktop\\王者荣耀图片(1)\\王者荣耀图片\\turret.png");
        setHp(6000);
        setCurrentHp(getHp());
        setAttackCoolDownTime(1000);
        setDis(300);
    }
    public void isLive(){
        if(gameFrame.turret.turretBlueBase.getCurrentHp()==0){
            gameFrame.state=2;
        }
        if(gameFrame.turret.turretRedBase.getCurrentHp()==0){
            gameFrame.state=1;
        }
    }
    @Override
    public void paintSelf(Graphics g) {
        // 生命值为0
        if (getCurrentHp() <= 0) {
            setAlive(false);
            gameFrame.removeList.add(this);
            if (this instanceof TurretBlue) {
                gameFrame.blueList.remove(this);
            } else {
                gameFrame.redList.remove(this);
            }
        } else {
            // 添加生命值
            if (this instanceof TurretBlue) {
                this.addHp(g, 50, 130, 100, 20, Color.GREEN);
                attack(gameFrame.redList);
            } else {
                this.addHp(g, 50, 130, 100, 20, Color.RED);
                attack(gameFrame.blueList);
            }
            g.drawImage(getImg(), getX() - 50, getY() - 100, null);
            g.fillOval(getX(), getY(), 10, 10);
            g.drawRect(getX() - 50, getY() - 100, 100, 180);
            g.drawOval(getX() - 300, getY() - 300, 600, 600);
        }
    }
 
    @Override
    public Rectangle getRec() {
        return new Rectangle(getX() - 50, getY() - 100, 100, 180);
    }
}

11、TurretBlue类

package sxt;
//蓝方防御塔
public class TurretBlue extends Turret{
    //有参构造
    public TurretBlue(GameFrame gameFrame){
        super(gameFrame);
    }
    public TurretBlue(int x,int y,GameFrame gameFrame){
        super(x,y,gameFrame);
    }
}

12、TurretRed类

package sxt;
//蓝方防御塔
public class TurretRed extends Turret{
    //有参构造
    public TurretRed(GameFrame gameFrame){
        super(gameFrame);
    }
    public TurretRed(int x,int y,GameFrame gameFrame){
        super(x,y,gameFrame);
    }
}

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

C++学习之路(四)C++ 实现简单的待办事项列表命令行应用 - 示例代码拆分讲解

本期示例介绍: 本期示例《待办事项列表应用》展示了一个简单的任务管理系统&#xff0c;用户可以通过命令行界面执行添加任务、删除任务和显示任务列表等操作。 功能描述&#xff1a; 添加任务功能&#xff1a; 用户可以输入任务描述&#xff0c;将新的任务添加到任务列表中。…

设计模式—依赖倒置原则(DIP)

1.概念 依赖倒置原则&#xff08;Dependence Inversion Principle&#xff09;是程序要依赖于抽象接口&#xff0c;不要依赖于具体实现。简单的说就是要求对抽象进行编程&#xff0c;不要对实现进行编程&#xff0c;这样就降低了客户与实现模块间的耦合。 通俗的讲&#xff1…

【教学类-06-13】20231126 (55格版)趣味题(一)1-9加法题(10倍)(整十相加)

作品展示 背景需求&#xff1a; 1、会做加法题的孩子5分钟内完成题目&#xff0c;太快了&#xff0c;所以为了拉平差异&#xff0c;需要给这些会做另外的题目&#xff0c;比如提供一些他们没有做过的“趣味题形”。 2、好多次&#xff0c;听见大班孩子在互相“考试”——“老…

04_MySQL备份与恢复

任务背景 一、真实案例 某天&#xff0c;公司领导安排刚入职不久的小冯同学将生产环境中的数据(MySQL数据库)全部导入到测试环境给测试人员使用。当小冯去拿备份数据时发现&#xff0c;备份数据是1个礼拜之前的。原因是之前运维同事通过脚本每天对数据库进行备份&#xff0c;…

2023年程序设计迎新赛(第二届个人程序设计大赛)

7-1 找规律 请从所给的四个选项中&#xff0c;选择最合适的一个填入问号处&#xff0c;使之呈现一定的规律性。 输入格式: 无 输出格式: 大写字母 输入样例: 输出样例: #include<stdio.h> int main(){printf("D");return 0; }7-2 蜡烛燃烧时间 有粗细不同…

【MySQL】JDBC编程

&#x1f451;专栏内容&#xff1a;MySQL⛪个人主页&#xff1a;子夜的星的主页&#x1f495;座右铭&#xff1a;前路未远&#xff0c;步履不停 目录 一、JDBC工作原理二、JDBC 使用1、准备工作2、使用实例3、手动输入 一、JDBC工作原理 JDBC是Java语言中用于与数据库进行交互…

Vscode工具使用指南

通用 快捷键文件 / 编辑查找 / 替换窗口插件主题 连接linux 快捷键 文件 / 编辑 新建文件&#xff1a;CtrlN放大或缩小&#xff1a;Ctrl /-代码行缩进&#xff0c;展开&#xff1a;Ctrl[ 和 Ctrl]在当前行下方插入一行&#xff1a;CtrlEnter在当前行上方插入一行&#xff1a;…

【方块消消乐】方块消除游戏-微信小程序开发流程详解

有做过俄罗斯方块游戏小程序的经验&#xff0c;这次有做了一个消灭方块的游戏&#xff0c;实现过程很顺利&#xff0c;游戏看着和之前做的俄罗斯方块游戏很像&#xff0c;这里调整了玩法&#xff0c;试玩感觉还可以&#xff0c;接下来给大家讲一讲消灭方块游戏开发过程。 俄罗斯…

Unity2D-URP基于ShaderGraph创建带粒子特效的激光光束

文章目录 创建Shader新建Node: UV新建Node: Split......参数说明 基于Shader创建Material创建Line创建粒子系统StartVFX创建粒子材质更改粒子系统的材质设置透明模式设置粒子效果创建一个Beam设置EndVFX效果预览激光光束管理脚本最终预览 创建Shader Create --> Shader Gra…

Redis面试题:Redis的数据淘汰策略有哪些?

目录 面试官&#xff1a;Redis的数据淘汰策略有哪些 ? 面试官&#xff1a;数据库有1000万数据 ,Redis只能缓存20w数据, 如何保证Redis中的数据都是热点数据 ? 面试官&#xff1a;Redis的内存用完了会发生什么&#xff1f; 面试官&#xff1a;Redis的数据淘汰策略有哪些 ? …

掌握文件夹重命名技巧:字母大小写批量转换的实用操作

在这个数字化时代&#xff0c;经常要与各种文件和文件夹打交道。有时候&#xff0c;为了提高工作效率或整理文件&#xff0c;要对文件夹名称进行修改。其中&#xff0c;字母大小写的转换是一个常见的需求。例如&#xff0c;将所有文件夹名称中的大写字母转换为小写字母&#xf…

【Linux系统编程】冯 • 诺依曼体系结构(什么是冯 • 诺依曼体系结构?冯 • 诺依曼体系结构如何应用?)

目录 一、前言 二、什么是冯 • 诺依曼体系结构&#xff1f; &#x1f4a6; 冯 • 诺依曼体系结构的发展推导 &#x1f4a6;冯 • 诺依曼体系结构的5大部件 ⭐输入和输出设备 ⭐存储器 ⭐中央处理器&#xff08;CPU&#xff09; &#x1f4a6;冯 • 诺依曼体系结构的细节…

《数据结构、算法与应用C++语言描述》-二叉树与其他树-二叉树的C++实现-设置信号放大器与并查集问题

二叉树和其他树 可编译运行程序见&#xff1a;Github::Jasmine-up/Data-Structures-Algorithms-and-Applications/_23BinaryTree 定义 树 定义 11-1 一棵树 t是一个非空的有限元素的集合&#xff0c;其中一个元素为根&#xff08;root&#xff09;&#xff0c;其余的元素&a…

Python 测试框架 Pytest 的入门

简介 pytest 是一个功能强大而易于使用的 Python 测试框架。它提供了简单的语法和灵活的功能&#xff0c;用于编写和组织测试代码。 1、简单易用&#xff1a;pytest 的语法简洁明了&#xff0c;使得编写测试用例更加直观和易于理解。它使用 assert 语句来验证预期结果&#x…

Java进阶(第二期):package 包 抽象类和抽象方法 接口的实现 多态的实现 综合继承、接口、多态的使用。

2023年11月26日20:11:11 文章目录 Java进阶&#xff08;第二期&#xff09;一、package包的概念二、抽象类和抽象方法(abstract)2.1 使用2.1 抽象类注意事项 三、接口3.1 接口的定义格式3.2 接口成员特点3.3 类和接口的关系3.4 接口和抽象类的对比 四、多态4.1 多态的前提条件4…

4G模块(EC600N)通过MQTT连接华为云

目录 一、前言 二、EC600N模块使用 1&#xff0e;透传模式 2&#xff0e;非透传模式 3、华为云的MQTT使用教程&#xff1a; 三、具体连接步骤 1、初始化检测 2、打开MQTT客户端网络 3、创建产品 4、创建模型 5、注册设备 6、连接客户端到MQTT服务器 7、发布主题消…

2023-11-26 事业-代号s-跨境物流-记录

摘要: 2023-11-26 事业-代号s-跨境物流-记录 跨境物流: 【结论】 中小卖家&#xff08;最低适合1个人经营的卖家&#xff09;首选以下两种物流&#xff0c;目前已知的是以下两种&#xff0c;后续有新的发现再更新。 1、云途物流&#xff08;YunExpress&#xff09;&#xff…

2016年五一杯数学建模A题购房中的数学问题解题全过程文档及程序(采光与房款)

2016年五一杯数学建模 A题 购房中的数学问题 原题再现 随着现代社会经济的快速发展&#xff0c;房地产成为国家经济发展中重要的经济增长点之一。为了充分利用楼房建设的土地面积&#xff0c;开发商经常会选择建筑高层住宅。在购买住房时&#xff0c;影响消费者选择购房的因素…

企业文档文件管理软件推荐:提升管理效率与数据安全性

Zoho WorkDrive企业网盘是一种高效的文件管理工具&#xff0c;它不仅可以为组织搭建统一、高效、安全、智能的内容管理体系&#xff0c;还能够提供大规模支撑、海量数据处理、非结构化数据治理、智能挖掘与洞察等服务能力。通过这些服务&#xff0c;企业可以更好地管理和利用其…