Magnet DesignTopMagnetGame Design

MagnetGame Design

/**
 * Class that creates two magnets that may be dragged around the screen
 * or clicked on to flip the polarity.  When magnets are near each other
 * they are attracted or repelled.
 * @author Jane Cool
 */

import objectdraw.*;

public class MagnetGame extends WindowController {

    // starting locations for the two magnets
    private static final Location MAGNET1_LOC = new Location(50, 100);
    private static final Location MAGNET2_LOC = new Location(250, 100);

    // Magnet currently being dragged, and one at rest
    private Magnet movingMagnet, restingMagnet; 

    // last location where mouse was
    private Location lastPoint; 

    // Is a magnet being dragged?
    private boolean dragging; 

    /**
     *  Create magnets and have them interact
     */
    public void begin() {
        // Create 2 magnets at MAGNET1_LOC and MAGNET2_LOC
    }

    /**
     *  Determine which, if any, magnet mouse is on
     *  dragging set to true iff mouse pressed on a magnet
     *  @param point - location where mouse is pressed.
     */
    public void onMousePress(Location point) {
        // remember point in lastPoint for dragging later
        // if point in movingMagnet then set dragging true
        // else if point in restingMagnet, set dragging true
        //       and swap names of two magnets so one containing
        //       point is now movingMagnet
        // else set dragging false
    }

    /**
     *  Drag selected magnet as far as mouse is dragged
     *  @param point -- location where mouse dragged to
     */
    public void onMouseDrag(Location point) {
        // if dragging a magnet then
        //     move movingMagnet by distance from lastPoint
        //     test its interaction with restingMagnet;
        //     remember point in lastPoint;
        }
    }

    /**
     *  Flip magnet if it is clicked on
     *  @param point -- location where mouse is clicked
     */
    public void onMouseClick(Location point) {
        // if clicked on the movingMagnet then flip it
        //  & test its interaction with the restingMagnet);
    }

}


Magnet DesignTopMagnetGame Design