📄 myship.java
字号:
import javax.microedition.lcdui.*;
class MyShip extends Sprite {
private Image shipImg;
private Image burstImg;
MyShip() {
// 取得图像
try {
shipImg = Image.createImage("/jiki.png");
burstImg = Image.createImage("/imgmyshipbomb.png");
}catch(Exception e) {}
//设定宽度与高度
width = shipImg.getWidth();
height = shipImg.getHeight();
}
void doMove() {
tickCount++;
if(isHit()) {
if(tickCount > 4) {
setHit(false);
}
}else {
if(tickCount > 4) {
tickCount = 0;
}
}
}
void doDraw(Graphics g) {
if(isHit()) {
//Hit时描绘爆炸图像
g.drawImage(burstImg, x, y, Graphics.TOP|Graphics.LEFT);
}else {
switch(flag)
{
case 1:
g.setClip(x,y,21,26);
g.drawImage(shipImg,x,y,Graphics.TOP|Graphics.LEFT);
break;
case 2:
g.setClip(x+20,y,23,26);
g.drawImage(shipImg,x,y,Graphics.TOP|Graphics.LEFT);
break;
case 3:
g.setClip(x+42,y,21,26);
g.drawImage(shipImg,x,y,Graphics.TOP |Graphics.LEFT);
break;
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -