|
游戏页
源程序
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.image.*;
public final class puzz extends Applet
implements Runnable
{
int i = 0;
int j = 0;
int k = 0;
int l = 0;
int li = 0;
int downX = 0;
int downY = 0;
int slidePiece = 0;
int slideH = 0;
int slideV = 0;
int displace = 0;
int dragging = 0;
int seed = 0;
int counter = 0;
int goalsDone = 0;
int shades[] = {
0, 0, 1, 0, 1, 1, 0, 1, 0, 0,
1, 0, 1, 1, 0, 1, 0
};
int shadows[] = {
0, 0, 0, 2, 0, 4, 1, 3
};
int autoDisplace[] = {
0, 5, 12, 21, 32, 32, 27, 20, 11, 0
};
int subgoals[] = {
1, 0, 2, 0, 3, 4, 0, 5, 0, 6,
0, 7, 8, 0, 9, 13, 0, 10, 14, 0,
11, 12, 15, 0, 16
};
int detour1[] = {
11, 10, 6, 7, 11, 10, 6, 7, 3, 2,
6, 7, 11, -1
};
int detour2[] = {
15, 14, 10, 11, 15, 14, 10, 11, 7, 6,
10, 11, 15, -1
};
int detour3[] = {
6, 2, 3, 7, -1
};
int detour4[] = {
3, 7, -1
};
int detour5[] = {
10, 6, 7, 11, -1
};
int detour6[] = {
7, 11, -1
};
int detour7[] = {
13, 12, 8, 9, -1
};
int detour8[] = {
8, 9, -1
};
int detour9[] = {
10, 14, 13, 9, 10, 14, 13, 9, 8, 12,
13, 9, 10, -1
};
int detour10[] = {
14, 13, 9, 10, -1
};
int detour11[] = {
9, 10, -1
};
int detour12[] = {
11, 15, 14, 10, 11, 15, 14, 10, 9, 13,
14, 10, 11, -1
};
int roundabout[] = {
11, 10, 14, 15, -1
};
int roundDisp[] = {
-4, -3, 1, 5, 4, 3, -1, -5, -4, -3,
1, 5, 4, 3, -1, -5, -4, -3, 1, 5,
4, 3, -1, -5, -4
};
int rounddx[] = {
0, 1, 1, 1, 0, -1, -1, -1, 0, 1,
1, 1, 0, -1, -1, -1, 0, 1, 1, 1,
0, -1, -1, -1, 0
};
int moves[] = null;
int moveCount = 0;
int holder[] = null;
int current = 0;
int moveNum = 0;
int map[] = null;
int ppath[] = null;
boolean vertical = false;
boolean dragControl = false;
boolean automatic = false;
boolean oldDragControl = false;
Image background = null;
Image vert = null;
Image hori = null;
Image smalls[] = null;
Color backCol = null;
Graphics backG = null;
Graphics vertG = null;
Graphics horiG = null;
MediaTracker mt = null;
ImageProducer improd = null;
Thread life = null;
long nextTime = 0;
AudioClip click = null;
AudioClip slide = null;
public void init()
{
String s = getParameter("bgcolor");
if(s != null && s.length() == 7)
{
int ai[] = new int[3];
for(i = 0; i < 3; i++)
{
j = Character.toLowerCase(s.charAt(1 + i * 2));
if(j >= 48 && j <= 57)
k = j - 48;
else
k = (10 + j) - 97;
j = Character.toLowerCase(s.charAt(2 + i * 2));
if(j >= 48 && j <= 57)
k = 16 * k + (j - 48);
else
k = 16 * k + ((10 + j) - 97);
ai = k;
}
backCol = new Color(ai[0], ai[1], ai[2]);
}
mt = new MediaTracker(this);
background = createImage(129, 128);
backG = background.getGraphics();
vert = createImage(38, 70);
vertG = vert.getGraphics();
hori = createImage(70, 38);
horiG = hori.getGraphics();
smalls = new Image[31];
Image image = getImage(getCodeBase(), "pieces.gif");
mt.addImage(image, 0);
showStatus("Loading image");
try
{
mt.waitForID(0);
}
catch(InterruptedException _ex) { }
improd = image.getSource();
for(i = 0; i < 2; i++)
for(j = 0; j < 5; j++)
{
smalls[i * 5 + j] = createImage(new FilteredImageSource(improd, new CropImageFilter(16 * (j % 3), 16 * (j / 3) + 32 * i, 16, 16)));
mt.addImage(smalls[i * 5 + j], 1);
}
smalls[10] = createImage(new FilteredImageSource(improd, new CropImageFilter(0, 64, 32, 32)));
smalls[11] = createImage(new FilteredImageSource(improd, new CropImageFilter(0, 96, 32, 32)));
smalls[12] = createImage(new FilteredImageSource(improd, new CropImageFilter(32, 64, 4, 38)));
smalls[13] = createImage(new FilteredImageSource(improd, new CropImageFilter(36, 64, 4, 36)));
smalls[14] = createImage(new FilteredImageSource(improd, new CropImageFilter(0, 128, 38, 4)));
smalls[15] = createImage(new FilteredImageSource(improd, new CropImageFilter(0, 132, 37, 4)));
for(i = 10; i < 16; i++)
mt.addImage(smalls, 1);
for(i = 0; i < 15; i++)
{
smalls[16 + i] = createImage(new FilteredImageSource(improd, new CropImageFilter(23 * (i & 0x1), 136 + 14 * (i / 2), 23, 14)));
mt.addImage(smalls[16 + i], 1);
}
try
{
mt.waitForID(1);
}
catch(InterruptedException _ex) { }
for(i = 0; i < 6; i++)
{
map = 1;
map[i * 6] = 1;
}
for(i = 0; i < 4; i++)
for(j = 0; j < 4; j++)
map[7 + i * 6 + j] = i * 4 + j + 1 & 0xf;
click = getAudioClip(getCodeBase(), "click.au");
slide = getAudioClip(getCodeBase(), "slide.au");
buildBackground();
showStatus("Done");
}
public void buildBackground()
{
backG.setColor(backCol);
backG.fillRect(0, 0, 129, 128);
for(i = 0; i < 4; i++)
{
backG.drawImage(smalls[12], 125, i * 32, this);
backG.drawImage(smalls[14], i * 32, 124, this);
}
for(i = 0; i < 5; i++)
{
if(map[4 + 6 * i] > 0)
backG.drawImage(smalls[13], 125, (i - 1) * 32, this);
if(map[24 + i] > 0)
backG.drawImage(smalls[15], (i - 1) * 32, 124, this);
}
for(i = 0; i < 4; i++)
for(j = 0; j < 4; j++)
{
k = 0;
if(map[i * 6 + j] > 0)
k += 2;
if(map[1 + i * 6 + j] > 0)
k++;
if(map[6 + i * 6 + j] > 0)
k += 4;
l = shadows[k];
k = map[7 + i * 6 + j];
if(k > 0)
{
l += 5 * shades[k];
backG.drawImage(smalls[l], j * 32 - 3, i * 32 - 4, this);
}
}
for(i = 0; i < 4; i++)
for(j = 0; j < 4; j++)
{
k = map[7 + i * 6 + j];
if(k > 0)
{
backG.drawImage(smalls[10 + shades[k]], j * 32, i * 32, this);
backG.drawImage(smalls[15 + k], 5 + j * 32, 9 + i * 32, this);
}
}
}
public void drawVertical(int i1, int j1, int k1, int l1)
{
vertG.setColor(backCol);
vertG.fillRect(0, 0, 38, 70);
if(k1 > 3)
vertG.drawImage(smalls[5 * shades[l1] + 1], 0, k1 - 1, this);
else
vertG.drawImage(smalls[5 * shades[l1] + 3], 0, k1 - 1, this);
if(i1 == 3)
{
vertG.drawImage(smalls[12], 32, 0, this);
vertG.drawImage(smalls[12], 32, 35, this);
vertG.drawImage(smalls[13], 32, -29, this);
}
if(j1 == 2)
{
vertG.drawImage(smalls[14], 0, 63, this);
vertG.drawImage(smalls[15], -29, 63, this);
}
if(i1 == 3)
{
vertG.drawImage(smalls[13], 32, 3 + k1, this);
}
else
{
k = 2;
if(k1 < 8)
k = 3;
int i2;
k += 5 * shades[map[7 + (i2 = i1 + 1) + 6 * j1]];
vertG.drawImage(smalls[k], 32, -1, this);
k = 2;
if(k1 > 7)
if(k1 < 29)
k = 3;
else
k = 4;
int i3;
k += 5 * shades[map[7 + (i2 = i1 + 1) + 6 * (i3 = j1 + 1)]];
vertG.drawImage(smalls[k], 32, 31, this);
}
if(j1 == 2)
{
if(k1 > 28)
vertG.drawImage(smalls[15], 3 + (32 - k1), 63, this);
}
else
{
k = 1;
if(k1 > 28)
k = 3;
int j2;
k += 5 * shades[map[7 + i1 + 6 * (j2 = j1 + 2)]];
vertG.drawImage(smalls[k], 0, 63, this);
}
if(i1 < 3 && j1 < 2)
{
k = 4;
if(k1 > 28)
k = 3;
int k2;
int j3;
k += 5 * shades[map[7 + (k2 = i1 + 1) + 6 * (j3 = j1 + 2)]];
vertG.drawImage(smalls[k], 32, 63, this);
}
for(i = -1; i < 3; i++)
for(j = -1; j < 2; j++)
{
int l2 = i1 + j;
int k3 = j1 + i;
if(map[7 + l2 + 6 * k3] > 0)
vertG.drawImage(smalls[10 + shades[map[7 + (l2 = i1 + j) + 6 * (k3 = j1 + i)]]], 3 + 32 * j, 3 + 32 * i, this);
}
vertG.drawImage(smalls[10 + shades[l1]], 3, 3 + k1, this);
vertG.drawImage(smalls[15 + l1], 8, 12 + k1, this);
}
public void drawHorizontal(int i1, int j1, int k1, int l1)
{
horiG.setColor(backCol);
horiG.fillRect(0, 0, 70, 38);
if(k1 > 3)
horiG.drawImage(smalls[5 * shades[l1] + 2], k1, -1, this);
else
horiG.drawImage(smalls[5 * shades[l1] + 3], k1, -1, this);
if(i1 == 2)
{
horiG.drawImage(smalls[12], 64, 0, this);
horiG.drawImage(smalls[13], 64, -29, this);
}
if(j1 == 3)
{
horiG.drawImage(smalls[14], 0, 31, this);
horiG.drawImage(smalls[14], 35, 31, this);
horiG.drawImage(smalls[15], -29, 31, this);
}
if(i1 == 2)
{
if(k1 > 28)
horiG.drawImage(smalls[13], 64, 3 + (32 - k1), this);
}
else
{
k = 2;
if(k1 > 28)
k = 3;
int i2;
k += 5 * shades[map[7 + (i2 = i1 + 2) + 6 * j1]];
horiG.drawImage(smalls[k], 64, -1, this);
}
if(j1 == 3)
{
horiG.drawImage(smalls[15], 3 + k1, 31, this);
}
else
{
k = 1;
if(k1 < 8)
k = 3;
int j2;
k += 5 * shades[map[7 + i1 + 6 * (j2 = j1 + 1)]];
horiG.drawImage(smalls[k], 0, 31, this);
k = 1;
if(k1 > 7)
if(k1 < 29)
k = 3;
else
k = 4;
int i3;
k += 5 * shades[map[7 + (j2 = i1 + 1) + 6 * (i3 = j1 + 1)]];
horiG.drawImage(smalls[k], 32, 31, this);
}
if(i1 < 2 && j1 < 3)
{
k = 4;
if(k1 > 28)
k = 3;
int k2;
int j3;
k += 5 * shades[map[7 + (k2 = i1 + 2) + 6 * (j3 = j1 + 1)]];
horiG.drawImage(smalls[k], 64, 31, this);
}
for(i = -1; i < 2; i++)
for(j = -1; j < 3; j++)
{
int l2 = i1 + j;
int k3 = j1 + i;
if(map[7 + l2 + 6 * k3] > 0)
horiG.drawImage(smalls[10 + shades[map[7 + (l2 = i1 + j) + 6 * (k3 = j1 + i)]]], 3 + 32 * j, 3 + 32 * i, this);
}
horiG.drawImage(smalls[10 + shades[l1]], 3 + k1, 3, this);
horiG.drawImage(smalls[15 + l1], 8 + k1, 12, this);
} |
|