CSE 131 (Fall 2008)

  1. What objects do you envision being instantiated to implement the game? In terms of graphics coordinates, where do you plan to place those objects?

  2. Define precisely the asynchronous events: user inputs that affect the game and that originate from mouse actions and keyboard input. Think in terms of a storyboard for how the game should work and describe mode changes that are triggered, based on user inputs.

    Take a look at the extesion for Lab 5, in which a timer was used to move the pupil slowly form its old to new position.

    Give meaningful names to the various modes, so that efficient conversations can take place among the groups.

    Deploy the following code in a game packge under eclipse and run it to experiment with mouse actions and the resulting method calls.

    package game;
    import yops.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Timer;
    public class Controller implements ActionListener {
    	final private GraphicsPanel panel;
    	final private Timer timer;
    	final private int quantum;
    	private       int tick; // in ms
    	public Controller(GraphicsPanel p) {
    		this.quantum = 1000;
    		this.panel = p;
    		this.timer = new Timer(quantum, this);
    		// Uncomment the following line to start the timer
    		// timer.start();
    	public void mouseMoved(GraphicsPanel p, int x, int y) {
    		log("moved", x, y);
    	public void mousePressed(GraphicsPanel p, int x, int y) {
    		log("pressed", x, y);
    	public synchronized void mouseReleased(GraphicsPanel p, int x, int y) {
    		log("released", x, y);
    	private static void log(String message, int x, int y) {
    		log(message + "(" + x + "," + y + ")");
    	public static void log(String message) {
    	public synchronized void actionPerformed(ActionEvent arg0) {
    		log("Tick " + tick++);
    	public static void main(String[] args) {
    		YOPS yops = new YOPS(500,500);
    		new Controller(yops.getGraphicsPanel(0));

  3. Define precisely the synchronous events: activities that occur based on the ticks of a clock. How does the ticking clock affect the game's mode changes? Uncomment the code that starts the clock. What do you observe about the mouse actions and clock behaviors when running the code?
    How frequently should the clock tick? What are the tradeoffs between a fast and slow clock?

Last modified 07:13:38 CST 04 November 2008 by Ron K. Cytron