Beispiel #1
0
 public String spell(Monster other, String userInput) {
   if (userInput.equals("1") && thing.nextInt(this.getACC()) > 20) {
     if ((this.getMP() - 20) < 0) {
       return ("Not enough mana!");
     } else {
       int damage = 15 + thing.nextInt(11);
       other.setHP(other.getHP() - damage);
       this.setMP(this.getMP() - 20);
       return (this + " shot a fireball at " + other + ". " + other + " lost " + damage + "  HP.");
     }
   } else if (userInput.equals("2") && thing.nextInt(this.getACC()) > 0) {
     if ((this.getMP() - 30) < 0) {
       return ("Not enough mana!");
     } else {
       int damage = 15 + thing.nextInt(11);
       other.setHP(other.getHP() - damage);
       this.setMP(this.getMP() - 30);
       return (this + " electrified " + other + ". " + other + " lost " + damage + "  HP.");
     }
   } else if (userInput.equals("3") && thing.nextInt(this.getACC()) > 20) {
     if ((this.getMP() - 40) < 0) {
       return ("Not enough mana!");
     } else {
       int damage = 25 + thing.nextInt(11);
       other.setHP(other.getHP() - damage);
       this.setMP(this.getMP() - 40);
       return (this + " froze " + other + ". " + other + " lost " + damage + " HP.");
     }
   } else {
     if (userInput.equals("1")) {
       this.setMP(this.getMP() - 20);
       return "The spell fizzled and died";
     }
     if (userInput.equals("2")) {
       this.setMP(this.getMP() - 30);
       return "The spell fizzled and died";
     }
     if (userInput.equals("3")) {
       this.setMP(this.getMP() - 40);
       return "The spell fizzled and died";
     }
     if (userInput.equals("")) {
       return this.toString() + " did nothing.";
     }
     if (this.getMP() < 0) {
       this.setMP(0);
     }
     return "";
   }
 }