home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 64 / CDPRO64.iso / JUEGOS / java / tobitris / tobitris.jar / tetris_std / stein.class (.txt) < prev   
Encoding:
Java Class File  |  2005-06-27  |  4.4 KB  |  238 lines

  1. package tetris_std;
  2.  
  3. import java.util.Random;
  4. import javax.microedition.lcdui.Graphics;
  5. import javax.microedition.lcdui.Image;
  6.  
  7. public class stein {
  8.    Graphics imageGraphics;
  9.    Image stein1;
  10.    Image stein2;
  11.    Image stein3;
  12.    Image stein4;
  13.    Image stein5;
  14.    Image stein6;
  15.    Image stein7;
  16.    private int xpos;
  17.    private int ypos;
  18.    private int typ;
  19.    private int rotation;
  20.    private int oldxpos;
  21.    private int oldypos;
  22.    private int oldrotation;
  23.    private int farbe;
  24.    Random rand = new Random();
  25.  
  26.    public stein(int scaler) {
  27.       this.stein1 = Image.createImage(scaler + 1, scaler + 1);
  28.       this.stein2 = Image.createImage(scaler + 1, scaler + 1);
  29.       this.stein3 = Image.createImage(scaler + 1, scaler + 1);
  30.       this.stein4 = Image.createImage(scaler + 1, scaler + 1);
  31.       this.stein5 = Image.createImage(scaler + 1, scaler + 1);
  32.       this.stein6 = Image.createImage(scaler + 1, scaler + 1);
  33.       this.stein7 = Image.createImage(scaler + 1, scaler + 1);
  34.       this.createpics(scaler);
  35.    }
  36.  
  37.    private void createpics(int scaler) {
  38.       for(int i = 1; i <= 7; ++i) {
  39.          switch (i) {
  40.             case 1:
  41.                this.imageGraphics = this.stein1.getGraphics();
  42.                break;
  43.             case 2:
  44.                this.imageGraphics = this.stein2.getGraphics();
  45.                break;
  46.             case 3:
  47.                this.imageGraphics = this.stein3.getGraphics();
  48.                break;
  49.             case 4:
  50.                this.imageGraphics = this.stein4.getGraphics();
  51.                break;
  52.             case 5:
  53.                this.imageGraphics = this.stein5.getGraphics();
  54.                break;
  55.             case 6:
  56.                this.imageGraphics = this.stein6.getGraphics();
  57.                break;
  58.             case 7:
  59.                this.imageGraphics = this.stein7.getGraphics();
  60.          }
  61.  
  62.          this.imageGraphics.setColor(this.privategetcolor(i));
  63.          this.imageGraphics.fillRect(0, 0, scaler, scaler);
  64.          this.imageGraphics.setColor(0);
  65.          this.imageGraphics.drawRect(0, 0, scaler, scaler);
  66.       }
  67.  
  68.    }
  69.  
  70.    public Image getImage(int pattern) {
  71.       if (pattern != 21 && pattern != 11) {
  72.          if (pattern != 22 && pattern != 12) {
  73.             if (pattern != 23 && pattern != 13) {
  74.                if (pattern != 24 && pattern != 14) {
  75.                   if (pattern != 25 && pattern != 15) {
  76.                      if (pattern != 26 && pattern != 16) {
  77.                         return pattern != 27 && pattern != 17 ? this.stein4 : this.stein7;
  78.                      } else {
  79.                         return this.stein6;
  80.                      }
  81.                   } else {
  82.                      return this.stein5;
  83.                   }
  84.                } else {
  85.                   return this.stein4;
  86.                }
  87.             } else {
  88.                return this.stein3;
  89.             }
  90.          } else {
  91.             return this.stein2;
  92.          }
  93.       } else {
  94.          return this.stein1;
  95.       }
  96.    }
  97.  
  98.    public void neuerstein(int posx, int posy) {
  99.       this.typ = this.rand.nextInt() % 7 + 1;
  100.       this.xpos = posx;
  101.       this.ypos = posy;
  102.       this.oldypos = posy;
  103.       this.oldxpos = posx;
  104.       this.rotation = 0;
  105.       this.oldrotation = 0;
  106.    }
  107.  
  108.    public void setbackxyr() {
  109.       this.xpos = this.oldxpos;
  110.       this.ypos = this.oldypos;
  111.       this.rotation = this.oldrotation;
  112.    }
  113.  
  114.    public void backupxyr() {
  115.       this.oldxpos = this.xpos;
  116.       this.oldypos = this.ypos;
  117.       this.oldrotation = this.rotation;
  118.    }
  119.  
  120.    public void movelinks(int steps) {
  121.       this.xpos -= steps;
  122.    }
  123.  
  124.    public void moverechts(int steps) {
  125.       this.xpos += steps;
  126.    }
  127.  
  128.    public void movedown(int steps) {
  129.       this.ypos += steps;
  130.    }
  131.  
  132.    public void rotate(int steps) {
  133.       switch (this.typ) {
  134.          case 1:
  135.             this.rotation = (this.rotation + steps) % 1;
  136.             break;
  137.          case 2:
  138.             this.rotation = (this.rotation + steps) % 2;
  139.             break;
  140.          case 3:
  141.             this.rotation = (this.rotation + steps) % 4;
  142.             break;
  143.          case 4:
  144.             this.rotation = (this.rotation + steps) % 2;
  145.             break;
  146.          case 5:
  147.             this.rotation = (this.rotation + steps) % 2;
  148.             break;
  149.          case 6:
  150.             this.rotation = (this.rotation + steps) % 4;
  151.             break;
  152.          case 7:
  153.             this.rotation = (this.rotation + steps) % 4;
  154.       }
  155.  
  156.    }
  157.  
  158.    public int getcolor(int pattern) {
  159.       if (pattern != 21 && pattern != 11) {
  160.          if (pattern != 22 && pattern != 12) {
  161.             if (pattern != 23 && pattern != 13) {
  162.                if (pattern != 24 && pattern != 14) {
  163.                   if (pattern != 25 && pattern != 15) {
  164.                      if (pattern != 26 && pattern != 16) {
  165.                         if (pattern == 27 || pattern == 17) {
  166.                            this.farbe = 6710886;
  167.                         }
  168.                      } else {
  169.                         this.farbe = 3394713;
  170.                      }
  171.                   } else {
  172.                      this.farbe = 10079487;
  173.                   }
  174.                } else {
  175.                   this.farbe = 16737894;
  176.                }
  177.             } else {
  178.                this.farbe = 13408767;
  179.             }
  180.          } else {
  181.             this.farbe = 6724044;
  182.          }
  183.       } else {
  184.          this.farbe = 16777113;
  185.       }
  186.  
  187.       return this.farbe;
  188.    }
  189.  
  190.    private int privategetcolor(int type) {
  191.       if (type == 1) {
  192.          this.farbe = 16777113;
  193.       } else if (type == 2) {
  194.          this.farbe = 6724044;
  195.       } else if (type == 3) {
  196.          this.farbe = 13408767;
  197.       } else if (type == 4) {
  198.          this.farbe = 16737894;
  199.       } else if (type == 5) {
  200.          this.farbe = 10079487;
  201.       } else if (type == 6) {
  202.          this.farbe = 3394713;
  203.       } else if (type == 7) {
  204.          this.farbe = 6710886;
  205.       }
  206.  
  207.       return this.farbe;
  208.    }
  209.  
  210.    public int getx() {
  211.       return this.xpos;
  212.    }
  213.  
  214.    public int gety() {
  215.       return this.ypos;
  216.    }
  217.  
  218.    public int getrot() {
  219.       return this.rotation;
  220.    }
  221.  
  222.    public int gettyp() {
  223.       return this.typ;
  224.    }
  225.  
  226.    public int getoldx() {
  227.       return this.oldxpos;
  228.    }
  229.  
  230.    public int getoldy() {
  231.       return this.oldypos;
  232.    }
  233.  
  234.    public int getoldrot() {
  235.       return this.oldrotation;
  236.    }
  237. }
  238.