盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

J2ME游戏开发中时钟的容易完成

时间:2024/12/4作者:未知来源:盾怪网教程人气:

[摘要]Options and locate the template under * the Source Creation and Management node. Right-click the te...
Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package com.j2medev.gameclock;
import java.util.Timer;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.*;

/**
 *
 * @author Administrator
 */
public class ClockCanvas extends GameCanvas implements Runnable {
   
    private Timer timer = new Timer();
    private GameClock clock = null;
    private boolean going = true;
    int timeLeft = 0;
    /** Creates a new instance of ClockCanvas */
    public ClockCanvas() {
        super(false);
    }
   
    public void run(){
        clock = new GameClock(30);
        timer.schedule(clock,0,1000);
        while(going){
            verifyGameState();
            userInput();
            repaint();
            try{
                Thread.sleep(100);
            }catch(Exception e){
                e.printStackTrace();
            }
           
        }
    }
   
    public void userInput(){
        int keyStates = this.getKeyStates();
        if((keyStates & GameCanvas.LEFT_PRESSED) != 0){
            clock.pause();
        }else if((keyStates & GameCanvas.RIGHT_PRESSED) != 0){
            clock.resume();
        }
           
    }
   
    public void paint(Graphics g){
        int color = g.getColor();
        g.setColor(0xffffff);
        g.fillRect(0,0, this.getWidth(), this.getHeight());
        g.setColor(color);
       
        if(timeLeft == 0){
            g.drawString("游戏结束", this.getWidth()/2, this.getHeight()/4, Graphics.HCENTER

关键词:J2ME游戏开发中时钟的容易完成




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版