基于Nokia S40的猜数字游戏之二[3]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

    public CongScreen(Display display,Manager next, Mark mark)
    {
        this(display, next);
        this.mark = mark;
    
    }


    protected void paint(Graphics g)
    {
        int width = this.getWidth();
        int height = this.getHeight();
        if (image == null)
        {
            try
            {
                image = Image.createImage("/cong.png");
                star = Image.createImage("/star.png");
            } catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        if (title != null)
        {
            g.drawString(title, width / 2, 5, Graphics.HCENTER | Graphics.TOP);
        }
        int offset = 10 + getFont().getHeight();
        g.drawImage(image, 2, offset, Graphics.TOP | Graphics.LEFT);
        offset = offset + image.getHeight();
       
        if(type == CONG)
        {
            int number = 5 - mark.getCount()/2;
            if(number ==0) number = 1;
           
            g.drawString("成绩:",2,offset+3,Graphics.TOP|Graphics.LEFT);
            for(int i = 0;i<number;i++)
            {
               g.drawImage(star,4+font.stringWidth("成绩:")+i*star.getWidth(),offset+3,Graphics.LEFT|Graphics.TOP);
               
            }
           
        }
    }

    public void setType(int type)
    {
        this.type = type;
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public Mark getMark()
    {
        return mark;
    }

    public void setMark(Mark mark)
    {
        this.mark = mark;
    }
   

}

    至此我们程序需要的元素都有了,下面我们的任务是写游戏的MIDlet了。由于我是针对s40的手机写的游戏,因此在了解到他的屏幕为128*128之后,进行了界面布局的计算。并且用到了Nokia UI提供的FullCanvas类,但是没有使用它提供的DirectGraphics,因为没有太多需要图形和动作的处理。

package com.j2medev.numbergame;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class NumberGame extends MIDlet implements ButtonListener
{

    private Display display;

    private SplashScreen welcome;

    private Manager manager;

    private Button[] buttons = new Button[4];

    private Button cmd;

    private Mark mark;

本文关键:基于Nokia S40的猜数字游戏之二
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top