Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
MobileTris - Cell.java

Cell.java

Caricato da:
Scarica il programma completo

  1. package mobiletris.graphics;
  2.  
  3. import mobiletris.Size;
  4. import mobiletris.Point;
  5. import javax.microedition.lcdui.Graphics;
  6. import javax.microedition.lcdui.Image;
  7.  
  8. public class Cell {
  9.  
  10.     public static final int BLANK=0;
  11.     public static final int X=1;
  12.     public static final int O=2;
  13.  
  14.     private int type;
  15.     private Point location;
  16.     private Size size;
  17.     private int background;
  18.     private boolean selected;
  19.  
  20.     public Cell(int pBackground){
  21.         this.background=pBackground;
  22.         this.type=Cell.BLANK;
  23.         this.location=new Point(0,0);
  24.         this.size= new Size(0,0);
  25.         this.selected=false;
  26.     }
  27.  
  28.     public Point getLocation() {
  29.         return location;
  30.     }
  31.  
  32.     public void setLocation(Point pLocation) {
  33.         this.location = pLocation;
  34.     }
  35.  
  36.     public Size getSize() {
  37.         return size;
  38.     }
  39.  
  40.     public void setSize(Size pSize) {
  41.         this.size = pSize;
  42.     }
  43.  
  44.     public void setType(int pType){
  45.         if(pType==Cell.O || pType==Cell.X){
  46.             this.type=pType;
  47.         }else{
  48.             this.type=Cell.BLANK;
  49.         }
  50.     }
  51.  
  52.     public boolean isSelected() {
  53.         return this.selected;
  54.     }
  55.  
  56.     public void setSelected(boolean pSelected) {
  57.         this.selected = pSelected;
  58.     }
  59.  
  60.  
  61.  
  62.     public Image getImage(){
  63.         Image image= Image.createImage(this.size.width, this.size.height);
  64.         Graphics g=image.getGraphics();
  65.         g.setColor(this.background);
  66.         g.fillRect(0, 0, this.size.width, this.size.height);
  67.         g.setColor(0xFFFFFF-this.background);
  68.         if(this.selected){
  69.             g.drawRect(0, 0, this.size.width-1, this.size.height-1);
  70.         }
  71.         if(this.type==Cell.X){
  72.             g.drawLine(this.size.width/4, this.size.height/4, this.size.width-this.size.width/4, this.size.height-this.size.height/4);
  73.             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);
  74.         }else if(this.type== Cell.O){
  75.             g.drawArc(this.size.width/4,this.size.height/4,this.size.width/2, this.size.height/2, 0, 360);
  76.         }
  77.         return image;
  78.     }
  79.  
  80.     public boolean isIn(Point pPoint){
  81.         if(pPoint.x > this.location.x
  82.            && pPoint.x< this.location.x+this.size.width
  83.            && pPoint.y>this.location.y
  84.            && pPoint.y< this.location.y+this.size.height){
  85.             return true;
  86.         }
  87.         return false;
  88.     }
  89. }