俺手上有一个.java源程序文件,需要转换成.class程序文件,我在网吧因为无法安装jdk,自己搞不定,哪位有空的话帮俺转换一下,谢谢。- package xqwlight;
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Font;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- public class MainForm extends Canvas
- implements CommandListener
- {
- private static final int PHASE_STARTING = 0;
- private static final int PHASE_WAITING = 1;
- private static final int PHASE_THINKING = 2;
- private static final int PHASE_EXITTING = 3;
- private static Image imgBackground;
- private static Image imgThinking;
- private Image imgBoard;
- private static final String[] IMAGE_NAME = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, "rk", "ra", "rb", "rn", "rr", "rc", "rp",
- 0, "bk", "ba", "bb", "bn", "br", "bc", "bp" };
- private static int widthBackground;
- private static int heightBackground;
- private static Font font = Font.getFont(0, 3, 16);
- private static int fontWidth = font.charWidth(12288);
- private static int fontHeight = font.getHeight();
- private XQWLight midlet;
- private Search search;
- private int cursorX;
- private int cursorY;
- private int sqSelected;
- private int mvLast;
- private int normalWidth;
- private int normalHeight;
- private volatile int phase;
- private String message;
- private Command cmdRetract;
- private Command cmdBack;
- private boolean bLoaded;
- private Image imgSelected;
- private Image imgSelected2;
- private Image imgCursor;
- private Image imgCursor2;
- private Image[] imgPieces = new Image[24];
- private int squareSize;
- private int squareShift;
- private int width;
- private int height;
- private int left;
- private int right;
- private int top;
- private int bottom;
- static
- {
- try
- {
- imgBackground = Image.createImage("/images/background.png");
- imgThinking = Image.createImage("/images/thinking.png");
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage());
- }
- widthBackground = imgBackground.getWidth();
- heightBackground = imgBackground.getHeight();
- }
- public MainForm(XQWLight midlet)
- {
- this.midlet = midlet;
- this.search = new Search();
- this.search.pos = new Position();
- this.normalWidth = getWidth();
- this.normalHeight = getHeight();
- super.setFullScreenMode(true);
- this.cmdBack = new Command("返回", 2, 1);
- addCommand(this.cmdBack);
- setCommandListener(this);
- this.phase = 0;
- this.bLoaded = false;
- }
- public void reset() {
- super.setFullScreenMode(true);
- this.cursorX = (this.cursorY = 7);
- this.sqSelected = (this.mvLast = 0);
- if (this.midlet.rsData[0] == 0) {
- this.search.pos.fromFen(Position.STARTUP_FEN[this.midlet.handicap]);
- } else {
- this.search.pos.clearBoard();
- for (int sq = 0; sq < 256; ++sq) {
- int pc = this.midlet.rsData[(sq + 2)];
- if (pc > 0)
- this.search.pos.addPiece(sq, pc);
- }
- if (this.midlet.flipped)
- this.search.pos.changeSide();
- this.search.pos.setIrrev();
- }
- this.phase = 0;
- }
- public void commandAction(Command c, Displayable d) {
- if ((((this.phase == 1) || (this.phase == 3))) &&
- (c != this.cmdRetract) &&
- (c == this.cmdBack)) {
- this.midlet.rsData[0] = 0;
- Display.getDisplay(this.midlet).setCurrent(this.midlet.startUp);
- }
- }
- protected void paint(Graphics g)
- {
- int i;
- int j;
- int k;
- if (this.phase == 0) {
- this.phase = 1;
- this.width = getWidth();
- this.height = getHeight();
- for (int i = 0; i < 10; ++i) {
- if (this.width != this.normalWidth) break; if (this.height != this.normalHeight)
- break;
- this.width = getWidth();
- this.height = getHeight();
- try {
- Thread.sleep(100L);
- }
- catch (Exception localException1) {
- }
- }
- if (!(this.bLoaded)) {
- this.bLoaded = true;
- String imagePath = "/images/";
- if ((this.width >= 320) && (this.height >= 356)) {
- imagePath = imagePath + "large/";
- this.squareSize = 36;
- this.squareShift = 2;
- } else if ((this.width >= 232) && (this.height >= 258)) {
- imagePath = imagePath + "medium/";
- this.squareSize = 26;
- this.squareShift = 1;
- } else {
- imagePath = imagePath + "small/";
- this.squareSize = 13;
- this.squareShift = 1;
- }
- try {
- this.imgBoard = Image.createImage(imagePath + "board.png");
- this.imgSelected = Image.createImage(imagePath + "selected.png");
- this.imgSelected2 = Image.createImage(imagePath + "selected2.png");
- this.imgCursor = Image.createImage(imagePath + "cursor.png");
- this.imgCursor2 = Image.createImage(imagePath + "cursor2.png");
- for (int i = 0; i < 24; ++i)
- if (IMAGE_NAME[i] == null)
- this.imgPieces[i] = null;
- else
- this.imgPieces[i] = Image.createImage(imagePath + IMAGE_NAME[i] + ".png");
- }
- catch (Exception e)
- {
- throw new RuntimeException(e.getMessage());
- }
- int boardWidth = this.imgBoard.getWidth();
- int boardHeight = this.imgBoard.getHeight();
- this.left = ((this.width - boardWidth) / 2);
- this.top = ((this.height - boardHeight) / 2);
- this.right = (this.left + boardWidth - 32);
- this.bottom = (this.top + boardHeight - 32);
- }
- if (this.search.pos.sdPlayer == 0) if (!(this.midlet.flipped)) break label582;
- else if (this.midlet.flipped) break label582;
- responseMove();
- return;
- }
- for (int x = 0; x < this.width; x += widthBackground) {
- label582: int j;
- for (j = 0; j < this.height; j += heightBackground)
- g.drawImage(imgBackground, x, j, 20);
- }
- g.drawImage(this.imgBoard, this.left, this.top, 20);
- for (int sq = 0; sq < 256; ++sq)
- if (Position.IN_BOARD(sq)) {
- j = this.search.pos.squares[sq];
- if (j > 0)
- drawPiece(g, this.imgPieces[j], sq);
- }
- int sqSrc = 0;
- int k = 0;
- if (this.mvLast > 0) {
- sqSrc = Position.SRC(this.mvLast);
- k = Position.DST(this.mvLast);
- drawPiece(g, ((this.search.pos.squares[sqSrc] & 0x8) == 0) ? this.imgSelected : this.imgSelected2, sqSrc);
- drawPiece(g, ((this.search.pos.squares[k] & 0x8) == 0) ? this.imgSelected : this.imgSelected2, k);
- } else if (this.sqSelected > 0) {
- drawPiece(g, ((this.search.pos.squares[this.sqSelected] & 0x8) == 0) ? this.imgSelected : this.imgSelected2, this.sqSelected);
- }
- int sq = Position.COORD_XY(this.cursorX + 3, this.cursorY + 3);
- if (this.midlet.flipped)
- sq = Position.SQUARE_FLIP(sq);
- if ((sq == sqSrc) || (sq == k) || (sq == this.sqSelected))
- drawCursor(g, ((this.search.pos.squares[sq] & 0x8) == 0) ? this.imgCursor2 : this.imgCursor, sq);
- else
- drawCursor(g, ((this.search.pos.squares[sq] & 0x8) == 0) ? this.imgCursor : this.imgCursor2, sq);
- if (this.phase == 2)
- {
- int x;
- int y;
- if (this.midlet.flipped) {
- x = (Position.FILE_X(k) < 8) ? this.left : this.right;
- y = (Position.RANK_Y(k) < 8) ? this.top : this.bottom;
- } else {
- x = (Position.FILE_X(k) < 8) ? this.right : this.left;
- y = (Position.RANK_Y(k) < 8) ? this.bottom : this.top;
- }
- g.drawImage(imgThinking, x, y, 20);
- } else if (this.phase == 3) {
- g.setFont(font);
- g.setColor(255);
- g.drawString(this.message, (this.width - this.message.length() * fontWidth) / 2, (this.height - fontHeight) / 2, 20);
- }
- }
- protected void keyPressed(int code) {
- if (this.phase == 3) {
- Display.getDisplay(this.midlet).setCurrent(this.midlet.startUp);
- return;
- }
- int deltaX = 0; int deltaY = 0;
- int action = super.getGameAction(code);
- if ((action == 8) || (code == 53)) {
- int sq = Position.COORD_XY(this.cursorX + 3, this.cursorY + 3);
- if (this.midlet.flipped)
- sq = Position.SQUARE_FLIP(sq);
- int pc = this.search.pos.squares[sq];
- if ((pc & Position.SIDE_TAG(this.search.pos.sdPlayer)) != 0) {
- this.mvLast = 0;
- this.sqSelected = sq; break label381:
- }
- if ((this.sqSelected <= 0) || (!(addMove(Position.MOVE(this.sqSelected, sq)))) || (responseMove())) break label381;
- this.mvLast = 0;
- this.midlet.rsData[0] = 0;
- this.phase = 3;
- super.repaint();
- super.serviceRepaints();
- return;
- }
- switch (action)
- {
- case 1:
- deltaY = -1;
- break;
- case 2:
- deltaX = -1;
- break;
- case 5:
- deltaX = 1;
- break;
- case 6:
- deltaY = 1;
- break;
- case 3:
- case 4:
- default:
- switch (code) {
- case 49:
- deltaX = -1;
- deltaY = -1;
- break;
- case 50:
- deltaY = -1;
- break;
- case 51:
- deltaX = 1;
- deltaY = -1;
- break;
- case 52:
- deltaX = -1;
- break;
- case 54:
- deltaX = 1;
- break;
- case 55:
- deltaX = -1;
- deltaY = 1;
- break;
- case 56:
- deltaY = 1;
- break;
- case 57:
- deltaX = 1;
- deltaY = 1;
- case 53:
- }
- }
- this.cursorX = ((this.cursorX + deltaX + 9) % 9);
- this.cursorY = ((this.cursorY + deltaY + 10) % 10);
- label381: super.repaint();
- super.serviceRepaints();
- }
- private void drawCursor(Graphics g, Image image, int sq) {
- drawSquare(g, image, sq, true);
- }
- private void drawPiece(Graphics g, Image image, int sq) {
- drawSquare(g, image, sq, false);
- }
- private void drawSquare(Graphics g, Image image, int sq, boolean cursor) {
- int shift = (cursor) ? 0 : this.squareShift;
- int sqLocal = (this.midlet.flipped) ? Position.SQUARE_FLIP(sq) : sq;
- int sqX = this.left + (Position.FILE_X(sqLocal) - 3) * this.squareSize + shift;
- int sqY = this.top + (Position.RANK_Y(sqLocal) - 3) * this.squareSize + shift;
- g.drawImage(image, sqX, sqY, 20);
- }
- private boolean getResult(boolean computer) {
- if (this.search.pos.isMate()) {
- this.message = ((computer) ? "请再接再厉!" : "祝贺你取得胜利!");
- return true;
- }
- int vlRep = this.search.pos.repStatus(3);
- if (vlRep > 0) {
- vlRep = (computer) ? -this.search.pos.repValue(vlRep) : this.search.pos.repValue(vlRep);
- this.message = ((vlRep < -9800) ? "电脑长打作负,祝贺你取得胜利!" : (vlRep > 9800) ? "长打作负,请不要气馁!" : "双方不变作和,辛苦了!");
- return true;
- }
- if (this.search.pos.moveNum == 100) {
- this.message = "超过自然限着作和,辛苦了!";
- return true;
- }
- if (computer) {
- this.midlet.rsData[0] = (byte)(this.midlet.level + 1);
- this.midlet.rsData[1] = (byte)((this.midlet.flipped) ? 1 : 0);
- System.arraycopy(this.search.pos.squares, 0, this.midlet.rsData, 2, 256);
- }
- return false;
- }
- private boolean addMove(int mv) {
- if (this.search.pos.legalMove(mv)) {
- int pc = this.search.pos.squares[Position.DST(mv)];
- if (this.search.pos.makeMove(mv)) {
- if (pc > 0)
- this.search.pos.setIrrev();
- this.sqSelected = 0;
- this.mvLast = mv;
- return true;
- }
- }
- return false;
- }
- public boolean responseMove() {
- if (getResult(false))
- return false;
- this.phase = 2;
- super.repaint();
- super.serviceRepaints();
- this.search.searchMain(1 << this.midlet.level << 1);
- int pc = this.search.pos.squares[Position.DST(this.search.mvResult)];
- this.search.pos.makeMove(this.search.mvResult);
- if (pc > 0)
- this.search.pos.setIrrev();
- this.mvLast = this.search.mvResult;
- this.phase = 1;
- super.repaint();
- super.serviceRepaints();
- return (!(getResult(true)));
- }
- }
复制代码 转好的话请打个压缩包发俺信箱 xin46.cn@gmail.com
拜托各位了 |