package genericcard;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;


/**
 *
 @author Oran
 */
public class GenericCard{
    private int HEIGHT=80,WIDTH=50,ARC=5;
    boolean faceup,sideways;        //a sideways card exchanges HEIGHT and WIDTH
    Point location;
    /** Creates a new instance of GenericCard */
    public GenericCard() {
        location=new Point(0,0);
        faceup=true;
        sideways=false;
    }
    public boolean contains(int x,int y){
        boolean r=false;
        int w,h;
        if(sideways){w=HEIGHT;h=WIDTH;}
        else {w=WIDTH;h=HEIGHT;}
        if(x>=location.x && y>=location.y && x<=location.x+w && y<=location.y+h)r=true;
        return r;
    }
    protected void setHeight(int h){HEIGHT=h;}
    protected void setWidth(int w){WIDTH=w;}
    protected void setDimensions(Dimension d,int a){HEIGHT=d.height;WIDTH=d.width;ARC=a;}
    protected void setArc(int a){ARC=a;}
    public boolean contains(Point p){return contains(p.x,p.y);}
    public int getArc(){return ARC;}
    public int getHeight(){return HEIGHT;}
    public int getWidth(){return WIDTH;}
    public Point getLocation(){Point r=new Point(location);return r;}
    public Dimension getSize(){Dimension d=new Dimension(HEIGHT,WIDTH);return d;}
    public int getX(){return location.x;}
    public int getY(){return location.y;}
    public boolean isFaceup(){return faceup;}
    public boolean isSideways(){return sideways;}
    public void setFaceup(boolean f){faceup=f;}
    public void setSideways(boolean s){sideways=s;}
    public void turnOver(){faceup=!faceup;}
    public void turnSideways(){sideways=!sideways;}
    public void setLocation(int x,int y){location.x=x;location.y=y;}
    public void setLocation(Point p){location=(Point)p.clone();}
    //toString?
    public void translate(int dx,int dy){location.x+=dx;location.y+=dy;}
    public void translate(Point dp){location.x+=dp.x;location.y+=dp.y;}
    public void drawFront(Graphics g){
        int w,h;
        if(sideways){w=HEIGHT;h=WIDTH;}
        else {w=WIDTH;h=HEIGHT;}
        g.setColor(Color.white);
        g.fillRoundRect(location.x,location.y,w,h,ARC,ARC);
    }
    public void drawBack(Graphics g){
        int w,h;
        if(sideways){w=HEIGHT;h=WIDTH;}
        else {w=WIDTH;h=HEIGHT;}
        g.setColor(Color.white);
        g.fillRoundRect(location.x,location.y,w,h,ARC,ARC);
        g.setColor(Color.blue);
        g.fillRoundRect(location.x+ARC,location.y+ARC,w-2*ARC,h-2*ARC,ARC,ARC);
    }
    public void paint(Graphics g){
        if(faceup)drawFront(g);
        else drawBack(g);
    }
}
Java2html