package GloryofKings;
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("D:\\学习资料\\Java\\王者荣耀图片\\Daji\\abilityOne.jpg");
abilityTwo = Toolkit.getDefaultToolkit().getImage("D:\\学习资料\\Java\\王者荣耀图片\\Daji\\abilityTwo.jpg");
abilityThree = Toolkit.getDefaultToolkit().getImage("D:\\学习资料\\Java\\王者荣耀图片\\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, "D:\\学习资料\\Java\\王者荣耀图片\\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,
"D:\\学习资料\\Java\\王者荣耀图片\\Daji\\abilityTwoBullet.png");
} else {
bulletList[count] = new Bullet(gameFrame, this, targetList.get(r), 150, 60,
"D:\\学习资料\\Java\\王者荣耀图片\\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();