package mobiletris.graphics;
import mobiletris.Size;
import mobiletris.Point;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class Cell {
public static final int BLANK=0;
public static final int X=1;
public static final int O=2;
private int type;
private Size size;
private int background;
private boolean selected;
public Cell(int pBackground){
this.background=pBackground;
this.type=Cell.BLANK;
this.
location=new Point(0,0
);
this.size= new Size(0,0);
this.selected=false;
}
public Point getLocation
() {
return location;
}
public void setLocation
(Point pLocation
) {
this.location = pLocation;
}
public Size getSize() {
return size;
}
public void setSize(Size pSize) {
this.size = pSize;
}
public void setType(int pType){
if(pType==Cell.O || pType==Cell.X){
this.type=pType;
}else{
this.type=Cell.BLANK;
}
}
public boolean isSelected() {
return this.selected;
}
public void setSelected(boolean pSelected) {
this.selected = pSelected;
}
Image image
= Image.
createImage(this.
size.
width,
this.
size.
height);
g.setColor(this.background);
g.fillRect(0, 0, this.size.width, this.size.height);
g.setColor(0xFFFFFF-this.background);
if(this.selected){
g.drawRect(0, 0, this.size.width-1, this.size.height-1);
}
if(this.type==Cell.X){
g.drawLine(this.size.width/4, this.size.height/4, this.size.width-this.size.width/4, this.size.height-this.size.height/4);
g.drawLine(this.size.width/4, this.size.height/2+this.size.height/4, this.size.width-this.size.width/4, this.size.height/4);
}else if(this.type== Cell.O){
g.drawArc(this.size.width/4,this.size.height/4,this.size.width/2, this.size.height/2, 0, 360);
}
return image;
}
public boolean isIn
(Point pPoint
){
if(pPoint.x > this.location.x
&& pPoint.x< this.location.x+this.size.width
&& pPoint.y>this.location.y
&& pPoint.y< this.location.y+this.size.height){
return true;
}
return false;
}
}