Magnet DesignTopMagnetGame Design

MagnetGame Design

/*
 * Name:  Joe Cool
 * Lab:   Lab 3 (magnets)
 * Purpose:  MagnetGame draws two magnets on the screen.  It handles
 *           mouse input to allow the user to drag and flip the 
 *           magnets.
 */
public class MagnetGame extends WindowController{

    /* The two magnets */
    private Magnet magnet1, magnet2;

    /* These variables are used to remember which magnet the user
       is actively moving and which is reacting to the magnetic field
       of the moving magnet. */
    private Magnet restingMagnet, movingMagnet;

    /* Remember where the mouse was on the last press or drag so
       we know how far to move the magnet. */
    private Location lastPoint;

    /* Remember if we are dragging a magnet. */
    private boolean dragging = false;

    // Draws the magnets on the screen
    public void begin()  {
        // Draw the two magnets
    }

    // Remembers the mouse position and if the user is pointing at
    // one of the magnets.
    // Parameters:  point - where the user pressed the mouse button
    public void onMousePress(Location point) {
        // Remember where the mouse was pressed in lastpoint.
        // If the first magnet  was pressed on,
        //      remember that magnet as the movingMagnet and the other
        //      magnet as the restingMagnet.  Set dragging to true.
        // else if the second magnet was pressed on 
        //      set it as the movingMagnet and the other as the restingMagnet.
        //      set dragging to true.
        // otherwise (we are in neither magnet), 
        //      set dragging to false.
    }

    // If a magnet was selected, drag that magnet.
    // Parameters:  point - the current mouse location
    public void onMouseDrag(Location point)  {
        // If dragging is true, 
        //      determine how far the mouse moved
        //      and move the movingMagnet by that amount.  Then check
        //      to see if that movement causes an interaction with the
        //      resting magnet.
    }

    // If a magnet is clicked on, flip that magnet.
    // Parameters:  point - where the user clicked the mouse
    public void onMouseClick( Location point)  {
        // If the first magnet was clicked on,
        //    flip that magnet and the see if the flip causes an
        //    interaction with the other magnet.
        // else if the second magnet was clicked on
        //    flip that magnet and the see if the flip causes an
        //    interaction with the other magnet.
    }
}

Magnet DesignTopMagnetGame Design