奥特曼打小怪兽

 1 /**
 2  * OUTMAN附
 3  * 
 4  * @author 王启文
 5  *
 6  */
 7 public class One {
 8     private String name;
 9     private int hp;
10     private int mp;
11     private int damage;
12     private int defense;
13     private int intelligence;
14 
15     public One(String name, int hp, int mp, int damage, int defense,
16             int intelligence) {
17         this.name = name;
18         this.hp = hp;
19         this.mp = mp;
20         this.damage = damage;
21         this.defense = defense;
22         this.intelligence = intelligence;
23     }
24 
25     public String getName() {
26         return this.name;
27     }
28 
29     public boolean isAlive() {
30         return this.hp > 0;
31     }
32 
33     public boolean hasMp() {
34         return this.mp > 0;
35     }
36 
37     public String getInfo() {
38         return "姓名: " + name + "\n生命值: " + hp + "\t" + "魔法值: " + mp;
39     }
40 
41     public void physicsAttack(One other) {
42         int effectiveDamage = (int) (Math.random() * damage / 5 + 4 * damage / 5);
43         int effectiveDefense = (int) (Math.random() * defense / 4 + 3 * defense / 4);
44         if (effectiveDamage - effectiveDefense > 0) {
45             other.hp -= effectiveDamage - effectiveDefense;
46             if (other.hp <= 0) {
47                 other.hp = 0;
48             }
49         } else {
50             other.hp -= 1;
51         }
52     }
53 
54     public void magicAttack(One other) {
55         int effectiveMagicAttack = (int) (Math.random() * intelligence / 2 + intelligence);
56         other.hp -= effectiveMagicAttack;
57         mp -= 40;
58         if (other.hp <= 0) {
59             other.hp = 0;
60         }
61         if (mp <= 0) {
62             mp = 0;
63         }
64     }
65 
66     public void outburst() {
67         double sz = Math.random();
68         if (sz < 0.1 && this.hp < hp / 10) {
69             this.hp *= 2;
70             this.damage *= 2;
71             this.defense *= 0.5;
72         }
73     }
74 
75     // public boolean escape(){
76     // double sc = Math.random();
77     // if (this.hp<hp/10&&sc<0.1) {
78     // this.hp=0;
79     // }
80     // return false;
81     // }
82 }
 1 /**
 2  * OUTMAN
 3  * 
 4  * @author 王启文
 5  *
 6  */
 7 public class fight {
 8     public static void main(String[] args) {
 9         One a1 = new One("Ultraman", 600, 280, 99, 55, 120);
10         One a2 = new One("Monster", 1200, 200, 78, 70, 100);
11 
12         int times = 1;
13 
14         System.out.println(a1.getInfo());
15         System.out.println(a2.getInfo());
16 
17         while (a1.isAlive() && a2.isAlive()) {
18             System.out.println("第" + times + "次");
19             double a = Math.random();
20             if (a < 0.8) {
21                 a1.physicsAttack(a2);
22                 if (a2.isAlive()) {
23                     double b = Math.random();
24                     if (b < 0.8) {
25                         a2.physicsAttack(a1);
26                     } else {
27                         if (a2.hasMp()) {
28                             a2.magicAttack(a1);
29                         } else
30                             a2.physicsAttack(a1);
31                     }
32                 }
33             } else {
34                 if (a1.hasMp()) {
35                     a1.magicAttack(a2);
36                     if (a2.isAlive()) {
37                         double b = Math.random();
38                         if (b < 0.8) {
39                             a2.physicsAttack(a1);
40                         } else {
41                             if (a2.hasMp()) {
42                                 a2.magicAttack(a1);
43                             } else {
44                                 a2.physicsAttack(a1);
45                             }
46                         }
47                     }
48                 } else {
49                     a1.physicsAttack(a2);
50                     if (a2.isAlive()) {
51                         double b = Math.random();
52                         if (b < 0.8) {
53                             a2.physicsAttack(a1);
54                         } else {
55                             if (a2.hasMp()) {
56                                 a2.magicAttack(a1);
57                             } else
58                                 a2.physicsAttack(a1);
59                         }
60                     }
61                 }
62             }
63 
64             System.out.println(a1.getInfo());
65             System.out.println(a2.getInfo());
66             System.out.println("----------------");
67             times++;
68         }
69 
70         if (a1.isAlive()) {
71             System.out.println(a1.getName() + "获胜!!!");
72         } else {
73             System.out.println(a2.getName() + "获胜!!!");
74         }
75     }
76 }

未完待续......

转载于:https://www.cnblogs.com/Wqwwd/p/4052711.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
现在有一个奥特曼怪兽的角色扮演游戏。请你根据下面的描述,定义两个类:奥特曼类和怪兽类。 在奥特曼的世界,打怪兽就是全部。现在人人都有机会成为奥特曼,加入到与怪兽无止境的战斗中。可惜,并非人人生来就是英雄,革命尚未成功,同志仍需努力啊。每一个奥特曼都要从零开始,辛勤劳动,打怪升级,最终才能成为举世瞩目的大英雄。 奥特曼的等级(rank)从第一级开始,随着它打怪兽经验(exp)的增加,等级将不断攀升。随着等级的升高,奥特曼的生命值(hp)上限和攻击力(damage)也将大大增强。在与怪兽的战斗中,奥特曼收获的不仅仅是经验。有时,运气好的话,还能从怪兽身上弄到点小钱(money)。不要小看这些钱,关键时刻,它能给奥特曼买药补血呀。奥特曼没有金刚不坏之身,在与怪兽的战斗中,奥特曼会受到伤害。一旦奥特曼的生命值降到0,它英雄的一生就结束了。 好了,了解了奥特曼的基本情况,现在可以开始战斗了。首先,我们需要一位全新的奥特曼,我们给它赋予一定的初始实力(initial)。让它投入战斗吧! 在与怪兽的战斗中要讲究策略。所谓知己知彼,百战不殆,一旦碰到怪兽,我们首先要查看自己和对方的实力(display),包括双方的等级、生命值、攻击力、经验和所拥有的钱财。所谓打得赢就打,打不赢就跑。如果对手太强大,逃跑吧(escape)!偶尔逃跑无伤颜面,但会耗费一点生命值。如果总是逃跑,生命被虚耗,那英雄就当不成了。所以该出手时就出手,勇敢地战斗(attack)吧!每一回合的战斗中,怪兽会受到攻击(attacked),怪兽也会反击(fightback),让奥特曼受到攻击(attacked)。每一回合结束,只要奥特曼还活着(isalive),而且怪兽也还活着,战斗就要继续。如果奥特曼的生命值太低,也许抵挡不了下一轮的进攻,那么别财迷了,掏钱出来给它补血(restore)吧。当然,如果形势确实不妙,奥特曼也可以中途逃跑。但如果获得了最终的胜利(win),不仅能赢得战斗经验,夺取怪兽身上的钱财,足够多的经验也许能让奥特曼升级(upgrade)。 以及其实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值