王者荣耀Java

代码

package com.sxt;import javax.swing.*;
import java.awt.*;public class Background extends GameObject {public Background(GameFrame gameFrame) {super(gameFrame);// TODO Auto-generated constructor stub}Image bg = Toolkit.getDefaultToolkit().getImage("img/Map.jpg");public void paintSelf(Graphics g){g.drawImage(bg,0,0,null);}@Overridepublic Rectangle getRec() {// TODO Auto-generated method stubreturn null;}
}
package com.sxt;import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;import com.sxt.beast.Beast;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);// TODO Auto-generated constructor stub}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);// TODO Auto-generated constructor stub}public Bullet() {super();// TODO Auto-generated constructor stub}public void move() {// 子弹与目标碰撞,子弹消失,目标减血if (recIntersectsRec(getRec(), target.getRec())) {if (Beast.class.isAssignableFrom(target.getClass())) {target.setTarget(gameFrame.player);target.setHasTarget(true);}target.setCurrentHp(target.getCurrentHp() - getAd());gameFrame.removeList.add(this);}double dis = getDis(getX(), getY(), target.getX(), target.getY());int xSpeed = (int) (getSpd() * (target.getX() - getX()) / dis);int ySpeed = (int) (getSpd() * (target.getY() - getY()) / dis);setX(getX() + xSpeed);setY(getY() + ySpeed);}@Overridepublic void paintSelf(Graphics g) {// TODO Auto-generated method stubg.drawImage(getImg(), getX() - 16, getY() - 16, null);if (this.getImg() == null) {g.setColor(Color.BLACK);g.fillOval(getX() - 5, getY() - 5, 10, 10);g.drawRect(getX() - 5, getY() - 5, 10, 10);}move();}@Overridepublic Rectangle getRec() {// TODO Auto-generated method stubreturn new Rectangle(getX() - 5, getY() - 5, 10, 10);}/*** @return the ad*/public int getAd() {return ad;}/*** @param ad the ad to set*/public void setAd(int ad) {this.ad = ad;}}
package com.sxt;import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.ArrayList;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;//英雄头像Image classical;//技能冷却时间int coolDownTimeOne;int coolDownTimeTwo;int coolDownTimeThree;//三个技能是否处于冷却状态boolean coolDownOne = true;boolean coolDownTwo = true;boolean coolDownThree = true;//英雄列表ArrayList<Champion> championList = new ArrayList<Champion>();static {for (int i = 1; i < 8; i++) {imgs[i] = "img/" + i + ".png";}}public Champion(GameFrame gameFrame, int x, int y) {super(gameFrame);setImg("img/stand.png");setX(x);setY(y);setSpd(75);setHp(24000);setDis(250);setAttackCoolDownTime(100);setCurrentHp(getHp());championList.add(new ChampionDaji(gameFrame));championList.add(new ChampionHouyi(gameFrame));}public Champion(GameFrame gameFrame) {// TODO Auto-generated constructor stubsuper(gameFrame);setImg("img/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("img/stand.png");}}/*** 添加三个技能按钮* */public void addButton() {JButton button1 = new JButton();button1.setSize(100, 100);button1.setLocation(1056, 513);button1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {abilityOne();}});JButton button2 = new JButton();button2.setSize(100, 100);button2.setLocation(1090, 370);button2.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {abilityTwo();}});JButton button3 = new JButton();button3.setSize(100, 100);button3.setLocation(1220, 300);button3.addActionListener(new ActionListener() {@Overridepublic 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);@Overridepublic void paintSelf(Graphics g) {// TODO Auto-generated method stub// 生命值为0if (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);}}@Overridepublic Rectangle getRec() {// TODO Auto-generated method stubreturn new Rectangle(getX() - 30, getY() - 60, 60, 120);}}
package com.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;import com.sxt.beast.Beast;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("img/abilityOne.jpg");abilityTwo = Toolkit.getDefaultToolkit().getImage("img/abilityTwo.jpg");abilityThree = Toolkit.getDefaultToolkit().getImage("img/abilityThree.jpg");classical = Toolkit.getDefaultToolkit().getImage("img/Classical.jpg");// 三个技能冷却时间coolDownTimeOne = 6000;coolDownTimeTwo = 8000;coolDownTimeThree = 8000;}public void exit() {this.gameFrame.removeMouseListener(m);}public void abilityOneMove() {p.translate((int) (50 * cos), -(int) (50 * sin));for (GameObject redObj : gameFrame.objList) {// 是红色方小兵 && 发生碰撞 && 没在attacked列表里if (redObj instanceof MinionRed && p.intersects(redObj.getRec()) && attacked.indexOf(redObj) == -1) {// 小兵扣血,添加到attacked里redObj.setCurrentHp(redObj.getCurrentHp() - 400);attacked.add(redObj);}else if (Beast.class.isAssignableFrom(redObj.getClass()) && p.intersects(redObj.getRec()) && attacked.indexOf(redObj) == -1) {redObj.setCurrentHp(redObj.getCurrentHp() - 400);attacked.add(redObj);}}}@Overridepublic void abilityOne() {// TODO Auto-generated method stubif (coolDownOne) {m = new MouseMonitor();p = new Polygon();gameFrame.addMouseListener(m);attacked = new ArrayList<GameObject>();}}@Overridepublic void abilityTwo() {// TODO Auto-generated method stubif (coolDownTwo) {boolean find = false;for (GameObject redObj : gameFrame.objList) {// 是红色小兵 && 距离小于250 && 存活if ((redObj instanceof MinionRed || Beast.class.isAssignableFrom(redObj.getClass())) && recIntersectsCir(redObj.getRec(), getX(), getY(), 250)&& redObj.isAlive()) {// 添加子弹abilityTwoBullet = new Bullet(gameFrame, this, redObj, 250, 60, "img/abilityTwoBullet.png");gameFrame.objList.add(abilityTwoBullet);// 给目标赋值abilityTwoTarget = redObj;// 释放二技能ifAbilityTwo = true;find = true;break;}}if (find) {new AbilityTwoCD().start();find = false;}}}/*** 点击技能三释放技能 先将技能范围内目标储存到targetList里 提前定义五个子弹 技能释放时初始化五个子弹 子弹目标从targetList里随机选择* 如果期间目标死亡,制作一个目标替身,生命值设置为true 子弹与目标或替身碰撞后消失*/@Overridepublic void abilityThree() {// TODO Auto-generated method stub// 三技能没在冷却状态if (coolDownThree) {// 创建列表来储存目标ArrayList<GameObject> targetList = new ArrayList<GameObject>();// 遍历redListfor (int i = 0; i < gameFrame.objList.size(); i++) {GameObject target = gameFrame.objList.get(i);// 是红色小兵 && 在技能范围里 && 存活if ((target instanceof MinionRed || Beast.class.isAssignableFrom(target.getClass())) && 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, 250, 60, "img/abilityTwoBullet.png");}else {bulletList[count] = new Bullet(gameFrame, this, targetList.get(r), 250, 60, "img/abilityTwoBullet.png");}count++;}new AbilityThreeBulletCD().start();new AbilityThreeCD().start();}}}@Overridepublic void abilityEffect(Graphics g) {// TODO Auto-generated method stubif (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.stop();}}// 技能二冷却时间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.stop();}}// 技能二控制时间class AbilityControllCD extends Thread {public void run() {abilityTwoTarget.beControlled = true;// 线程休眠try {Thread.sleep(20000);} catch (Exception e) {e.printStackTrace();}abilityTwoTarget.beControlled = false;this.stop();}}// 技能三冷却时间class AbilityThreeCD extends Thread {public void run() {// 将技能三设置为冷却状态coolDownThree = false;// 线程休眠try {// three来表示三技能冷却时间int three = coolDownTimeThree;while (three > 0) {Thread.sleep(1000);System.out.println("三技能冷却时间: " + three / 1000);three -= 1000;}} catch (Exception e) {e.printStackTrace();}// 将技能三设置为攻击状态coolDownThree = true;// 线程终止this.stop();}}//技能三子弹时间间隔class AbilityThreeBulletCD extends Thread{public void run() {try {gameFrame.objList.add(bulletList[0]);Thread.sleep(200);gameFrame.objList.add(bulletList[1]);Thread.sleep(200);gameFrame.objList.add(bulletList[2]);Thread.sleep(200);gameFrame.objList.add(bulletList[3]);Thread.sleep(200);gameFrame.objList.add(bulletList[4]);}catch(Exception e) {e.printStackTrace();}this.stop();}}// 鼠标监视器private class MouseMonitor extends MouseAdapter {@Overridepublic 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;}}
}
package com.sxt;import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;import javax.swing.JButton;
import javax.swing.JFrame;import com.sxt.beast.Beast;public class GameFrame extends JFrame {// 游戏模式 0 选择英雄,1 游戏开始,2 游戏胜利,3 游戏失败int state = 0;// 窗口尺寸private int windowWidth = 1400;private int windowHeight = 700;// 双缓冲图片private Image offScreenImage = null;// 攻击图片private Image attack = Toolkit.getDefaultToolkit().getImage("img/attack.jpg");//游戏胜利失败图片private Image gameWin = Toolkit.getDefaultToolkit().getImage("img/gameWin.png");private Image gameLose = Toolkit.getDefaultToolkit().getImage("img/gameLose.png");// 游戏背景Background background = new Background(this);// 游戏玩家Champion player;Champion champion = new ChampionHouyi(this,700,3800);// 双方小兵MinionBlue mb = new MinionBlue(this);MinionRed mr = new MinionRed(this);// 防御塔Turret turret = new Turret(this);//野怪public Beast beast = new Beast(this);// 攻击按钮JButton attackButton;// 游戏元素列表public ArrayList<GameObject> objList = new ArrayList<GameObject>();ArrayList<GameObject> redList = new ArrayList<GameObject>();// 红色方ArrayList<GameObject> blueList = new ArrayList<GameObject>();// 蓝色方public ArrayList<GameObject> removeList = new ArrayList<GameObject>();// 存放将要删除的元素public void launch() {// 设置尺寸setSize(windowWidth, windowHeight);// 窗口居中setLocationRelativeTo(null);// 关闭事件setDefaultCloseOperation(3);// 用户不能调整窗口大小setResizable(false);// 标题setTitle("王者荣耀");// 窗口可见setVisible(true);// 添加键盘监视器this.addKeyListener(new GameFrame.KeyMonitor());// 添加游戏元素objList.add(background);objList.addAll(turret.turretList);objList.addAll(beast.beastList);blueList.add(turret.turretList.get(0));redList.add(turret.turretList.get(4));/*** 攻击按钮*/attackButton = new JButton();attackButton.setSize(130, 132);attackButton.setLocation(1150, 430);attackButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// 按钮事件player.attack(redList);}});this.add(attackButton);while (true) {if (state == 1) {// 添加小兵//mb.createMinion(this, blueList);//mr.createMinion(this, redList);// 添加防御塔turret.addTurret();}repaint();try {Thread.sleep(17);} 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) {for(int i = 0; i < champion.championList.size(); i++) {//添加图片Image classical = champion.championList.get(i).classical;gImage.drawImage(classical, i*160, 20, null);//添加按钮JButton championButton = new JButton();championButton.setSize(150, 150);championButton.setLocation(i*150, 0);int a = i;championButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {state = 1;player = champion.championList.get(a);objList.add(player);player.addButton();}});this.add(championButton);}} else if (state == 1) {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 == 2) {//游戏胜利gImage.drawImage(gameWin, 0, 5, null);} else if (state == 3) {//游戏失败gImage.drawImage(gameLose, 0, 5, null);}if (state != 1) {g.drawImage(offScreenImage, 0, 0, null);} else {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 {@Overridepublic void keyPressed(KeyEvent e) {int key = e.getKeyCode();player.keyPressed(e);}@Overridepublic void keyReleased(KeyEvent e) {int key = e.getKeyCode();player.keyReleased(e);}}
}
package com.sxt;import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.ArrayList;import com.sxt.beast.Beast;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() {// TODO Auto-generated constructor stub}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, "img/bullet.gif");}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;}}}}}class AttackCD extends Thread {public void run() {// 将攻击功能设置为冷却状态setAttackCoolDown(false);// 线程休眠try {Thread.sleep(attackCoolDownTime);} catch (Exception e) {e.printStackTrace();}// 将攻击功能设置为攻击状态setAttackCoolDown(true);// 线程终止this.stop();}}// 绘制元素public abstract void paintSelf(Graphics g);// 返回矩形public abstract Rectangle getRec();/*** @return the x*/public int getX() {return x;}/*** @param x the x to set*/public void setX(int x) {this.x = x;}/*** @return the y*/public int getY() {return y;}/*** @param y the y to set*/public void setY(int y) {this.y = y;}/*** @return the img*/public Image getImg() {return img;}/*** @param img the img to set*/public void setImg(String img) {this.img = Toolkit.getDefaultToolkit().getImage(img);}/*** @return the spd*/public int getSpd() {return spd;}/*** @param spd the spd to set*/public void setSpd(int spd) {this.spd = spd;}/*** @return the hp*/public int getHp() {return hp;}/*** @param hp the hp to set*/public void setHp(int hp) {this.hp = hp;}/*** @return the currentHp*/public int getCurrentHp() {return currentHp;}/*** @param currentHp the currentHp to set*/public void setCurrentHp(int currentHp) {if (currentHp < getHp()) {if (Beast.class.isAssignableFrom(getClass())) {System.out.println("yes");setTarget(gameFrame.player);setHasTarget(true);}}this.currentHp = currentHp;}/*** @return the target*/public GameObject getTarget() {return target;}/*** @param target the target to set*/public void setTarget(GameObject target) {this.target = target;}/*** @return the hasTarget*/public boolean isHasTarget() {return hasTarget;}/*** @param hasTarget the hasTarget to set*/public void setHasTarget(boolean hasTarget) {this.hasTarget = hasTarget;}/*** @return the dis*/public int getDis() {return dis;}/*** @param dis the dis to set*/public void setDis(int dis) {this.dis = dis;}/*** @return the attackCoolDownTime*/public int getAttackCoolDownTime() {return attackCoolDownTime;}/*** @param attackCoolDownTime the attackCoolDownTime to set*/public void setAttackCoolDownTime(int attackCoolDownTime) {this.attackCoolDownTime = attackCoolDownTime;}/*** @return the attackCoolDown*/public boolean isAttackCoolDown() {return attackCoolDown;}/*** @param attackCoolDown the attackCoolDown to set*/public void setAttackCoolDown(boolean attackCoolDown) {this.attackCoolDown = attackCoolDown;}/*** @return the alive*/public boolean isAlive() {return alive;}/*** @param alive the alive to set*/public void setAlive(boolean alive) {this.alive = alive;}
}
package com.sxt;import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
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);// TODO Auto-generated constructor stub}/*** (1325, 3750) (4425, 3750) (5050, 3125) (5050, 1125)*/public abstract void move(ArrayList<GameObject> objList);/*** @param x:       下一步的横坐标* @param y:       下一步的纵坐标* @param objList: 小兵列表* @return 下一步位置与其他小兵是否碰撞*/public boolean hitMinion(int x, int y, ArrayList<GameObject> objList) {// 新的区域生成矩形Rectangle r = new Rectangle(x - 16, y - 16, 45, 45);for (GameObject obj : objList) {// 相同类 && 不是自身if (obj.getClass() == this.getClass() && obj != this) {if (r.intersects(obj.getRec())) {return true;}}}return false;}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() {double dis = getDis(getX(), getY(), getTarget().getX(), getTarget().getY());int xSpeed = (int) (getSpd() * (getTarget().getX() - getX()) / dis);int ySpeed = (int) (getSpd() * (getTarget().getY() - getY()) / dis);if (!hitMinion(getX() + xSpeed, getY(), gameFrame.objList)) {setX(getX() + xSpeed);}if (!hitMinion(getX(), getY() + ySpeed, gameFrame.objList)) {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.5stry {Thread.sleep(1500);} catch (Exception e) {e.printStackTrace();}nextMinion = true;// 线程终止this.stop();}}// 每波小兵生成时间class NextLine extends Thread {public void run() {nextLine = false;// 休眠15stry {Thread.sleep(15000);} catch (Exception e) {e.printStackTrace();}nextLine = true;// 线程终止this.stop();}}@Overridepublic void paintSelf(Graphics g) {// TODO Auto-generated method stub// 生命值为0if (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);// 小兵移动if (!beControlled) {if (this instanceof MinionBlue) {move(gameFrame.redList);} else {move(gameFrame.blueList);}}}}@Overridepublic Rectangle getRec() {// TODO Auto-generated method stubreturn new Rectangle(getX() - 16, getY() - 16, 45, 45);}/*** @return the ifFindTarget*/public boolean isIfFindTarget() {return ifFindTarget;}/*** @param ifFindTarget the ifFindTarget to set*/public void setIfFindTarget(boolean ifFindTarget) {this.ifFindTarget = ifFindTarget;}}
package com.sxt;import java.util.ArrayList;public class MinionBlue extends Minion {public MinionBlue(GameFrame gameFrame) {super(gameFrame);setImg("img/blue.jpg");setX(1325);setY(3750);// TODO Auto-generated constructor stub}@Overridepublic void move(ArrayList<GameObject> objList) {// TODO Auto-generated method stubif (isIfFindTarget()) {// 离开检测范围if (!recIntersectsCir(getTarget().getRec(), getX(), getY(), 200)) {setIfFindTarget(false);} else {if (!isHasTarget()) {moveToTarget();}attack(objList);}} else {findTarget(objList);// 原路线移动if (getX() < 4425) {setSpd(25);if (!hitMinion(getX() + getSpd(), getY(), gameFrame.blueList)) {setX(getX() + getSpd());}} else if (getX() < 5100 && getX() >= 4425) {setSpd(20);if (!hitMinion(getX() + getSpd(), getY(), gameFrame.blueList)) {setX(getX() + getSpd());}if (!hitMinion(getX(), getY() - getSpd(), gameFrame.blueList)) {setY(getY() - getSpd());}} else if (getX() >= 4900) {setSpd(18);if (!hitMinion(getX(), getY() - getSpd(), gameFrame.blueList)) {setY(getY() - getSpd());}}}}
}
package com.sxt;import java.util.ArrayList;public class MinionRed extends Minion {public MinionRed(GameFrame gameFrame) {super(gameFrame);setImg("img/red.jpg");setX(5050);setY(1125);// TODO Auto-generated constructor stub}@Overridepublic void move(ArrayList<GameObject> objList) {// TODO Auto-generated method stubif (isIfFindTarget()) {// 离开检测范围if (!recIntersectsCir(getTarget().getRec(), getX(), getY(), 200)) {setIfFindTarget(false);} else {if (!isHasTarget()) {moveToTarget();}attack(objList);}} else {findTarget(objList);// 原路线移动if (getY() < 3125) {setSpd(18);if (!hitMinion(getX(), getY() + getSpd(), gameFrame.redList)) {setY(getY() + getSpd());}} else if (getY() < 3750 && getY() >= 3125) {setSpd(20);if (!hitMinion(getX(), getY() + getSpd(), gameFrame.redList)) {setY(getY() + getSpd());}if (!hitMinion(getX() - getSpd(), getY(), gameFrame.redList)) {setX(getX() - getSpd());}} else if (getY() >= 3750) {setSpd(25);if (!hitMinion(getX() - getSpd(), getY(), gameFrame.redList)) {setX(getX() - getSpd());}}}}}
package com.sxt;import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.ArrayList;public class Turret extends GameObject {ArrayList<Turret> turretList = new ArrayList<Turret>();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("img/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));// TODO Auto-generated constructor stub}public Turret(int x, int y, GameFrame gameFrame) {super(x, y, gameFrame);setImg("img/turret.png");setHp(6000);setCurrentHp(getHp());setAttackCoolDownTime(1000);setDis(300);}public void addTurret() {/*** 添加到objList里会被绘制出来,添加到redList和blueList才会被攻击 前一个防御塔爆炸后再把后一个添加到列表里*/if (!gameFrame.turret.turretBlueOne.isAlive() && gameFrame.turret.turretBlueTwo.isAlive()&& gameFrame.blueList.indexOf(gameFrame.turret.turretBlueTwo) == -1) {gameFrame.blueList.add(gameFrame.turret.turretBlueTwo);}if (!gameFrame.turret.turretBlueTwo.isAlive() && gameFrame.turret.turretBlueThree.isAlive()&& gameFrame.blueList.indexOf(gameFrame.turret.turretBlueThree) == -1) {gameFrame.blueList.add(gameFrame.turret.turretBlueThree);}if (!gameFrame.turret.turretBlueThree.isAlive() && gameFrame.turret.turretBlueBase.isAlive()&& gameFrame.blueList.indexOf(gameFrame.turret.turretBlueBase) == -1) {gameFrame.blueList.add(gameFrame.turret.turretBlueBase);}if (!gameFrame.turret.turretBlueBase.isAlive()) {//游戏失败gameFrame.state = 3;}if (!gameFrame.turret.turretRedOne.isAlive() && gameFrame.turret.turretRedTwo.isAlive()&& gameFrame.redList.indexOf(gameFrame.turret.turretRedTwo) == -1) {gameFrame.redList.add(gameFrame.turret.turretRedTwo);}if (!gameFrame.turret.turretRedTwo.isAlive() && gameFrame.turret.turretRedThree.isAlive()&& gameFrame.redList.indexOf(gameFrame.turret.turretRedThree) == -1) {gameFrame.redList.add(gameFrame.turret.turretRedThree);}if (!gameFrame.turret.turretRedThree.isAlive() && gameFrame.turret.turretRedBase.isAlive()&& gameFrame.redList.indexOf(gameFrame.turret.turretRedBase) == -1) {gameFrame.redList.add(gameFrame.turret.turretRedBase);}if (!gameFrame.turret.turretRedBase.isAlive()) {//游戏胜利gameFrame.state = 2;}}@Overridepublic void paintSelf(Graphics g) {// 生命值为0if (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.drawOval(getX() - 300, getY() - 300, 600, 600);}}@Overridepublic Rectangle getRec() {// TODO Auto-generated method stubreturn new Rectangle(getX() - 50, getY() - 100, 100, 180);}}
package com.sxt;public class TurretBlue extends Turret {public TurretBlue(GameFrame gameFrame) {super(gameFrame);// TODO Auto-generated constructor stub}public TurretBlue(int x, int y, GameFrame gameFrame) {super(x, y, gameFrame);}}
package com.sxt;public class TurretRed extends Turret {public TurretRed(GameFrame gameFrame) {super(gameFrame);// TODO Auto-generated constructor stub}public TurretRed(int x, int y, GameFrame gameFrame) {super(x, y, gameFrame);}}
package com.sxt.beast;import com.sxt.GameFrame;public class Bear extends Beast {public Bear(int x, int y, GameFrame gameFrame) {super(x, y, gameFrame);setImg("img/bear.jpg");width = 85;height = 112;setDis(65);// TODO Auto-generated constructor stub}}
package com.sxt.beast;import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.ArrayList;import com.sxt.*;public class Beast extends GameObject {public ArrayList<Beast> beastList = new ArrayList<Beast>();int width;int height;// 初始坐标int initialX;int initialY;// 有没有仇恨值public boolean isAggressive = false;// 复活的元素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());setSpd(10);setAttackCoolDownTime(2000);initialX = getX();initialY = getY();beast = this;}public void moveToTarget() {double dis = getDis(getX(), getY(), getTarget().getX(), getTarget().getY());if (dis > 500) {isAggressive = false;setHasTarget(false);} else {int xSpeed = (int) (getSpd() * (getTarget().getX() - getX()) / dis);int ySpeed = (int) (getSpd() * (getTarget().getY() - getY()) / dis);setX(getX() + xSpeed);setY(getY() + ySpeed);}}public void moveToInitialLocation() {double dis = getDis(getX(), getY(), initialX, initialY);if (dis < getSpd()) {setX(initialX);setY(initialY);isAggressive = true;} else {int xSpeed = (int) (getSpd() * (initialX - getX()) / dis);int ySpeed = (int) (getSpd() * (initialY - getY()) / dis);setX(getX() + xSpeed);setY(getY() + ySpeed);}}/**判断有没有目标及野怪的仇恨值(又没有攻击性)true,判断是否到攻击范围false,向目标移动,若中途离开出生点距离大于300或与目标距离大于400,则不再有攻击性。true,发射子弹,线程开始false,没有目标,回到出生地,自动回血,再次有攻击性*/public void move() {if (isHasTarget() && isAggressive) {if (!recIntersectsCir(getTarget().getRec(), getX(), getY(), getDis())) {moveToTarget();} else if (isAttackCoolDown() && isAlive()) {Bullet bullet = new Bullet(gameFrame, this, getTarget(), 500, 50, "img/bullet.gif");gameFrame.objList.add(bullet);new AttackCD().start();}} else {moveToInitialLocation();if (getCurrentHp() < getHp()) {setCurrentHp(getCurrentHp() + 100);}}}@Overridepublic void paintSelf(Graphics g) {// TODO Auto-generated method stub// 生命值为0if (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());move();}}@Overridepublic Rectangle getRec() {// TODO Auto-generated method stubreturn new Rectangle(getX() - width / 2, getY() - height / 2, width, height);}class AttackCD extends Thread {public void run() {// 将攻击功能设置为冷却状态setAttackCoolDown(false);// 线程休眠try {Thread.sleep(getAttackCoolDownTime());} catch (Exception e) {e.printStackTrace();}// 将攻击功能设置为攻击状态setAttackCoolDown(true);// 线程终止this.stop();}}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);}}}
package com.sxt.beast;import com.sxt.GameFrame;public class Bird extends Beast {public Bird(int x, int y, GameFrame gameFrame) {super(x, y, gameFrame);setImg("img/红隼.jpg");width = 122;height = 98;setDis(125);// TODO Auto-generated constructor stub}}
package com.sxt.beast;import com.sxt.GameFrame;public class BlueBuff extends Beast {public BlueBuff(int x, int y, GameFrame gameFrame) {super(x, y, gameFrame);setImg("img/blueBuff.jpg");width = 142;height = 176;setDis(70);// TODO Auto-generated constructor stub}}
package com.sxt.beast;import com.sxt.GameFrame;public class RedBuff extends Beast {public RedBuff(int x, int y, GameFrame gameFrame) {super(x, y, gameFrame);setImg("img/redBuff.jpg");width = 103;height = 150;setDis(70);// TODO Auto-generated constructor stub}
}
package com.sxt.beast;import com.sxt.GameFrame;public class Wolf extends Beast {public Wolf(int x, int y, GameFrame gameFrame) {super(x, y, gameFrame);setImg("img/wolf.jpg");width = 145;height = 140;setDis(65);// TODO Auto-generated constructor stub}}
package com.sxt.beast;import com.sxt.GameFrame;public class Xiyi extends Beast {public Xiyi(int x, int y, GameFrame gameFrame) {super(x, y, gameFrame);setImg("img/蜥蜴.jpg");width = 111;height = 65;setDis(125);// TODO Auto-generated constructor stub}
}

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

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

相关文章

notion 3.0.0 版本最新桌面端汉化教程,支持MAC和WIN版本

notion客户端汉化&#xff08;目前版本3.0.0&#xff09; 最近notion桌面端更新了3.0.0版本后会导致老版本汉化失效&#xff0c;本项目实现了最新版Notion桌面端的汉化。 文件下载地址&#xff1a;汉化文件下载地址 项目说明 本项目针对新的客户端做了汉化文化&#xff0c;依…

超实用!Spring Boot 常用注解详解与应用场景

目录 一、Web MVC 开发时&#xff0c;对于三层的类注解 1.1 Controller 1.2 Service 1.3 Repository 1.4 Component 二、依赖注入的注解 2.1 Autowired 2.2 Resource 2.3 Resource 与 Autowired 的区别 2.3.1 实例讲解 2.4 Value 2.5 Data 三、Web 常用的注解 3.1…

可以在Playgrounds或Xcode Command Line Tool开始学习Swift

一、用Playgrounds 1. App Store搜索并安装Swift Playgrounds 2. 打开Playgrounds&#xff0c;点击 文件-新建图书。然后就可以编程了&#xff0c;如下&#xff1a; 二、用Xcode 1. 安装Xcode 2. 打开Xcode&#xff0c;选择Creat New Project 3. 选择macOS 4. 选择Comman…

3.前端--HTML标签-文本图像链接【2023.11.25】

1.HTML常用标签(文本图像链接&#xff09; 文本标签 标题 <h1> - <h6> 段落<p> 我是一个段落标签 </p> 换行 <br /> <!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"UTF-8"><meta ht…

VMWare虚拟机ubuntu克隆打不开

ubuntu克隆打不开 复制的存有ubuntu克隆的文件夹&#xff0c;导入vmware打不开 说找不到这个文件&#xff0c;那就到目录把它的删掉 的删掉 换000001.vmdk后缀的

电子学会C/C++编程等级考试2021年06月(三级)真题解析

C/C++等级考试(1~8级)全部真题・点这里 第1题:数对 给定2到15个不同的正整数,你的任务是计算这些数里面有多少个数对满足:数对中一个数是另一个数的两倍。 比如给定1 4 3 2 9 7 18 22,得到的答案是3,因为2是1的两倍,4是2个两倍,18是9的两倍。 时间限制:1000 内存限制…

使用Selenium、Python和图鉴打码平台实现B站登录

selenium实战之模拟登录b站 基础知识铺垫&#xff1a; 利用selenium进行截图&#xff1a; driver.save_screenshot() 注意图片文件名要用png结尾. 关于移动&#xff1a; ActionChains(bro).move_to_element_with_offset()# 对于某个图像ActionChains(bro).move_by_offset(…

一种LED驱动专用控制电路

一、基本概述 TM1620是一种LED&#xff08;发光二极管显示器&#xff09;驱动控制专用IC,内部集成有MCU数字接口、数据锁存 器、LED驱动等电路。本产品质量可靠、稳定性好、抗干扰能力强。主要适用于家电设备(智能热 水器、微波炉、洗衣机、空调、电磁炉)、机顶盒、电子称、…

033.Python面向对象_类补充_生命周期

我 的 个 人 主 页&#xff1a;&#x1f449;&#x1f449; 失心疯的个人主页 &#x1f448;&#x1f448; 入 门 教 程 推 荐 &#xff1a;&#x1f449;&#x1f449; Python零基础入门教程合集 &#x1f448;&#x1f448; 虚 拟 环 境 搭 建 &#xff1a;&#x1f449;&…

[NOIP2006]明明的随机数

一、题目 登录—专业IT笔试面试备考平台_牛客网 二、代码 set去重&#xff0c;再利用vector进行排序 std::set是一个自带排序功能的容器&#xff0c;它已经按照一定的规则&#xff08;默认是元素的小于比较&#xff09;对元素进行了排序。因此&#xff0c;你不能直接对std::s…

【JAVA杂货铺】一文带你走进面向对象编程|继承|重载|重写|期末复习系列 | (中4)

&#x1f308;个人主页: Aileen_0v0&#x1f525;系列专栏:Java学习系列专栏&#x1f4ab;个人格言:"没有罗马,那就自己创造罗马~" 目录 继承 私有成员变量在继承中的使用​编辑 当子类和父类变量不重名时: 当子类和父类重名时: &#x1f4dd;总结: 继承的含义: …

卷积神经网络经典backbone

特征提取是数据分析和机器学习中的基本概念&#xff0c;是将原始数据转换为更适合分析或建模的格式过程中的关键步骤。特征&#xff0c;也称为变量或属性&#xff0c;是我们用来进行预测、对对象进行分类或从数据中获取见解的数据点的特定特征或属性。 1.AlexNet paper&#…

jQuery_06 过滤器的使用

什么是过滤器&#xff1f; 过滤器就是用来筛选dom对象的&#xff0c;过滤器是和选择器一起使用的。在选择了dom对象后在进行过滤筛选。 jQuery对象中存储的dom对象顺序与页面标签声明有关系。 声明顺序就是dom中存放的顺序 1.基本过滤器 使用dom对象在数组中的位置来作为过滤条…

一网打尽异步神器CompletableFuture

Future接口以及它的局限性 我们都知道&#xff0c;Java中创建线程的方式主要有两种方式&#xff0c;继承Thread或者实现Runnable接口。但是这两种都是有一个共同的缺点&#xff0c;那就是都无法获取到线程执行的结果&#xff0c;也就是没有返回值。于是在JDK1.5 以后为了解决这…

FloodFill

"绝境之中才窥见&#xff0c;Winner&#xff0c;Winner" FloodFill算法简介: floodfill又翻译成漫水填充。我们可以将下面的矩阵理解为一片具有一定高度的坡地&#xff0c;此时突发洪水&#xff0c;洪水会将高度<0的地方填满。 话句话来说&#xff0c;Fl…

IDEA2023版本创建Sping项目只能勾选17和21,却无法使用Java8?(已解决)

文章目录 前言分析解决方案一&#xff1a;替换创建项目的源方案二&#xff1a;升级JDK版本 参考文献 前言 起因 想创建一个springboot的项目&#xff0c;本地安装的是1.8&#xff0c;但是在使用Spring Initializr创建项目时&#xff0c;发现版本只有17和21。 在JDK为1.8的情况下…

代码随想录算法训练营第四十六天【动态规划part08】 | 139.单词拆分、背包总结

139.单词拆分 题目链接&#xff1a; 力扣&#xff08;LeetCode&#xff09;官网 - 全球极客挚爱的技术成长平台 求解思路&#xff1a; 单词是物品&#xff0c;字符串s是背包&#xff0c;单词能否组成字符串s&#xff0c;就是问物品能不能把背包装满。 动规五部曲 确定dp数…

弹窗concrt140.dll丢失的解决方法,深度解析concrt140.dll丢失的原因

在计算机使用过程中&#xff0c;我们经常会遇到一些错误提示或者系统崩溃的情况。其中&#xff0c;concrt140.dll是一个常见的错误提示&#xff0c;这个错误通常会导致某些应用程序无法正常运行。为了解决这个问题&#xff0c;本文将介绍5种详细的解决方法&#xff0c;帮助您恢…

蓝桥杯官网算法赛(蓝桥小课堂)

问题描述 蓝桥小课堂开课啦&#xff01; 海伦公式&#xff08;Herons formula&#xff09;&#xff0c;也称为海伦-秦九韶公式&#xff0c;是用于计算三角形面积的一种公式&#xff0c;它可以通过三条边的长度来确定三角形的面积&#xff0c;而无需知道三角形的高度。 海伦公…

Python 进阶(十):数学计算(math 模块)

《Python入门核心技术》专栏总目录・点这里 文章目录 1. 导入math模块2. 常用数学函数3. 常量4. 其他函数和用法5. 总结 大家好&#xff0c;我是水滴~~ Python的math模块提供了许多数学运算函数&#xff0c;为开发者在数值计算和数据处理方面提供了强大的工具。本教程将详细介…