home *** CD-ROM | disk | FTP | other *** search
- package tetris_std;
-
- import java.util.Random;
- import java.util.Timer;
- import java.util.TimerTask;
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Font;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
-
- public class maingame extends Canvas {
- private int width;
- private int height;
- private int scaler;
- private int yoffset;
- private int xoffset;
- private int[][] tetrismat;
- private int level = 1;
- private int reihen = 10;
- private int points;
- private int allreihen = 0;
- // $FF: renamed from: x int
- private int field_0 = 0;
- // $FF: renamed from: y int
- private int field_1 = 0;
- private int clipwidth;
- private int clipheight;
- private int ystart;
- private int yende;
- private int xstart;
- private int xende;
- private int fontxoffset;
- private stein stein;
- private TimerTask timertask = new timertask(this);
- private Timer timer = new Timer();
- private Random random = new Random();
- private static final int XLENGHT = 11;
- private static final int YLENGHT = 21;
- private static final int WAND = 88;
- private static final int BODEN = 77;
- private static final int XSTARTPOS = 6;
- private static final int YSTARTPOS = 1;
- private static final int STARTREIHEN = 10;
- private static final int STARTLEVEL = 1;
- private static final int anker = 20;
- private boolean paintall = true;
- private boolean firstpaint = true;
- private boolean steindown = false;
- private boolean steindown2 = false;
- private boolean asleep = false;
- private boolean gostatus = false;
- private static final Font font = Font.getFont(64, 0, 8);
- private Image dbuffer;
- private Graphics myg;
-
- public void start() {
- this.setFullScreenMode(true);
- this.width = this.getWidth();
- this.height = this.getHeight();
- this.scaler = this.height / 21;
- this.dbuffer = Image.createImage(this.width, this.height);
- this.myg = this.dbuffer.getGraphics();
- this.scaler = this.height / 21;
- this.fontxoffset = this.xoffset + this.scaler * 11;
- this.xoffset = 2;
- this.yoffset = 0;
- this.stein = new stein(this.scaler);
- this.clipwidth = 6 * this.scaler + 3;
- this.clipheight = 6 * this.scaler + 3;
- this.fillmatrix();
- this.stein.neuerstein(6, 1);
- this.changematrix(this.stein);
- this.zeichnen();
- this.timer.schedule(this.timertask, 450L, 450L);
- }
-
- protected void keyPressed(int keyCode) {
- if (!this.asleep) {
- switch (this.getGameAction(keyCode)) {
- case 1:
- this.stein.rotate(1);
- this.changematrix(this.stein);
- this.zeichnen();
- break;
- case 2:
- this.stein.movelinks(1);
- this.changematrix(this.stein);
- this.zeichnen();
- case 3:
- case 4:
- default:
- break;
- case 5:
- this.stein.moverechts(1);
- this.changematrix(this.stein);
- this.zeichnen();
- break;
- case 6:
- this.stein.movedown(1);
-
- while(this.changematrix(this.stein)) {
- this.stein.movedown(1);
- }
-
- this.zeichnen();
- }
- }
-
- }
-
- private synchronized boolean changematrix(stein stein) {
- if (!this.steincheck(stein.gety(), stein.getx(), stein.getrot(), stein.gettyp() + 10, 0, stein.gettyp())) {
- this.paintall = false;
- this.steincheck(stein.getoldy(), stein.getoldx(), stein.getoldrot(), 0, 1, stein.gettyp());
- this.steincheck(stein.gety(), stein.getx(), stein.getrot(), stein.gettyp() + 10, 1, stein.gettyp());
- stein.backupxyr();
- return true;
- } else {
- if (!this.steincheck(stein.getoldy() + 1, stein.getoldx(), stein.getoldrot(), stein.gettyp() + 10, 0, stein.gettyp())) {
- this.paintall = false;
- this.steincheck(stein.getoldy(), stein.getoldx(), stein.getoldrot(), stein.gettyp() + 10, 1, stein.gettyp());
- stein.setbackxyr();
- } else if (stein.getrot() == stein.getoldrot()) {
- this.paintall = true;
- this.steincheck(stein.getoldy(), stein.getoldx(), stein.getoldrot(), stein.gettyp() + 20, 1, stein.gettyp());
-
- for(int i = 0; i < 11; ++i) {
- if (this.tetrismat[2][i] > 20 && this.tetrismat[2][i] != 88) {
- this.levelstate(true);
- }
- }
-
- this.droprow();
- stein.neuerstein(6, 1);
- this.steindown = true;
- if (this.changematrix(stein)) {
- ++this.points;
- }
- } else {
- this.paintall = false;
- this.steincheck(stein.getoldy(), stein.getoldx(), stein.getoldrot(), stein.gettyp() + 10, 1, stein.gettyp());
- stein.setbackxyr();
- }
-
- return false;
- }
- }
-
- private boolean steincheck(int y, int x, int drehung, int pattern, int doit, int typ) {
- switch (typ) {
- case 1:
- switch (drehung) {
- case 0:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y][x - 1] <= 20 && this.tetrismat[y + 1][x] <= 20 && this.tetrismat[y + 1][x - 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y][x - 1] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- this.tetrismat[y + 1][x - 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- default:
- return true;
- }
- case 2:
- switch (drehung) {
- case 0:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y][x - 1] <= 20 && this.tetrismat[y + 1][x] <= 20 && this.tetrismat[y + 1][x + 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y][x - 1] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- this.tetrismat[y + 1][x + 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 1:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y + 1][x] <= 20 && this.tetrismat[y - 1][x + 1] <= 20 && this.tetrismat[y][x + 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- this.tetrismat[y - 1][x + 1] = pattern;
- this.tetrismat[y][x + 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- default:
- return true;
- }
- case 3:
- switch (drehung) {
- case 0:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y][x - 1] <= 20 && this.tetrismat[y][x + 1] <= 20 && this.tetrismat[y + 1][x - 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y][x - 1] = pattern;
- this.tetrismat[y][x + 1] = pattern;
- this.tetrismat[y + 1][x - 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 1:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y - 1][x] <= 20 && this.tetrismat[y + 1][x] <= 20 && this.tetrismat[y + 1][x + 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y - 1][x] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- this.tetrismat[y + 1][x + 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 2:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y][x - 1] <= 20 && this.tetrismat[y][x + 1] <= 20 && this.tetrismat[y - 1][x + 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y][x - 1] = pattern;
- this.tetrismat[y][x + 1] = pattern;
- this.tetrismat[y - 1][x + 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 3:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y - 1][x] <= 20 && this.tetrismat[y + 1][x] <= 20 && this.tetrismat[y - 1][x - 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y - 1][x] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- this.tetrismat[y - 1][x - 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- default:
- return true;
- }
- case 4:
- switch (drehung) {
- case 0:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y][x + 1] <= 20 && this.tetrismat[y + 1][x] <= 20 && this.tetrismat[y + 1][x - 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y][x + 1] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- this.tetrismat[y + 1][x - 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 1:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y + 1][x + 1] <= 20 && this.tetrismat[y][x + 1] <= 20 && this.tetrismat[y - 1][x] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y + 1][x + 1] = pattern;
- this.tetrismat[y][x + 1] = pattern;
- this.tetrismat[y - 1][x] = pattern;
- }
-
- return false;
- }
-
- return true;
- default:
- return true;
- }
- case 5:
- switch (drehung) {
- case 0:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y][x - 1] <= 20 && this.tetrismat[y][x - 2] <= 20 && this.tetrismat[y][x + 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y][x - 1] = pattern;
- this.tetrismat[y][x - 2] = pattern;
- this.tetrismat[y][x + 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 1:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y + 1][x] <= 20 && this.tetrismat[y + 2][x] <= 20 && this.tetrismat[y - 1][x] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- this.tetrismat[y + 2][x] = pattern;
- this.tetrismat[y - 1][x] = pattern;
- }
-
- return false;
- }
-
- return true;
- default:
- return true;
- }
- case 6:
- switch (drehung) {
- case 0:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y][x - 1] <= 20 && this.tetrismat[y][x + 1] <= 20 && this.tetrismat[y + 1][x + 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y][x - 1] = pattern;
- this.tetrismat[y][x + 1] = pattern;
- this.tetrismat[y + 1][x + 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 1:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y - 1][x] <= 20 && this.tetrismat[y + 1][x] <= 20 && this.tetrismat[y - 1][x + 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y - 1][x] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- this.tetrismat[y - 1][x + 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 2:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y][x - 1] <= 20 && this.tetrismat[y][x + 1] <= 20 && this.tetrismat[y - 1][x - 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y][x - 1] = pattern;
- this.tetrismat[y][x + 1] = pattern;
- this.tetrismat[y - 1][x - 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 3:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y - 1][x] <= 20 && this.tetrismat[y + 1][x] <= 20 && this.tetrismat[y + 1][x - 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y - 1][x] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- this.tetrismat[y + 1][x - 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- default:
- return true;
- }
- case 7:
- switch (drehung) {
- case 0:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y][x - 1] <= 20 && this.tetrismat[y][x + 1] <= 20 && this.tetrismat[y + 1][x] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y][x - 1] = pattern;
- this.tetrismat[y][x + 1] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 1:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y - 1][x] <= 20 && this.tetrismat[y + 1][x] <= 20 && this.tetrismat[y][x + 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y - 1][x] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- this.tetrismat[y][x + 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 2:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y][x - 1] <= 20 && this.tetrismat[y][x + 1] <= 20 && this.tetrismat[y - 1][x] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y][x - 1] = pattern;
- this.tetrismat[y][x + 1] = pattern;
- this.tetrismat[y - 1][x] = pattern;
- }
-
- return false;
- }
-
- return true;
- case 3:
- if (this.tetrismat[y][x] <= 20 && this.tetrismat[y - 1][x] <= 20 && this.tetrismat[y + 1][x] <= 20 && this.tetrismat[y][x - 1] <= 20) {
- if (doit == 1) {
- this.tetrismat[y][x] = pattern;
- this.tetrismat[y - 1][x] = pattern;
- this.tetrismat[y + 1][x] = pattern;
- this.tetrismat[y][x - 1] = pattern;
- }
-
- return false;
- }
-
- return true;
- }
- }
-
- return true;
- }
-
- private void droprow() {
- for(int y = 1; y < 21; ++y) {
- boolean leerstelle = false;
-
- for(int x = 1; x < 11; ++x) {
- if (this.tetrismat[y][x] == 0) {
- leerstelle = true;
- }
- }
-
- if (!leerstelle) {
- while(y > 1) {
- leerstelle = false;
-
- for(int var4 = 0; var4 <= 11; ++var4) {
- this.tetrismat[y][var4] = this.tetrismat[y - 1][var4];
- }
-
- --y;
- }
-
- this.levelstate(false);
-
- for(int var5 = 0; var5 <= 11; ++var5) {
- this.tetrismat[y][var5] = 0;
- }
-
- for(y = 0; y <= 21; ++y) {
- this.tetrismat[y][0] = 88;
- this.tetrismat[y][11] = 88;
- }
-
- this.droprow();
- }
- }
-
- }
-
- private void levelstate(boolean gameover) {
- if (!gameover) {
- if (this.reihen > 1) {
- --this.reihen;
- ++this.allreihen;
- } else {
- this.reihen = 10;
- if (this.level < 9) {
- ++this.level;
- this.timertask.cancel();
- this.timertask = new timertask(this);
- switch (this.level) {
- case 2:
- this.timer.schedule(this.timertask, 0L, 350L);
- break;
- case 3:
- this.timer.schedule(this.timertask, 0L, 300L);
- break;
- case 4:
- this.timer.schedule(this.timertask, 0L, 270L);
- break;
- case 5:
- this.timer.schedule(this.timertask, 0L, 250L);
- break;
- case 6:
- this.timer.schedule(this.timertask, 0L, 230L);
- break;
- case 7:
- this.timer.schedule(this.timertask, 0L, 220L);
- break;
- case 8:
- this.timer.schedule(this.timertask, 0L, 210L);
- break;
- case 9:
- this.timer.schedule(this.timertask, 0L, 200L);
- }
- }
- }
- } else {
- this.fillmatrix();
- this.gostatus = true;
- this.level = 1;
- this.reihen = 10;
- this.allreihen = 0;
- this.points = 0;
- this.gosleep();
- }
-
- }
-
- private void fillmatrix() {
- this.tetrismat = new int[22][12];
-
- for(int i = 0; i <= 21; ++i) {
- for(int j = 0; j <= 11; ++j) {
- this.tetrismat[21][11] = 0;
- }
- }
-
- for(int var3 = 0; var3 <= 11; ++var3) {
- this.tetrismat[21][var3] = 77;
- }
-
- for(int var4 = 0; var4 <= 21; ++var4) {
- this.tetrismat[var4][0] = 88;
- this.tetrismat[var4][11] = 88;
- }
-
- }
-
- protected synchronized void paint(Graphics g) {
- if (!this.paintall && !this.steindown) {
- if (this.firstpaint) {
- g.setClip(0, 0, this.width, this.height);
- this.firstpaint = false;
- } else {
- this.field_0 = this.xoffset + (this.stein.getx() - 3) * this.scaler;
- this.field_1 = this.yoffset + (this.stein.gety() - 3) * this.scaler;
- g.setClip(this.field_0, this.field_1, this.clipwidth, this.clipheight);
- }
- } else {
- g.setClip(this.xoffset + this.scaler, this.yoffset + this.scaler, this.width, this.height);
- this.steindown = false;
- }
-
- g.drawImage(this.dbuffer, 0, 0, 20);
- }
-
- private synchronized void zeichnen() {
- this.myg.setColor(16777215);
- this.myg.fillRect(0, 0, this.width, this.height);
- if (this.asleep && !this.gostatus) {
- try {
- Image picpause = Image.createImage("/tetris_std/paused.png");
- this.myg.drawImage(picpause, (this.width - picpause.getWidth()) / 2, (this.height - picpause.getHeight()) / 2, 20);
- } catch (Exception var4) {
- this.myg.drawString("- Pause -", this.width / 2, this.height / 2, 20);
- }
- } else if (this.gostatus) {
- try {
- Image picgameover = Image.createImage("/tetris_std/goscreen.png");
- this.myg.drawImage(picgameover, (this.width - picgameover.getWidth()) / 2, (this.height - picgameover.getHeight()) / 2, 20);
- } catch (Exception var3) {
- this.myg.drawString("- Game over -", this.width / 2, this.height / 2, 20);
- }
- } else {
- this.myg.setColor(14869218);
- this.myg.fillRect(this.xoffset + this.scaler + 1, this.yoffset + this.scaler + 1, 11 * this.scaler - this.scaler - 1, 21 * this.scaler - this.scaler - 1);
- this.myg.setColor(0);
- this.myg.drawRect(this.xoffset + this.scaler, this.yoffset + this.scaler, 11 * this.scaler - this.scaler, 21 * this.scaler - this.scaler);
- this.myg.setFont(font);
- this.myg.drawString(" Rows", this.fontxoffset, this.yoffset + this.scaler, 20);
- this.myg.drawString(" " + this.allreihen, this.fontxoffset, this.yoffset + this.scaler + font.getHeight(), 20);
- this.myg.drawString(" Level", this.fontxoffset, this.yoffset + this.scaler + font.getHeight() * 2, 20);
- this.myg.drawString(" " + this.level, this.fontxoffset, this.yoffset + this.scaler + font.getHeight() * 3, 20);
- this.myg.drawString(" Points", this.fontxoffset, this.yoffset + this.scaler + font.getHeight() * 4, 20);
- this.myg.drawString(" " + this.points, this.fontxoffset, this.yoffset + this.scaler + font.getHeight() * 5, 20);
- if (!this.paintall && !this.steindown && !this.firstpaint) {
- this.ystart = this.stein.gety() - 3;
- this.xstart = this.stein.getx() - 3;
- this.yende = this.stein.gety() + 3;
- this.xende = this.stein.getx() + 3;
- if (this.ystart < 0) {
- this.ystart = 0;
- }
-
- if (this.xstart < 0) {
- this.xstart = 0;
- }
-
- if (this.yende > 21) {
- this.yende = 21;
- }
-
- if (this.xende > 11) {
- this.xende = 11;
- }
- } else {
- this.ystart = 0;
- this.xstart = 0;
- this.yende = 21;
- this.xende = 11;
- }
-
- for(this.field_1 = this.ystart; this.field_1 <= this.yende; ++this.field_1) {
- for(this.field_0 = this.xstart; this.field_0 <= this.xende; ++this.field_0) {
- if (this.tetrismat[this.field_1][this.field_0] > 10 && this.tetrismat[this.field_1][this.field_0] < 30) {
- this.myg.drawImage(this.stein.getImage(this.tetrismat[this.field_1][this.field_0]), this.xoffset + this.field_0 * this.scaler, this.yoffset + this.field_1 * this.scaler, 20);
- }
- }
- }
- }
-
- this.repaint();
- }
-
- public void wakemeup() {
- this.gostatus = false;
- this.asleep = false;
- this.firstpaint = true;
- this.zeichnen();
- this.timertask.cancel();
- this.timertask = new timertask(this);
- switch (this.level) {
- case 1:
- this.timer.schedule(this.timertask, 0L, 450L);
- break;
- case 2:
- this.timer.schedule(this.timertask, 0L, 350L);
- break;
- case 3:
- this.timer.schedule(this.timertask, 0L, 300L);
- break;
- case 4:
- this.timer.schedule(this.timertask, 0L, 270L);
- break;
- case 5:
- this.timer.schedule(this.timertask, 0L, 250L);
- break;
- case 6:
- this.timer.schedule(this.timertask, 0L, 230L);
- break;
- case 7:
- this.timer.schedule(this.timertask, 0L, 220L);
- break;
- case 8:
- this.timer.schedule(this.timertask, 0L, 210L);
- break;
- case 9:
- this.timer.schedule(this.timertask, 0L, 200L);
- }
-
- }
-
- public void gosleep() {
- this.timertask.cancel();
- this.asleep = true;
- this.firstpaint = true;
- this.zeichnen();
- }
-
- // $FF: synthetic method
- static stein access$000(maingame x0) {
- return x0.stein;
- }
-
- // $FF: synthetic method
- static boolean access$100(maingame x0, stein x1) {
- return x0.changematrix(x1);
- }
-
- // $FF: synthetic method
- static void access$200(maingame x0) {
- x0.zeichnen();
- }
- }
-