Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 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 void highPunch(Fighter enemy) {
  35. if(randomPercent(enemy.blockPercent)) {
  36. enemy.health -= this.damage / 2;
  37. System.out.println(enemy.name + " took a high punch, but blocked it. Damage : -" + (this.damage / 2) + " .Health: " + enemy.health);
  38. return;
  39. }
  40.  
  41. if(randomPercent(enemy.dodgePercent)) {
  42. System.out.println(enemy.name + " took a high punch, but dodged it. No damage. Health: " + enemy.health);
  43. return;
  44. }
  45.  
  46. enemy.health -= this.damage;
  47. System.out.println(enemy.name + " took a high punch. Damage : -" + this.damage + " .Health: " + enemy.health);
  48. }
  49.  
  50. public void highKick (Fighter enemy) {
  51. if(randomPercent(enemy.blockPercent)) {
  52. enemy.health -= this.damage - HIGH_KICK_BLOCK;
  53. System.out.println(enemy.name + " took a high punch, but blocked it. Damage : -" + (this.damage - HIGH_KICK_BLOCK) + " .Health: " + enemy.health);
  54. return;
  55. }
  56.  
  57. if(randomPercent(enemy.dodgePercent)) {
  58. System.out.println(enemy.name + " took a high kick, but dodged it. No damage. Health: " + enemy.health);
  59. return;
  60. }
  61.  
  62. enemy.health -= this.damage;
  63. System.out.println(enemy.name + " took a high kick. Damage : -" + this.damage + " .Health: " + enemy.health);
  64. }
  65.  
  66. public void lowPunch(Fighter enemy) {
  67. if(randomPercent(enemy.blockPercent)) {
  68. enemy.health -= this.damage - LOW_PUNCH_BLOCK;
  69. System.out.println(enemy.name + " took a low punch, but blocked it. Damage : -" + (this.damage - LOW_PUNCH_BLOCK) + " .Health: " + enemy.health);
  70. return;
  71. }
  72.  
  73. if(randomPercent(enemy.dodgePercent)) {
  74. System.out.println(enemy.name + " took a low punch, but dodged it. No damage. Health: " + enemy.health);
  75. return;
  76. }
  77.  
  78. enemy.health -= this.damage;
  79. System.out.println(enemy.name + " took a low punch. Damage : -" + this.damage + " .Health: " + enemy.health);
  80. }
  81.  
  82. public void lowKick(Fighter enemy) {
  83. if(randomPercent(enemy.blockPercent)) {
  84. enemy.health -= this.damage - LOW_KICK_BLOCK;
  85. System.out.println(enemy.name + " took a low kick, but blocked it. Damage : -" + (this.damage - LOW_KICK_BLOCK) + " .Health: " + enemy.health);
  86. return;
  87. }
  88.  
  89. if(randomPercent(enemy.dodgePercent)) {
  90. System.out.println(enemy.name + " took a low kick, but dodged it. No damage. Health: " + enemy.health);
  91. return;
  92. }
  93.  
  94. enemy.health -= this.damage;
  95. System.out.println(enemy.name + " took a low kick. Damage : -" + this.damage + " .Health: " + enemy.health);
  96. }
  97.  
  98. public void fatality (Fighter enemy) {
  99. System.out.println("Finish him!");
  100. enemy.health = 0;
  101. System.out.println(this.name + " wins.");
  102. System.out.println("Fatality.");
  103. }
  104.  
  105. public void fireBall(Fighter enemy) {
  106. System.out.println(this.name + " threw a fire ball! Double damage!");
  107. enemy.health -= this.damage * 2;
  108. }
  109.  
  110. public void flyingKick(Fighter enemy) {
  111. System.out.println(this.name + " did a flying kick! Double damage!");
  112. enemy.health -= this.damage * 2;
  113. }
  114.  
  115. public void knifeThrow(Fighter enemy) {
  116. System.out.println(this.name + " threw knife! Double damage!");
  117. enemy.health -= this.damage * 2;
  118. }
  119.  
  120. public boolean randomPercent(int percent) {
  121. return new Random(100).nextInt() < percent;
  122. }
  123.  
  124. public void chooseAttack(Fighter enemy) {
  125. int attack = new Random().nextInt(7) + 1;
  126. switch(attack) {
  127. case 1 : this.highPunch(enemy); break;
  128. case 2 : this.highKick(enemy); break;
  129. case 3 : this.lowKick(enemy); break;
  130. case 4 : this.highPunch(enemy); break;
  131. case 5 : this.fireBall(enemy); break;
  132. case 6 : this.flyingKick(enemy); break;
  133. case 7 : this.knifeThrow(enemy); break;
  134. default : break;
  135. }
  136. }
  137.  
  138. public void revive () {
  139. this.health = maxHealth;
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement