?? herosprite.java
字號(hào):
import java.io.*;
import java.util.Random;
import javax.microedition.lcdui.Image;
import javax.microedition.rms.RecordStore;
public class HeroSprite extends ASprite
{
public final int LISTENER_LEFT = 4;
public final int LISTENER_RIGHT = 32;
public final int LISTENER_UP = 2;
public final int LISTENER_DOWN = 64;
public final int LISTENER_FIRE = 256;
public int dir;
public int hp;
public int maxhp;
public int lv;
public int exp;
public int nextexp;
public int prevexp;
public int itemlv;
public int gold;
public int at;
public int df;
public int mapdir;
public String MyItem;
public boolean isAlive;
public boolean isAttach;
public boolean isStop;
public boolean isBattle;
public boolean iisBattle;
public boolean iiisBattle;
public boolean isStopb;
public boolean isPause;
public int x;
public int y;
public int luX;
public int luY;
public int ruX;
public int ruY;
public int ldX;
public int ldY;
public int rdX;
public int rdY;
public int stopTime;
public int time;
public Random random;
public int numEmpty;
public final int DIR_LEFT = 2;
public final int DIR_DOWN = 1;
public final int DIR_RIGHT = 4;
public final int DIR_UP = 3;
public final int DIR_LU = 5;
public final int DIR_RU = 6;
public final int DIR_LD = 7;
public final int DIR_RD = 8;
public String DataName;
public char itemcode[] = {
'0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0'
};
private int up_seq[] = {
1, 2, 3, 4, 5, 6, 7, 8
};
private int lu_seq[] = {
14, 15, 16, 17, 18, 19, 20, 21
};
private int ru_seq[] = {
40, 41, 42, 43, 44, 45, 46, 47
};
private int ld_seq[] = {
66, 67, 68, 69, 70, 71, 72, 73
};
private int rd_seq[] = {
79, 80, 81, 82, 83, 84, 85, 86
};
private int left_seq[] = {
92, 93, 94, 95, 96, 97, 98, 99
};
private int down_seq[] = {
53, 54, 55, 56, 57, 58, 59, 60
};
private int right_seq[] = {
27, 28, 29, 30, 31, 32, 33, 34
};
public int itemat[] = {
0, 30, 70, 120, 200
};
public int itemdf[] = {
0, 20, 60, 110, 190
};
private int up[] = {
0
};
private int lu[] = {
13
};
private int ru[] = {
39
};
private int ld[] = {
65
};
private int rd[] = {
78
};
private int left[] = {
91
};
private int down[] = {
52
};
private int right[] = {
26
};
public int downb_seq[] = {
9, 10, 11, 12
};
public int upb_seq[] = {
35, 36, 37, 38
};
public int leftb_seq[] = {
48, 49, 50, 51
};
public int rightb_seq[] = {
61, 62, 63, 64
};
private int lub_seq[] = {
87, 88, 89, 90
};
private int rub_seq[] = {
74, 75, 76, 77
};
private int ldb_seq[] = {
22, 23, 24, 25
};
private int rdb_seq[] = {
100, 101, 102, 103
};
public boolean isWalkable[][];
public HeroSprite(Image image, int i, int j)
{
super(image, i, j);
mapdir = 0;
isPause = false;
stopTime = 5;
time = 0;
random = new Random();
numEmpty = 0;
x = 180;
y = 180;
luX = x / 16 + 1;
luY = y / 16;
lv = 1;
maxhp = 160 + (lv - 1) * 40;
itemlv = 0;
gold = 0;
MyItem = "000000000000";
exp = 210;
hp = maxhp;
at = 30;
df = 20;
prevexp = (lv * lv * 60 - (lv - 1) * (lv - 1) * 60) + 150;
nextexp = ((prevexp + (lv - 1) * (lv - 1) * 60) - (lv - 2) * (lv - 2) * 60) + 150;
System.out.print("已裝載英雄類");
setFrameSequence(down);
isAlive = true;
System.out.print("英雄類裝載完畢");
}
public byte[] chgTorms(boolean flag)
throws IOException
{
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
if (itemcode != null)
MyItem = String.valueOf(itemcode);
dataoutputstream.writeUTF(String.valueOf(lv));
dataoutputstream.writeUTF(String.valueOf(itemlv));
dataoutputstream.writeUTF(String.valueOf(gold));
dataoutputstream.writeUTF(String.valueOf(MyItem));
dataoutputstream.writeUTF(String.valueOf(exp));
if (!flag)
{
at = itemat[itemlv] + (lv - 1) * 8 + 30;
df = itemdf[itemlv] + (lv - 1) * 10 + 20;
}
bytearrayoutputstream.close();
dataoutputstream.close();
numEmpty = 0;
if (!flag)
{
for (int i = 0; i < itemcode.length; i++)
if (itemcode[i] == '0')
numEmpty++;
}
return bytearrayoutputstream.toByteArray();
}
public void doMonster(int i, int j, RecordStore recordstore, int k)
{
hp = i;
if (lv <= 6)
{
prevexp = (lv * lv * 60 - (lv - 1) * (lv - 1) * 60) + 150;
nextexp = ((prevexp + (lv - 1) * (lv - 1) * 60) - (lv - 2) * (lv - 2) * 60) + 150;
} else
{
prevexp = (lv * (lv - 5) * (lv - 5) - 40 * (lv - 4) * (lv - 4)) + 150;
nextexp = ((prevexp + 50 * (lv + 1) * (lv - 4) * (lv - 4)) - 40 * (lv - 3) * (lv - 3)) + 150;
}
if (j != 0)
{
exp = exp + j * 15 + random.nextInt() % 5;
if (exp >= nextexp)
{
if (lv < 12)
lv++;
at = itemat[itemlv] + (lv - 1) * 8 + 30;
df = itemdf[itemlv] + (lv - 1) * 10 + 20;
maxhp = 160 + (lv - 1) * 40;
hp = maxhp;
}
try
{
recordstore.setRecord(k, chgTorms(false), 0, chgTorms(false).length);
}
catch (Exception exception)
{
System.out.println(exception);
}
isBattle = false;
}
}
private void getNowHanglie()
{
luX = x / 16 + 1;
luY = y / 16;
ruX = (x + 40) / 16 + 1;
ruY = luY;
ldX = luX;
ldY = (y + 40) / 16;
rdX = ldX;
rdY = ldY;
}
public void chgMapbool(boolean aflag[][])
{
isWalkable = aflag;
}
public void doMove(int i)
{
if (hp <= 0)
isAlive = false;
if (isAlive)
{
getNowHanglie();
if (!isPause)
{
switch (i)
{
case 2: // '\002'
if (dir != 3)
{
dir = 3;
setFrameSequence(up_seq);
}
if (isWalkable[ldX][ldY - 1] && isWalkable[rdX][rdY - 1])
{
if (isBattle)
{
setFrameSequence(up_seq);
isBattle = false;
}
if (isStop)
{
setFrameSequence(up_seq);
isStop = false;
}
y = y - 5;
nextFrame();
}
break;
case 64: // '@'
if (dir != 1)
{
dir = 1;
setFrameSequence(down_seq);
}
if (isBattle)
{
setFrameSequence(down_seq);
isBattle = false;
}
if (isStop)
{
setFrameSequence(down_seq);
isStop = false;
}
if (isWalkable[ldX][ldY + 1] && isWalkable[rdX][rdY + 1])
{
y = y + 5;
nextFrame();
}
break;
case 4: // '\004'
if (dir != 2)
{
dir = 2;
setFrameSequence(left_seq);
}
if (isBattle)
{
setFrameSequence(left_seq);
isBattle = false;
}
if (isStop)
{
setFrameSequence(left_seq);
isStop = false;
}
if (isWalkable[ldX - 1][ldY])
{
x = x - 5;
nextFrame();
}
break;
case 32: // ' '
if (dir != 4)
{
dir = 4;
setFrameSequence(right_seq);
}
if (isBattle)
{
setFrameSequence(right_seq);
isBattle = false;
}
if (isStop)
{
setFrameSequence(right_seq);
isStop = false;
}
if (isWalkable[rdX + 1][rdY])
{
x = x + 5;
nextFrame();
}
break;
case 6: // '\006'
if (dir != 5)
{
dir = 5;
setFrameSequence(lu_seq);
}
if (isBattle)
{
setFrameSequence(lu_seq);
isBattle = false;
}
if (isStop)
{
setFrameSequence(lu_seq);
isStop = false;
}
if (isWalkable[ldX - 1][ldY] && isWalkable[ldX][ldY - 1] && isWalkable[rdX][rdY - 1])
{
x = x - 3;
y = y - 3;
nextFrame();
}
break;
case 34: // '"'
if (dir != 6)
{
dir = 6;
setFrameSequence(ru_seq);
}
if (isBattle)
{
setFrameSequence(ru_seq);
isBattle = false;
}
if (isStop)
{
setFrameSequence(ru_seq);
isStop = false;
}
if (isWalkable[ldX][ldY - 1] && isWalkable[rdX][rdY - 1] && isWalkable[rdX + 1][rdY])
{
x = x + 3;
y = y - 3;
nextFrame();
}
break;
case 68: // 'D'
if (dir != 7)
{
dir = 7;
setFrameSequence(ld_seq);
}
if (isBattle)
{
setFrameSequence(ld_seq);
isBattle = false;
}
if (isStop)
{
setFrameSequence(ld_seq);
isStop = false;
}
if (isWalkable[ldX - 1][ldY] && isWalkable[ldX][ldY + 1] && isWalkable[rdX][rdY + 1])
{
x = x - 3;
y = y + 3;
nextFrame();
}
break;
case 96: // '`'
if (dir != 8)
{
dir = 8;
setFrameSequence(rd_seq);
}
if (isBattle)
{
setFrameSequence(rd_seq);
isBattle = false;
}
if (isStop)
{
setFrameSequence(rd_seq);
isStop = false;
}
if (isWalkable[rdX + 1][rdY] && isWalkable[ldX][ldY + 1] && isWalkable[rdX][rdY + 1])
{
x = x + 3;
y = y + 3;
nextFrame();
}
break;
case 0: // '\0'
if (!isBattle)
{
isStop = true;
switch (dir)
{
case 1: // '\001'
setFrameSequence(down);
break;
case 2: // '\002'
setFrameSequence(left);
break;
case 3: // '\003'
setFrameSequence(up);
break;
case 4: // '\004'
setFrameSequence(right);
break;
case 5: // '\005'
setFrameSequence(lu);
break;
case 6: // '\006'
setFrameSequence(ru);
break;
case 8: // '\b'
setFrameSequence(rd);
break;
case 7: // '\007'
setFrameSequence(ld);
break;
}
}
break;
case 256:
if (mapdir == 1)
{
switch (dir)
{
default:
break;
case 1: // '\001'
if (!isBattle)
setFrameSequence(downb_seq);
break;
case 2: // '\002'
if (!isBattle)
setFrameSequence(leftb_seq);
break;
case 3: // '\003'
if (!isBattle)
setFrameSequence(upb_seq);
break;
case 4: // '\004'
if (!isBattle)
setFrameSequence(rightb_seq);
break;
case 5: // '\005'
if (!isBattle)
setFrameSequence(lub_seq);
break;
case 7: // '\007'
if (!isBattle)
setFrameSequence(ldb_seq);
break;
case 6: // '\006'
if (!isBattle)
setFrameSequence(rub_seq);
break;
case 8: // '\b'
if (!isBattle)
setFrameSequence(rdb_seq);
break;
}
isBattle = true;
}
break;
}
if (isBattle)
{
if (getFrame() == 2)
iiisBattle = true;
else
iiisBattle = false;
nextFrame();
}
if (iiisBattle && isBattle)
iisBattle = true;
else
iisBattle = false;
dx = x;
dy = y;
}
} else
if (exp > 150)
exp = exp - 150;
else
exp = 0;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -