//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Mario Foe Tests //Description: Test suite for classes that represent enemies of the Mario // Brothers. //CS 284 //Programmed by Jonathan Voris //2/21/06 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ package MarioFoes; //for LinkedList manipulation import java.util.LinkedList; //for LinkedList traversal import java.util.ListIterator; class MarioTests { public static void main(String[] args) { //create a new linked list of objects that implement //the MarioFoe interface LinkedList enemies = new LinkedList(); //populate the list Goomba g = new Goomba(); enemies.add(g); SilverGoomba sg = new SilverGoomba(); enemies.add(sg); ParaGoomba pg = new ParaGoomba(); enemies.add(pg); KoopaTroopa kt = new KoopaTroopa(); enemies.add(kt); RedKoopaTroopa rkt = new RedKoopaTroopa(); enemies.add(rkt); HammerBrother hb = new HammerBrother(); enemies.add(hb); DryBones db = new DryBones(); enemies.add(db); //create a list iterator to traverse the list ListIterator enemyIter = enemies.listIterator(); while (enemyIter.hasNext()) { //grab the foe that is currently being pointed to //and store it as a MarioFoe MarioFoe enemy = (MarioFoe)enemyIter.next(); System.out.println(enemy); //check and see if the MarioFoe implements //any additional interfaces. If so, temporarilly cast it to //the type of the interface and call the method associated with it. if (enemy instanceof stompable) { System.out.println("Stomped:" + ((stompable)enemy).stomped()); } if (enemy instanceof burnable) { System.out.println("Burnt:" + ((burnable)enemy).burnt()); } if (enemy instanceof attacker) { System.out.println("Attack:" + ((attacker)enemy).attack()); } System.out.println(); } } }