+ p.getClass().getSimpleName() + ","
+ this.getClass().getSimpleName()
+ (this.hitFlag ? "发动攻击技能" : "未发动攻击技能")
+ p.getClass().getSimpleName()
+ (this.defenseFlag ? "发动防御技能" : "未发动防御技能")
+ this.getClass().getSimpleName() + ":" + this.val + ","
+ p.getClass().getSimpleName() + ":" + p.val);
hitFlag = false;
defenseFlag = false;
}
public int defense(Person p) {
if (rand.nextInt(10)chanceDefense) {
if (count != 0) {
p.val = p.val - p.fight;
count++;
defenseFlag = true;
if (p.val = 0) {
System.out.println(this.getClass().getSimpleName() + "胜出!");
System.exit(0);
}
}
}
return p.fight;
}
}
class MK extends Person {
public MK() {
val = 700;
coldTime = 2.5;
fight = 50;
chanceDefense = 6;
chanceHit = 3;
waitTime = 0;
}
boolean hitFlag = false;
boolean defenseFlag = false;
Random rand = new Random();
public void hit(Person p) {
if (rand.nextInt(10)chanceHit) {
p.waitTime = 3;//使对方晕眩3s
hitFlag = true;
}
int hurt = p.defense(this);
p.val = p.val - hurt;
if (p.val = 0) {
System.out.println(this.getClass().getSimpleName() + "胜出!");
System.exit(0);
}
System.out.println(this.getClass().getSimpleName() + "攻击"
+ p.getClass().getSimpleName() + ","
+ this.getClass().getSimpleName()
+ (this.hitFlag ? "发动攻击技能" : "未发动攻击技能")
+ p.getClass().getSimpleName()
+ (this.defenseFlag ? "发动防御技能" : "未发动防御技能")
+ this.getClass().getSimpleName() + ":" + this.val + ","
+ p.getClass().getSimpleName() + ":" + p.val);
hitFlag = false;
defenseFlag = false;
}
public int defense(Person p) {
if (rand.nextInt(10)chanceDefense) {
defenseFlag = true;
return p.fight / 2;//防御技能发动,伤害减半
}
return p.fight;
}
}
package com.lxi;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Random;
//三个人物的基类
abstract class Person {
int val;//生命值
double coldTime;//冷却时间
int waitTime;//晕眩时间
int fight;//攻击力
int chanceHit;//发起主动技能的概率
int chanceDefense;//发起防御技能的概率
abstract void hit(Person p);//攻击技能
abstract int defense(Person p); //防御技能 , 返回被伤害点数
}
class DH extends Person {
public DH() {
val = 600;
coldTime = 1.0;
fight = 30;
chanceHit = 3;//表示30%的概率
chanceDefense = 3;
waitTime = 0;
}
Random rand = new Random();
boolean hitFlag = false;//主动技能发动的标识
boolean defenseFlag = false;//防御技能发动的标识
public void hit(Person p) {
if (rand.nextInt(10)chanceHit) {//发动主动技能
int hurt = p.defense(this);
p.val = p.val - hurt;
if (p.val = 0) {
System.out.println(this.getClass().getSimpleName() + "胜出!");
System.exit(0);
}
val = val + hurt;
if (val600)
val = 600;
hitFlag = true;//标记主动技能已经发动
} else {//进行普通攻击
int hurt = p.defense(this);
p.val = p.val - hurt;
if (p.val = 0) {
System.out.println(this.getClass().getSimpleName() + "胜出!");
System.exit(0);
}
}
System.out.println(this.getClass().getSimpleName() + "攻击"
+ p.getClass().getSimpleName() + ","
+ this.getClass().getSimpleName()
+ (this.hitFlag ? "发动攻击技能" : "未发动攻击技能")
+ p.getClass().getSimpleName()
+ (this.defenseFlag ? "发动防御技能" : "未发动防御技能")
推荐阅读
- 电视怎么连wifi用不了,电视怎么连wifi用不了网
- uefi启动硬盘怎么设置,uefi启动找不到硬盘
- 联机电脑游戏经营建设类,好玩的联机经营游戏
- python中循环函数 python循环函数程序
- 加盟店如何做会员营销策略,加盟店如何做会员营销策略分析
- linux卸载挂载点命令,linux卸载挂载盘
- python模块与主程序,python 主模块
- linux命令大全传文件 linux传送文件
- 修复硬盘不能启动怎么办,硬盘修复没反应