Public Pages by jhsu
CSE115
Page owned by - jhsu
CSE115


Notes

Behaviors Tue, 28 Feb 2006

  • Regular - a fish that swims across the screen.
  • Chameleon - a fish that changes colors randomly as it swims about the screen.
  • Dizzy - a fish that spins while it swims.
  • Random Swim - a fish that moves in a random way each time it is ready to move.
  • Dying - a fish that swims along at first, but eventually stops swimming. While dying, the fish will change color from its original color to black gradually.
  • Leader - a fish that combines 2 different behaviors from above.
  • Follower - a fish that when created will follow its leader wherever it goes.
  • Surprise - an opportunity for extra credit (should you choose to accept it).
When a fish is created, it should begin its swim at a random position, be created with a random color and move accordingly. Parameterize values where possible. You can always select random values for these when the fish are created.

ToDo Tue, 28 Feb 2006

  • Lab5.dia
  • Create a lot of classes on your own.
  • For every fish that you create, you will want to have a class (10 total)
  • Use: java.awt.Color c = NGP.Utilities.randomColor();
  • int randomNum = NGP.Utilities.randomNumber(low, high)
  • All the fish you create will extend CSE115.FishBowl.Fish (a plain swimming fish)
xxxxxxxxxxxxxxxxxxxxxxxxxxx
public class ChameleonFish extends CSE115.FishBowl.Fish {

public void update(){ overide
this.setColor(NGP.Utilities.randomColor());fish won't swim
} we don't want to redefine like this we wan't partial overide

Chameleon extends CSE115.FishBowl.Fish, we want to do a method call on the superclass

public void update(){ overide
super.update();
this.setColor(NGP.Utilities.randomColor());
}


}

xxxxxxxxxxxxxxxxxxxxxxxxxxx
Dizzy Fish

  • setRotation(90); where the tip points. You want to get current angle, and add on some amount angle
xxxxxxxxxxxxxxxxxxxxxxxxxxx
Random Swim
  • getDx();
  • getDy();
xxxxxxxxxxxxxxxxxxxxxxxxxxx
Dying Fish
  • special update();
  • slow down
  • turn black
xxxxxxxxxxxxxxxxxxxxxxxxxxx
Leader Fish
  • implement 2 previous traits
xxxxxxxxxxxxxxxxxxxxxxxxxxx
Following Fish
  • Know who leader is
  • Every following fish created will follow the leader
  • "knows-a" leader
  • get dx, dy of leader
  • somewhere in FishHatchery, keep track of leader
in FishHatchery:
private LeaderFish _currentLeader;
  • call create leader method and set _currentLeader = new LeaderFish();
xxxxxxxxxxxxxxxxxxxxxxxxxxx
Surprise

Lab5 page Tue, 28 Feb 2006

Lab6 Tue, 7 Mar 2006

Assignment Specification

Write an applet with 4 menus. The first menu allows the user to select a type of fish behavior, Regular, Chameleon, Dizzy, and Random Swim and then create fish of that type. The second menu allows the user to select any combination of Chameleon, Dizzy, or Random Swim and create a fish with that behavior.

The third menu allows the user to create a leader fish, and the fourth menu allows the user to create a follower fish. When a leader fish is created, it will take on the behavior currently specific by the MultiFish menu. When a fish with follower behavior is created, it will "follow" the leader on the screen. There will only be one fish with leader behavior allowed on the board at any one time. So the last leader created will be the leader that all of the follower fish must follow.

Additionally, when a fish is clicked by the user, it will become the new leader and take on the (composite) behavior specified by the MultiFish menu. That is, it will change its behavior while the program is running!

ToDo:

  • Fish that does one thing
  • Fish that does multiple things
  • Create Behaviors (represented by a class)

Code:

  • LeaderMenuObserver
  • FollowerMenuObserver
  • SingleFishBehaviorMenuObserver
  • createMenu(Single..., Multi..., Leader..., Follower...);
UML
  • Dotted open arrow shows implements
  • SingleMenu implements SingleFish...
  • new SingleMenu() <- pass in the class that does the implementing into createMenu();
  • Behavior has composition with Fish
  • Fish extends CSE115.FishBowl.Fish
  • example in Applet:
  • this.createMenu( new SingleMenu(), new MultiMenu(), new LeaderMenu(), new FollowerMenu() );
Other stuff:
  • Behavior -interface with one method
  • void ChangeFish(Fish fishy);
  • implement this behavior, depending on class,
  • DizzyBehavior implements Behavior
  • ChangeFish(...);
  • ChameleonBehavior implements Behavior
  • ChangeFish(...);
  • RegularBehavior implements Behavior
  • ChangeFish(...);
  • Code:
public void ChangeFish(Fish fishy) {

}


public class Thing {
private Foo _f;
private Thing(){
_f = new Foo();
}
}

*Fish.Java: public class Fish extends cse115....Fish {
private Behavior _behavior;
public Fish {
_behavior = new RegularBehavior();
}
public void setBehavior (Behavior b) {
_behavior = b; }
public void update(){ super.update();
}
}

Lab 7 Tue, 11 Apr 2006

public interface Constatns {
public static final int NUM_ROW = 5;
NUM_COLS
CELL_SIZE = 20;
}


public class MyThing implements Constants {
public MyThing(){
system.out.println(NUM_ROW);
} }