package edu.columbia.cs.cs1007.comics;
import java.util.Random;
/**
* An implementation of superheroes who possess super-natural
* physical strength.
* @author Julia Stoyanovich (jds2109@columbia.edu)
* COMS 1007, Summer 2009
*
*/
public class StrongSuperHero extends SuperHero {
/**
* Constructor.
* @param name
*/
public StrongSuperHero(String name) {
super(name, "Physical Strength");
}
/**
* Implementation of the abstract method inherited from the superclass.
* @param villain
* @return dialogue
*/
public String killVillain(Villain villain) {
StringBuffer dialogue = new StringBuffer(villain.speakUp());
dialogue.append("\n" + this.speakUp());
while (villain.isAlive()) {
dialogue.append("\n" + hitOverTheHead(villain));
}
return dialogue.toString();
}
/**
* A private method that implements the method of killing the villain
* using physical force.
* @param villain
* @return dialogue
*/
private String hitOverTheHead(Villain villain) {
String dialogue = getName() + " : Boom!";
Random rand = new Random();
if (rand.nextBoolean()) {
dialogue += "\n" + villain.die();
}
return dialogue;
}
}
|