11-12-2013

posted Nov 12, 2013, 8:34 AM by Samuel Konstantinovich   [ updated Nov 13, 2013, 5:10 AM ]
Today at 2:15pm and 16 seconds it will be:
11-12-13 14:15:16

Goal: Getting classes and sub classes can harmoniously co-exist. 

Lets make two simple classes:

public class enemy{
 public void greet(){
  System.out.println("Muah ha hah!");
 }
 
}

public class boss extends enemy{
 public void greet(){
  System.out.println("MUAH HA HAH!");
 }
 public void taunt(){
  System.out.println("Your princess is in another castle!!!");
 }
}

//HERE IS A DEMO TO RUN THEM
public class demo{
 public static void main(String[]args){
  enemy a = new enemy();
  enemy b = new boss();
  boss c = new boss();

  a.greet();
  b.greet();
  c.greet();

//how do we call taunt?
  c.taunt();
//can b taunt?
((boss)b).taunt();
 }

}

Goal2: Implementing multiple player controlled characters using arrays.

Character[] party = new Character[4];
an object array needs to be new'ed,
AND EACH object in the array needs to be new'ed


HW: Design a party such that you can keep track of what kind of character each member is. 
How would you do this? What else does a party need?
Comments