Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3.  
  4. public class Fighter {
  5.  
  6. private String name;
  7. private int health;
  8. private int damage;
  9. private int blockPercent;
  10. private int dodgePercent;
  11. private int wonFights;
  12. private int maxHealth;
  13. private static final int HIGH_KICK_BLOCK = 4;
  14. private static final int LOW_PUNCH_BLOCK = 6;
  15. private static final int LOW_KICK_BLOCK = 8;
  16.  
  17. public Fighter (String name, int damage) {
  18. this();
  19. this.name = name;
  20. this.damage = damage;
  21. }
  22.  
  23. public Fighter() {
  24. this.health = 100;
  25. this.maxHealth = this.health;
  26. this.blockPercent = 10;
  27. this.dodgePercent = 12;
  28. }
  29.  
  30. public int getHealth() {
  31. return health;
  32. }
  33.  
  34. public String getName() {
  35. return name;
  36. }
  37.  
  38. public void highPunch(Fighter enemy) {
  39. if(randomPercent(enemy.blockPercent)) {
  40. enemy.health -= this.damage / 2;
  41. System.out.println(enemy.name + " took a high punch, but blocked it. Damage : " + (this.damage / 2) + " .Health: " + enemy.health);
  42. return;
  43. }
  44.  
  45. if(randomPercent(enemy.dodgePercent)) {
  46. System.out.println(enemy.name + " took a high punch, but dodged it. No damage. Health: " + enemy.health);
  47. return;
  48. }
  49.  
  50. enemy.health -= this.damage;
  51. System.out.println(enemy.name + " took a high punch. Damage : " + this.damage + " .Health: " + enemy.health);
  52. }
  53.  
  54. public void highKick (Fighter enemy) {
  55. if(randomPercent(enemy.blockPercent)) {
  56. enemy.health -= this.damage - HIGH_KICK_BLOCK;
  57. System.out.println(enemy.name + " took a high punch, but blocked it. Damage : " + (this.damage - HIGH_KICK_BLOCK) + " .Health: " + enemy.health);
  58. return;
  59. }
  60.  
  61. if(randomPercent(enemy.dodgePercent)) {
  62. System.out.println(enemy.name + " took a high kick, but dodged it. No damage. Health: " + enemy.health);
  63. return;
  64. }
  65.  
  66. enemy.health -= this.damage;
  67. System.out.println(enemy.name + " took a high kick. Damage : " + this.damage + " .Health: " + enemy.health);
  68. }
  69.  
  70. public void lowPunch(Fighter enemy) {
  71. if(randomPercent(enemy.blockPercent)) {
  72. enemy.health -= this.damage - LOW_PUNCH_BLOCK;
  73. System.out.println(enemy.name + " took a low punch, but blocked it. Damage : " + (this.damage - LOW_PUNCH_BLOCK) + " .Health: " + enemy.health);
  74. return;
  75. }
  76.  
  77. if(randomPercent(enemy.dodgePercent)) {
  78. System.out.println(enemy.name + " took a low punch, but dodged it. No damage. Health: " + enemy.health);
  79. return;
  80. }
  81.  
  82. enemy.health -= this.damage;
  83. System.out.println(enemy.name + " took a low punch. Damage : " + this.damage + " .Health: " + enemy.health);
  84. }
  85.  
  86. public void lowKick(Fighter enemy) {
  87. if(randomPercent(enemy.blockPercent)) {
  88. enemy.health -= this.damage - LOW_KICK_BLOCK;
  89. System.out.println(enemy.name + " took a low kick, but blocked it. Damage : " + (this.damage - LOW_KICK_BLOCK) + " .Health: " + enemy.health);
  90. return;
  91. }
  92.  
  93. if(randomPercent(enemy.dodgePercent)) {
  94. System.out.println(enemy.name + " took a low kick, but dodged it. No damage. Health: " + enemy.health);
  95. return;
  96. }
  97.  
  98. enemy.health -= this.damage;
  99. System.out.println(enemy.name + " took a low kick. Damage : " + this.damage + " .Health: " + enemy.health);
  100. }
  101.  
  102. public void fatality (Fighter enemy) {
  103. System.out.println("Finish him!");
  104. enemy.health = 0;
  105. System.out.println(this.name + " wins.");
  106. System.out.println("Fatality.");
  107. }
  108.  
  109. public void fireBall(Fighter enemy) {
  110. System.out.println(this.name + " threw a fire ball! Double damage!");
  111. enemy.health -= this.damage * 2;
  112. System.out.println(enemy.name + " health: " + enemy.health);
  113. }
  114.  
  115. public void flyingKick(Fighter enemy) {
  116. System.out.println(this.name + " did a flying kick! Double damage!");
  117. enemy.health -= this.damage * 2;
  118. System.out.println(enemy.name + " health: " + enemy.health);
  119. }
  120.  
  121. public void knifeThrow(Fighter enemy) {
  122. System.out.println(this.name + " threw knife! Double damage!");
  123. enemy.health -= this.damage * 2;
  124. System.out.println(enemy.name + " health: " + enemy.health);
  125. }
  126.  
  127. public boolean randomPercent(int percent) {
  128. return new Random(100).nextInt() < percent;
  129. }
  130.  
  131. public void chooseAttack(Fighter enemy) {
  132. int attack = new Random().nextInt(7) + 1;
  133. switch(attack) {
  134. case 1 : this.highPunch(enemy); break;
  135. case 2 : this.highKick(enemy); break;
  136. case 3 : this.lowKick(enemy); break;
  137. case 4 : this.highPunch(enemy); break;
  138. case 5 : this.fireBall(enemy); break;
  139. case 6 : this.flyingKick(enemy); break;
  140. case 7 : this.knifeThrow(enemy); break;
  141. default : break;
  142. }
  143. }
  144.  
  145. public boolean isDead() {
  146. return this.health <= 0;
  147. }
  148.  
  149. public void revive () {
  150. this.health = maxHealth;
  151. }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement