⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blackwhitegamecanvas.java

📁 一个黑白棋的源代码(尚未完成
💻 JAVA
字号:
/* * BlackWhiteGameCanvas.java * * Created on 2007-9-28, 14:53:37 * * To change this template, choose Tools | Templates * and open the template in the editor. */package org.yangcq.canvas;import java.io.IOException;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.game.GameCanvas;import javax.microedition.lcdui.game.LayerManager;import javax.microedition.lcdui.game.TiledLayer;import org.yangcq.controller.BlackAndWhite;import org.yangcq.logic.chessboard.ChessboardImpl;import org.yangcq.logic.step.Step;/** * * @author Administrator */public class BlackWhiteGameCanvas extends GameCanvas implements Runnable{    private BlackAndWhite midlet;    private Graphics g;    private boolean inputable;    private boolean pause;    private LayerManager lm;    private int canvasWidth;    private int canvasHeight;    public static byte fps = 12;    public BlackWhiteGameCanvas(BlackAndWhite midlet)    {        super(true);        this.midlet = midlet;        this.lm = new LayerManager();//管理图层        this.g = this.getGraphics();//双缓冲        this.inputable = true;        this.pause = false;        this.setFullScreenMode(true);        this.canvasHeight = this.getHeight();        this.canvasWidth = this.getWidth();    }    public void run()    {        while (!pause)        {            long start = System.currentTimeMillis();            //显示棋盘            displayChessboard();            //处理键盘输入            input();            //处理计算机棋手走棋            logic();            long count = System.currentTimeMillis() - start;            if (count < 1000 / fps)            {                try                {                    Thread.sleep(1000 / fps - count);                } catch (InterruptedException ex)                {                    continue; //继续游戏                }            }        }    }    private void displayChessboard()    {        Step[][] steps = ChessboardImpl.getChessboard().getBoard();        for (int i = 0; i < steps.length; i++)        {            for (int j = 0; j < steps.length; j++)            {            }        }        lm.paint(g, 0, 0);        this.flushGraphics();        this.serviceRepaints();    }    private void input()    {        int keyStates = this.getKeyStates();        if ((keyStates & GameCanvas.LEFT_PRESSED) != 0)        {            System.out.println("待处理左键按下");        } else if ((keyStates & GameCanvas.RIGHT_PRESSED) != 0)        {            System.out.println("待处理右键按下");        } else if ((keyStates & GameCanvas.DOWN_PRESSED) != 0)        {        //        } else if ((keyStates & GameCanvas.UP_PRESSED) != 0)        {        //        } else if ((keyStates & GameCanvas.FIRE_PRESSED) != 0)        {        //        }    }    private void logic()    {        //看游戏是否结束        this.pause = true;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -