Professional Documents
Culture Documents
*;
public class AssassinManager {
//AssassinNode that points to the front of killRing
private AssassinNode killRing;
//points to the front of graveyard
private AssassinNode graveyard;
//pre: There must be names of players in the list that is passed in
//otherwise a IllegalArgumentException will be thrown
//post: Sets the initial kill ring with the names in list order
public AssassinManager(List<String> names){
if(names.size() == 0){
throw new IllegalArgumentException();
}
for(int i = names.size() - 1; i >= 0; i--){
killRing = new AssassinNode(names.get(i), killRing);
}
}
//post: prints the names in the kill ring, stating who is stalking who
public void printKillRing(){
AssassinNode first = killRing;
while(first.next != null){
AssassinNode second = first.next;
System.out.println("
" + first.name + " is stalking " + second.name)
;
first = first.next;
}
System.out.println("
" + first.name + " is stalking " + killRing.name);
}
//post: prints the names in the graveyard
public void printGraveyard(){
AssassinNode curr = graveyard;
while(curr != null){
System.out.println("
" + curr.name + " was killed by " + curr.killer
);
curr = curr.next;
}
}
//post: returns whether or not given assassin node has the given string
private boolean contains(AssassinNode temp, String name){
while(temp != null){
if(temp.name.equalsIgnoreCase(name)){
return true;
}
temp = temp.next;
}
return false;
}
//post: returns true if the name is in the kill ring, false if not
public boolean killRingContains(String name){
AssassinNode current = killRing;
return contains(current, name);
}