📄 warmap.java.bak
字号:
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.game.GameCanvas;
import java.io.IOException;
public class WarMap extends GameCanvas implements Runnable
{
//********************************全局静态变量
public static int WIDTH = 0;
public static int HEIGHT = 0;
public static final int WAR_FIELD_LEFT = 20;
public static final int WAR_FIELD_TOP = 20;
public static final int WAR_FIELD_WIDTH = 120;
public static final int WAR_FIELD_HEIGHT = 160;
public static final int ACTOR_WIDTH = 24;
public static final int ACTOR_HEIGHT = 32;
public static final int H_NUMBER = WAR_FIELD_WIDTH/ACTOR_WIDTH;
public static final int V_NUMBER = WAR_FIELD_HEIGHT/ACTOR_HEIGHT;
public static final int DISPLAY_TIME = 100;
public static final int MAX_WALL_NUMBER = 10;
//********************************全局非静态变量
private MainSelect mainSelect = null;
//循环控制器
private boolean stop = false;
//现在的状态——布墙(false)战争(true)
//private boolean isWarTime = false;
//主角
//private Sprite actorSprite = null;
//主角方向状态——上(0)下(1)左(2)右(3)
//private int currentDirectStatus = 0;
//private int lastDirectStatus = 0;
//主角现在坐标
private int currentX = 0, currentY = 0;
//主角现在的帧
//private int currentFrame = 0;
//wall变量
private WallManager wallManager = null;
private Image wallImage = null;
public WarMap(MainSelect ms)
{
super(true);
mainSelect = ms;
setFullScreenMode(true);
WIDTH = getWidth();//240
HEIGHT = getHeight();//309
initSprite();
new Thread(this).start();
}
private void initSprite()
{
try
{
wallImage = Image.createImage("/wall.png");
wallManager = new WallManager(wallImage, MAX_WALL_NUMBER);
//Image actorImage = Image.createImage("/actor.png");
//actorSprite = new Sprite(actorImage, ACTOR_WIDTH, ACTOR_HEIGHT);
}
catch (IOException ie)
{
}
}
public void run()
{
Graphics g = getGraphics();
while(!stop)
{
input();
drawScreen(g);
flushGraphics();
try
{
Thread.sleep(DISPLAY_TIME);
}
catch (InterruptedException ie)
{
}
}
WarMidlet.dis.setCurrent(mainSelect);
}
private void input()
{
int keyState=getKeyStates();
//lastDirectStatus = currentDirectStatus;
//UP
if((keyState&GameCanvas.UP_PRESSED)!=0)
{
//currentDirectStatus = 0;
if (currentY != 0)
{
currentY--;
}
}
//DOWN
if((keyState&GameCanvas.DOWN_PRESSED)!=0)
{
//currentDirectStatus = 1;
if (currentY != V_NUMBER - 1)
{
currentY++;
}
}
//LEFT
if((keyState&GameCanvas.LEFT_PRESSED)!=0)
{
//currentDirectStatus = 2;
if (currentX != 0)
{
currentX--;
}
}
//RIGHT
if((keyState&GameCanvas.RIGHT_PRESSED)!=0)
{
//currentDirectStatus = 3;
if (currentX != H_NUMBER - 1)
{
currentX++;
}
}
if((keyState&GameCanvas.FIRE_PRESSED)!=0)
{
wallManager.addWall(currentX, currentY);
//System.out.println("布墙完成");
}
//System.out.println(currentX+":"+currentY);
}
private void drawScreen(Graphics g)
{
//绘制背景
g.setColor(0,0,0);
g.fillRect(0,0,WIDTH,HEIGHT);
//绘制战争区域
g.setColor(0,255,0);
g.fillRect(WAR_FIELD_LEFT, WAR_FIELD_TOP, WAR_FIELD_WIDTH, WAR_FIELD_HEIGHT);
//绘制选择标记
g.setColor(255,0,0);
g.drawRect(WAR_FIELD_LEFT + currentX * ACTOR_WIDTH, WAR_FIELD_TOP + currentY * ACTOR_HEIGHT, ACTOR_WIDTH, ACTOR_HEIGHT);
//绘制墙
wallManager.updateWall(g);
}
/*private void drawActor(Graphics g)
{
actorSprite.setPosition(WAR_FIELD_LEFT + currentX * ACTOR_WIDTH, WAR_FIELD_TOP + currentY * ACTOR_HEIGHT);
if (currentDirectStatus == 0)
{//上
if (currentDirectStatus != lastDirectStatus)
{
currentFrame = 1;
}
else
{
currentFrame = (currentFrame+1)%3;
}
}
else if (currentDirectStatus == 1)
{//下
if (currentDirectStatus != lastDirectStatus)
{
currentFrame = 7;
}
else
{
currentFrame = 6 + (currentFrame - 6 + 1)%3;
}
}
else if (currentDirectStatus == 2)
{//左
if (currentDirectStatus != lastDirectStatus)
{
currentFrame = 10;
}
else
{
currentFrame = 9 + (currentFrame - 9 + 1)%3;
}
}
else
{//右
if (currentDirectStatus != lastDirectStatus)
{
currentFrame = 4;
}
else
{
currentFrame = 3 + (currentFrame - 3 + 1)%3;
}
}
actorSprite.setFrame(currentFrame);
actorSprite.paint(g);
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -