无畏契约:源能行动-java模拟程序
以下是一个模拟无畏契约:源能行动游戏机制的 Java 程序
import java.util.*;
// 特工基类
abstract class Agent {
protected String name;
protected String role;
protected int health;
protected boolean isAlive;
public Agent(String name, String role) {
this.name = name;
this.role = role;
this.health = 100;
this.isAlive = true;
}
// 抽象方法 - 使用技能
public abstract void useAbility(int abilityNumber);
// 通用方法 - 受到伤害
public void takeDamage(int damage) {
if (isAlive) {
health -= damage;
if (health <= 0) {
health = 0;
isAlive = false;
System.out.println(name + " 已被击败!");
} else {
System.out.println(name + " 受到 " + damage + " 点伤害,剩余生命值: " + health);
}
}
}
// 通用方法 - 治疗
public void heal(int amount) {
if (isAlive) {
health += amount;
if (health > 100) health = 100;
System.out.println(name + " 恢复 " + amount + " 点生命值,当前生命值: " + health);
}
}
// Getter 方法
public String getName() { return name; }
public String getRole() { return role; }
public int getHealth() { return health; }
public boolean isAlive() { return isAlive; }
}
// 决斗者类
class Duelist extends Agent {
public Duelist(String name) {
super(name, "决斗者");
}
@Override
public void useAbility(int abilityNumber) {
switch(abilityNumber) {
case 1:
System.out.println(name + " 使用了冲刺技能,快速移动!");
break;
case 2:
System.out.println(name + " 使用了烟雾弹,遮挡视线!");
break;
case 3:
System.out.println(name + " 使用了致命射击,造成高额伤害!");
break;
case 4:
System.out.println(name + " 释放终极技能:死亡之眼!");
break;
default:
System.out.println("无效的技能选择!");
}
}
}
// 控场者类
class Controller extends Agent {
public Controller(String name) {
super(name, "控场者");
}
@Override
public void useAbility(int abilityNumber) {
switch(abilityNumber) {
case 1:
System.out.println(name + " 使用了烟雾屏障,阻挡视野!");
break;
case 2:
System.out.println(name + " 使用了闪光弹,致盲敌人!");
break;
case 3:
System.out.println(name + " 使用了减速区域,限制敌人移动!");
break;
case 4:
System.out.println(name + " 释放终极技能:全域封锁!");
break;
default:
System.out.println("无效的技能选择!");
}
}
}
// 先锋类
class Initiator extends Agent {
public Initiator(String name) {
super(name, "先锋");
}
@Override
public void useAbility(int abilityNumber) {
switch(abilityNumber) {
case 1:
System.out.println(name + " 使用了侦察箭,探测敌人位置!");
break;
case 2:
System.out.println(name + " 使用了冲击波,击退敌人!");
break;
case 3:
System.out.println(name + " 使用了震荡陷阱,眩晕敌人!");
break;
case 4:
System.out.println(name + " 释放终极技能:猎人之怒!");
break;
default:
System.out.println("无效的技能选择!");
}
}
}
// 守卫类
class Sentinel extends Agent {
public Sentinel(String name) {
super(name, "守卫");
}
@Override
public void useAbility(int abilityNumber) {
switch(abilityNumber) {
case 1:
System.out.println(name + " 部署了陷阱,限制敌人移动!");
break;
case 2:
System.out.println(name + " 设置了警报器,探测敌人!");
break;
case 3:
System.out.println(name + " 建立了防御屏障!");
break;
case 4:
System.out.println(name + " 释放终极技能:绝对防御!");
break;
default:
System.out.println("无效的技能选择!");
}
}
}
// 游戏回合类
class Round {
private int roundNumber;
private boolean attackersWin;
public Round(int roundNumber) {
this.roundNumber = roundNumber;
}
public void playRound(List<Agent> attackers, List<Agent> defenders) {
System.out.println("\n===== 第 " + roundNumber + " 回合开始 =====");
// 模拟回合战斗
Random random = new Random();
// 随机决定攻击方或防守方获胜
attackersWin = random.nextBoolean();
if (attackersWin) {
System.out.println("攻击方成功安放/拆除爆能器,攻击方获胜!");
// 随机选择一名防守方特工被击败
Agent defeatedDefender = defenders.get(random.nextInt(defenders.size()));
defeatedDefender.takeDamage(100);
} else {
System.out.println("防守方成功防守/拆除爆能器,防守方获胜!");
// 随机选择一名攻击方特工被击败
Agent defeatedAttacker = attackers.get(random.nextInt(attackers.size()));
defeatedAttacker.takeDamage(100);
}
// 随机使用技能
for (Agent agent : attackers) {
if (agent.isAlive()) {
agent.useAbility(random.nextInt(4) + 1);
}
}
for (Agent agent : defenders) {
if (agent.isAlive()) {
agent.useAbility(random.nextInt(4) + 1);
}
}
}
public boolean didAttackersWin() {
return attackersWin;
}
}
// 游戏类
public class ValorantSourceAction {
private List<Agent> attackers;
private List<Agent> defenders;
private int attackerScore;
private int defenderScore;
private int currentRound;
public ValorantSourceAction() {
this.attackers = new ArrayList<>();
this.defenders = new ArrayList<>();
this.attackerScore = 0;
this.defenderScore = 0;
this.currentRound = 1;
}
// 选择特工
public void selectAgents() {
System.out.println("===== 特工选择阶段 =====");
// 创建一些示例特工
attackers.add(new Duelist("捷风"));
attackers.add(new Initiator("猎枭"));
attackers.add(new Controller("幽影"));
attackers.add(new Duelist("雷兹"));
attackers.add(new Initiator("海神"));
defenders.add(new Sentinel("奇乐"));
defenders.add(new Sentinel("圣祈"));
defenders.add(new Controller("蝰蛇"));
defenders.add(new Duelist("菲尼克斯"));
defenders.add(new Sentinel("赛博"));
System.out.println("攻击方特工:");
for (Agent agent : attackers) {
System.out.println("- " + agent.getName() + " (" + agent.getRole() + ")");
}
System.out.println("\n防守方特工:");
for (Agent agent : defenders) {
System.out.println("- " + agent.getName() + " (" + agent.getRole() + ")");
}
}
// 玩游戏
public void playGame() {
System.out.println("\n===== 无畏契约:源能行动开始! =====");
selectAgents();
// 进行13回合比赛
while (currentRound <= 13 && attackerScore < 13 && defenderScore < 13) {
Round round = new Round(currentRound);
round.playRound(attackers, defenders);
if (round.didAttackersWin()) {
attackerScore++;
} else {
defenderScore++;
}
System.out.println("当前比分: 攻击方 " + attackerScore + " - " + defenderScore + " 防守方");
currentRound++;
// 每回合后暂停一下
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// 宣布获胜者
System.out.println("\n===== 比赛结束! =====");
if (attackerScore > defenderScore) {
System.out.println("攻击方获胜! 最终比分: " + attackerScore + " - " + defenderScore);
} else {
System.out.println("防守方获胜! 最终比分: " + attackerScore + " - " + defenderScore);
}
}
public static void main(String[] args) {
ValorantSourceAction game = new ValorantSourceAction();
game.playGame();
}
}
