import java.io.IOException;
import javax.microedition.lcdui.*;
class MainCanvas extends Canvas implements Runnable
{
int i;
int j;
int k;
int l;
int seed;
int state;
long nextTime;
long now;
Image maze;
Image buf;
Image mazebuf;
Image imgs[];
Graphics bg;
Graphics mg;
Command startCommand;
Command pauseCommand;
int pX;
int pY;
int pDir;
int pLook;
int pCount;
int pState;
int mX;
int mY;
int wantDir;
int dots;
int lives;
int level;
int eatCount;
int gX[];
int gY[];
int gDir[];
int gState[];
int gCount[];
int gLook[];
int sLook[];
int sX[];
int sY[];
int sCount[];
int w;
int h;
int counter;
int oldState;
int speed;
int targetX;
int targetY;
int bestVal;
int bestDir;
int randomness;
Font f;
char scoreChars[];
char levelChars[];
int fH;
int fW;
int lW;
String various[] = {
"E-BEAR presents", "The Develop Men:", "Bryan", "Tony", "Libeia"
};
String dummyScore;
String dummyLevel;
final int dx[] = {
0, 0, 0, -1, 1
};
final int dy[] = {
0, -1, 1, 0, 0
};
final int offsX[] = {
-6, -6, -6, -6, -6, -6, -6, -6, -6, -6,
-6, -6, -6, -5, -6, -6, -6, -7, -7, -7,
-7
};
final int offsY[] = {
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, 0, -2, -2, -2, 0, 0, 0,
0
};
final int bonuses[] = {
8, 1, 2, 4
};
final int dPos[] = {
0, -31, 31, -1, 1
};
int map[] = {
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 8, 8, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 8,
8, 8, 8, 8, 1, 8, 8, 8, 8, 1,
8, 8, 8, 8, 8, 1, 8, 8, 1, 8,
8, 8, 8, 8, 1, 8, 8, 8, 8, 1,
8, 8, 8, 8, 8, 2, 8, 8, 8, 8,
1, 8, 8, 8, 8, 8, 1, 8, 8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8, 8, 8, 1, 8, 8, 1, 8, 8,
1, 8, 8, 8, 8, 8, 8, 8, 1, 1,
1, 1, 1, 1, 8, 8, 1, 1, 1, 1,
8, 8, 1, 1, 1, 1, 8, 8, 1, 1,
1, 1, 1, 1, 8, 8, 8, 8, 8, 1,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
1, 8, 8, 1, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 1, 8, 8, 8, 8, 8,
1, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 1, 8, 8, 1, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 1, 8, 8, 8, 8,
8, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8
};
Thread runner;
int x0;
int y0;
public MainCanvas(Command command, Command command1)
{
seed = 1;
state = 0;
imgs = new Image[27];
gX = new int[3];
gY = new int[3];
gDir = new int[3];
gState = new int[3];
gCount = new int[3];
gLook = new int[3];
sLook = new int[4];
sX = new int[4];
sY = new int[4];
sCount = new int[4];
counter = 0;
f = Font.getFont(0, 0, 0);
scoreChars = new char[6];
levelChars = new char[2];
dummyScore = "00000";
dummyLevel = "00";
//System.out.println("main error 1");
startCommand = command;
pauseCommand = command1;
//System.out.println("main error 2 ");
try
{
maze = Image.createImage("/pacmaze.png");
for(i = 0; i < 27; i++)
imgs[i] = Image.createImage("/img" + i + ".png");
}
catch(IOException ioexception) { }
//System.out.println("main error 3 ");
w = getWidth();
h = getHeight();
if(w > 112)
{
x0 = (w - 112) / 2;
w = 112;
}
if(h > 133)
{
y0 = (h - 133) / 2;
h = 133;
}
//System.out.println("main error 4 ");
buf = Image.createImage(w, h);
mazebuf = Image.createImage(112, 124);
bg = buf.getGraphics();
mg = mazebuf.getGraphics();
//System.out.println("main error 4 ");
bg.setColor(0, 0, 0);
bg.fillRect(0, 0, w, h);
//System.out.println("main error 5 ");
f = Font.getFont(0, 0, 0);
fH = f.getHeight() - 1;
if(fH > 10)
{
f = Font.getFont(0, 0, 8);
fH = f.getHeight() - 1;
if(fH > 11)
fH = 11;
}
//System.out.println("main error 6 ");
bg.setFont(f);
mg.setFont(f);
fW = f.stringWidth(dummyScore);
lW = f.stringWidth(dummyLevel);
prepareIntro();
//System.out.println("main error 7 ");
runner = new Thread(this);
runner.start();
//System.out.println("main error 8 ");
}
public void prepareIntro()
{
//System.out.print