Boxball.javaTopMagnetGame DesignMagnet Design

Magnet Design

/**
 * Class representing a magnet drawn on the screen with north and south poles.
 * Methods are provided that allow it to be moved and determine how it interacts
 * with other magnets.  Also uses Pole class.
 * @author Jane Cool
 */

import objectdraw.*;

public class Magnet {

    // dimensions of magnets
    private final static double MAGNET_WIDTH = 150;
    private final static double MAGNET_HEIGHT = 50;

    // Distance from pole to magnet perimeter
    private static final double POLE_DISTANCE = MAGNET_HEIGHT / 2;

    // Box representing perimeter of magnet
    private FramedRect box; 

    // The poles of the magnet
    private Pole northPole;
    private Pole southPole;

    /**
     *  Creates a new magnet
     * @param location - the upper left corner of the magnet
     * @param canvas - the canvas that the magnet will be displayed on
     */
    public Magnet(Location location, DrawingCanvas canvas) {
        // create box, northPole, and southPole at given coordinates
    }

    /**
     * @return the upper-left coordinates of the magnet
     */
    public Location getLocation() {
        // return location of box;
    }

    /**
     * Move the magnet by xoff to right and yoff down.
     * @param xoff -- distance to move horizontally
     * @param yoff -- distance to move vertically
     */
    public void move(double xoff, double yoff) {
        // move all the pieces by xoff and yoff
    }

    /**
     * Move the upper-left corner of magnet to location point
     * @param point -- place where magnet is to be moved.
     */
    public void moveTo(Location point) {
        // let dx be distance in x direction from current location to point
        // dy be distance in y direction from current location to point
        
        // move this magnet by dx, dy
    }

    /**
     * @param point is location that want to check if it is 
     *          within the magnet outline.
     * @return true iff the given point is within the magnet
     */
    public boolean contains(Location point) {
        // return whether the box contains the point
    }

    /**
     * @return the width of the magnet
     */
    public double getWidth() {
        // return MAGNET_WIDTH;
    }

    /**
     * @return the height of the magnet
     */
    public double getHeight() {
        // return MAGNET_HEIGHT;
    }

    /**
     *  Swaps the north and south poles of the magnet.
     */
    public void flip() {
        // calculate difference d between north & south poles
        // move northPole by d in x direction and southPole by -d
    }

    /**
     * @return north pole of this magnet
     */
    public Pole getNorth() {
        // return the northPole;
    }

    /**
     * @return south pole of this magnet
     */
    public Pole getSouth() {
        // return the southPole;
    }

    /**
     * determine interactions of this magnet with the other magnet,
     * moving the other magnet if attracted or repelled
     * @param other - the other magnet being attracted or repelled
     */
    public void interact(Magnet other) {
        // check whether both pairs of opposite poles attract
        // and whether both pairs of same poles repel each other
    }

}



Boxball.javaTopMagnetGame DesignMagnet Design