Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. public static int randomDamage(int min, int max) {
  2. int range = (max - min) + 1;
  3. int randomDamage = (int)(Math.random() * range) + min;
  4. return randomDamage;
  5.  
  6. public static void battle(Pokemon pokemon1, Pokemon pokemon2) {
  7. showMessageDialog(null, pokemon2.name + "'s stats are: n Health: "
  8. + pokemon2.health + "n Attack: " + pokemon2.attack + "n Speed: " + pokemon2.speed);
  9. showMessageDialog(null, pokemon1.name + " begins the fight against " + pokemon2.name);
  10. do {
  11.  
  12. if (pokemon1.health > 0 && pokemon2.health > 0) {
  13. showMessageDialog(null, pokemon1.name + " attacks " + pokemon2.name);
  14. pokemon2.health = pokemon2.health - randomDamage(0,pokemon1.attack);
  15. showMessageDialog(null, pokemon1.name + " does " + pokemon1.randomDamage + " damage to " +
  16. pokemon2.name + " and " + pokemon2.name + " has " + pokemon2.health + " left.");
  17. }
  18.  
  19. if (pokemon1.health > 0 && pokemon2.health > 0) {
  20. showMessageDialog(null, pokemon2.name + " attacks " + pokemon1.name);
  21. pokemon1.health = pokemon1.health - pokemon2.attack;
  22. showMessageDialog(null, pokemon2.name + " does " + pokemon2.attack + " damage to " +
  23. pokemon1.name + " and " + pokemon1.name + " has " + pokemon1.health + " left.");
  24. }
  25.  
  26.  
  27. } while (pokemon1.health > 0 && pokemon2.health > 0);
  28. if (pokemon1.health < 1) showMessageDialog(null, pokemon1.name + " has been reduced to 0 health. "
  29. + pokemon1.name + " has lost the fight.");
  30. else showMessageDialog(null, pokemon2.name + " has been reduced to 0 health. "
  31. + pokemon2.name + " has lost the fight.");
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement