傻子打架!

package equipment;


public class Equipment {

private String name;

private double addAttack;

private double addDefence;

private double addBlood;

private double Crit;

private double drinkBloodNum;


public Equipment(String name, double addAttack, double addDefence,
double addBlood, double crit, double drinkBloodNum) {
super();
setName(name);
setAddAttack(addAttack);
setAddDefence(addDefence);
setAddBlood(addBlood);
setCrit(crit);
setDrinkBloodNum(drinkBloodNum);
}


public String getName() {
return name;
}


private void setName(String name) {
this.name = name;
}


public double getAddAttack() {
return addAttack;
}


private void setAddAttack(double addAttack) {
if(addAttack >= 0){
this.addAttack = addAttack;
}
else{
this.addAttack = 0;
}
}


public double getAddDefence() {
return addDefence;
}


private void setAddDefence(double addDefence) {
if(addDefence >= 0){
this.addDefence = addDefence;
}
else{
this.addDefence = 0;
}
}


public double getAddBlood() {
return addBlood;
}


private void setAddBlood(double addBlood) {
if(addBlood >= 0){
this.addBlood = addBlood;
}
else{
this.addBlood = 0;
}
}


public double getCrit() {
return Crit;
}


private void setCrit(double crit) {
if(crit >= 0 && crit <= 1){
this.Crit = crit;
}
else{
this.Crit = 0;
}
}


public double getDrinkBloodNum() {
return drinkBloodNum;
}


private void setDrinkBloodNum(double drinkBloodNum) {
if(drinkBloodNum >= 0){
this.drinkBloodNum = drinkBloodNum;
}
else{
this.drinkBloodNum = 0;
}
}




}


----------------------------------------------------------------------------------------------------------------------


package hero;


import equipment.Equipment;


public class Hero {

private String name;

private double attack;

private double defence;

private double maxBlood;

private double atTimeBlood;

private double Crit;

private double drinkBloodNum;

private Equipment equipment;


public Hero(String name, double attack, double defence, double maxBlood,
double atTimeBlood, double crit, double drinkBloodNum,
Equipment equipment) {
super();
setName(name);
setAttack(attack);
setDefence(defence);
setMaxBlood(maxBlood);
setAtTimeBlood(atTimeBlood);
setCrit(crit);
setDrinkBloodNum(drinkBloodNum);
setEquipment(equipment);
}


public String getName() {
return name;
}


private void setName(String name) {
this.name = name;
}


public double getAttack() {
return attack;
}


public void setAttack(double attack) {
if(attack >= 0){
this.attack = attack;
}
else{
this.attack = 0;
}
}


public double getDefence() {
return defence;
}


public void setDefence(double defence) {
if(defence >= 0){
this.defence = defence;
}
else{
this.defence = 0;
}
}


private double getMaxBlood() {
return maxBlood;
}


private void setMaxBlood(double maxBlood) {
if(maxBlood > 0){
this.maxBlood = maxBlood;
}
else{
this.maxBlood = 10;
}
}


public double getAtTimeBlood() {
return atTimeBlood;
}


public void setAtTimeBlood(double atTimeBlood) {
if(atTimeBlood > 0 && atTimeBlood < this.maxBlood){
this.atTimeBlood = atTimeBlood;
}
else if(atTimeBlood <= 0){
this.atTimeBlood = 0;
}
else{
this.atTimeBlood = this.maxBlood;
}
}


private double getCrit() {
return Crit;
}


private void setCrit(double crit) {
if(crit >= 0 && crit <= 1){
this.Crit = crit;
}
else{
this.Crit = 0;
}

}


private double getDrinkBloodNum() {
return drinkBloodNum;
}


private void setDrinkBloodNum(double drinkBloodNum) {
if(drinkBloodNum >= 0){
this.drinkBloodNum = drinkBloodNum;
}
else{
this.drinkBloodNum = 0;
}
}


private Equipment getEquipment() {
return equipment;
}


public void setEquipment(Equipment equipment) {
if(equipment!=null){
removeEquipment();
this.equipment = equipment;
setAttack(attack + this.equipment.getAddAttack());
setDefence(defence + this.equipment.getAddDefence());
setMaxBlood(maxBlood + this.equipment.getAddBlood());
setCrit(Crit + this.equipment.getCrit());
setDrinkBloodNum(drinkBloodNum + this.equipment.getDrinkBloodNum());
}
}

private void removeEquipment(){

if(this.equipment == null){
}
else{
setAttack(attack - this.equipment.getAddAttack());
setDefence(defence - this.equipment.getAddDefence());
setMaxBlood(maxBlood - this.equipment.getAddBlood());
if(atTimeBlood <= maxBlood - this.equipment.getAddBlood()){
setAtTimeBlood(atTimeBlood);
}
else{
setAtTimeBlood(maxBlood - this.equipment.getAddBlood());
}
setCrit(Crit - this.equipment.getCrit());
setDrinkBloodNum(drinkBloodNum - this.equipment.getDrinkBloodNum());
this.equipment = null;
}

}

public void hit(Hero hero){
double damage = this.attack - hero.getDefence();
if(damage < 0){
damage = 1;
}
if(isCrit()){
damage *= 2;
}
if(hero.getAtTimeBlood() - damage >= 0){
hero.setAtTimeBlood(hero.getAtTimeBlood() - damage);
}
else{
hero.setAtTimeBlood(0);
}
if(this.getAtTimeBlood() != 0){
drinkBlood(damage);
}
System.out.println(this.name+"使用"+this.equipment.getName()+"对"+hero.getName()+"造成了"+damage+"的伤害。");
}

private boolean isCrit(){
if(this.Crit >= Math.random()){
System.out.println(this.getName()+"产生了暴击,伤害翻倍!");
return true;
}
else{
return false;
}
}

private void drinkBlood(double damage){
setAtTimeBlood((damage * this.drinkBloodNum)+getAtTimeBlood());
System.out.println(this.name+"使用饮血效果,吸血"+(damage * this.drinkBloodNum));
}




}











-------------------------------------------------------------------------------------------------------------------------


package hero;


import equipment.Equipment;


public class Warrior extends Hero{


public Warrior(String name, double attack, double defence, double maxBlood,
double atTimeBlood, double crit, double drinkBloodNum,
Equipment equipment) {
super(name, attack, defence, maxBlood, atTimeBlood, crit, drinkBloodNum,
equipment);
// TODO Auto-generated constructor stub
}

public void newHit(Hero hero){

if(Math.random() < 0.3){
if(Math.random() < 0.5){
roach();
}
else{
fear(hero);
}
}

else{
this.hit(hero);
}

}

private void roach(){

this.setAttack(this.getAttack()+20.0);

this.setDefence(this.getDefence()-10.0);

System.out.println("使用了咆哮技能,当前攻击力增加20防御力减少10,分别为:"+this.getAttack()+"   "+this.getDefence());

}

private void fear(Hero hero){

hero.setDefence(hero.getDefence()-20.0);

System.out.println("使用了恐惧技能,对方防御力减20,分别为:"+hero.getAttack()+"   "+hero.getDefence());

}


}


--------------------------------------------------------------------------------------------------------------------------------------



package hero;


import equipment.Equipment;


public class Wizard extends Hero{


public Wizard(String name, double attack, double defence, double maxBlood,
double atTimeBlood, double crit, double drinkBloodNum,
Equipment equipment) {
super(name, attack, defence, maxBlood, atTimeBlood, crit, drinkBloodNum,
equipment);
// TODO Auto-generated constructor stub
}

public void newHit(Hero hero){

if(Math.random()<0.3){

fire(hero);

}

else{
this.hit(hero);
}

}

private void fire(Hero hero){

hero.setAtTimeBlood(hero.getAtTimeBlood() - 100);

System.out.println("使用了火球术,直伤100点!");

}


}


-----------------------------------------------------------------------------------------------------------------


package game;


import equipment.Equipment;
import hero.*;




public class Game {

static Warrior hero1;

static Wizard hero2;

static Equipment equip;

public static void main(String[] args) {

init();


keepHit();

printResult();

/*System.out.println("等着,老子去换装备!");

System.out.print("充值中");

for (int i = 0; i < 10; i++) {


try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.print(".");

}
System.out.println();

init();

hero1.setEquipment(equip);


keepHit();

printResult();*/



}

/*public static void init(){

Equipment e1 = new Equipment("青龙偃月刀", 14.5, 10.1, 40, 0.3, 0.15);

Equipment e2 = new Equipment("长河落日弓", 13.6, 11.2, 50, 0.25,0.1);

Hero h1 = new Hero("德玛西亚",60.0,80.0,300.0,400.0,0.2,0.1,e1);

Hero h2 = new Hero("蒙多",95.0,49.0,250.0,300.0,0.4,0.1,e2);

hero1 = h1;

hero2 = h2;

Equipment e3 = new Equipment("GM氪金玄天杀神刀", 1000.0, 1000.0, 10000.0, 1.0,1.0);

equip = e3;

}*/

public static void init(){

Equipment e1 = new Equipment("时光杖", 27.0, 10.1, 500.0, 0.3, 0.15);

Equipment e2 = new Equipment("饮血刀", 13.6, 11.2, 500.0, 0.25,0.1);

Warrior h1 = new Warrior("德玛西亚",60.0,95.0,1000.0,1000.0,0.2,0.1,e2);

Wizard h2 = new Wizard("吉安娜",95.0,49.0,900.0,900.0,0.4,0.1,e1);

hero1 = h1;

hero2 = h2;


}

public static void keepHit(){

while(true){

if(hero1.getAtTimeBlood() == 0 || hero2.getAtTimeBlood() == 0){

break;

}

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

hero1.newHit(hero2);

if(hero1.getAtTimeBlood() == 0 || hero2.getAtTimeBlood() == 0){

break;

}

System.out.println(hero1.getName()+"当前血量值为"+hero1.getAtTimeBlood()+","+hero2.getName()+"当前血量值为"+hero2.getAtTimeBlood());

System.out.println("----------------------------------------------------------------------------------");

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

hero2.newHit(hero1);

System.out.println(hero1.getName()+"当前血量值为"+hero1.getAtTimeBlood()+","+hero2.getName()+"当前血量值为"+hero2.getAtTimeBlood());

System.out.println("----------------------------------------------------------------------------------");
}

}


/*public static void keepHit(){

while(true){

if(hero1.getAtTimeBlood() == 0 || hero2.getAtTimeBlood() == 0){

break;

}

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

hero1.hit(hero2);

if(hero1.getAtTimeBlood() == 0 || hero2.getAtTimeBlood() == 0){

break;

}

System.out.println(hero1.getName()+"当前血量值为"+hero1.getAtTimeBlood()+","+hero2.getName()+"当前血量值为"+hero2.getAtTimeBlood());

System.out.println("----------------------------------------------------------------------------------");

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

hero2.hit(hero1);

System.out.println(hero1.getName()+"当前血量值为"+hero1.getAtTimeBlood()+","+hero2.getName()+"当前血量值为"+hero2.getAtTimeBlood());

System.out.println("----------------------------------------------------------------------------------");


}

}*/

public static void printResult(){

if(hero1.getAtTimeBlood() > 0 && hero2.getAtTimeBlood() == 0){

System.out.println(hero2.getName()+"生命值为0");

System.out.println(hero1.getName()+"胜利");

}

else if(hero1.getAtTimeBlood() == 0 && hero2.getAtTimeBlood() > 0){

System.out.println(hero1.getName()+"生命值为0");

System.out.println(hero2.getName()+"胜利");

}

else{

System.out.println("生命值均为0");

System.out.println("平局!");

}

}


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值