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

📄 broomevent.java

📁 关于j2me的宠物游戏!!!!!!!!!!! 希望打架提出意见
💻 JAVA
字号:
/*
 * BroomEvent.java
 *
 * Created on 2006年5月5日, 上午10:50
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package DogPet;

import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.lcdui.*;

// Referenced classes of package com.webineti:
//            GameData, GameView

public class BroomEvent
{
    GameView view;
    private Graphics g;
    int swapped;
    private int start_x;
    private int start_y;
    int repeat;
    private Image image_bg;
    private Timer timer;
    private int flashDuration;
    Image play[];
    
    class Task2 extends TimerTask  //TimerTask中的scheduledExecutionTime方法返回的是一个预定的任务的执行时间或正在运行的任务的时间
                                  //它经常被在run方法中调用
    {

        public final void run()
        {
            if(GameView.events == 9)
            {
                swapped = swapped + 1;
                if(swapped > play.length - 1)
                {
                    swapped = 0;
                    repeat++;
                    if(repeat > 8)
                    {
                        GameView.events = -1;
                        repeat = 0;
                    }
                }
                view.repaint();
            }
        }

        Task2()
        {
        }
    }


    public void add_data()
    {
        GameData.Mood += 5;
        if(GameData.Mood > 100)
            GameData.Mood = 100;
        GameData.Health += 5;
        if(GameData.Health > 100)
            GameData.Health = 100;
        GameData.Capacity--;
        if(GameData.Capacity < 0)
            GameData.Capacity = 0;
    }

    public BroomEvent(GameView view)
    {
        swapped = 0;
        start_x = 0;
        start_y = 0;
        repeat = 0;
        image_bg = null;
        timer = new Timer();//一种线程设施,用于安排以后在后台线程中执行的任务。可安排任务执行一次,或者定期重复执行。
        flashDuration = 300;
        play = new Image[2];
        this.view = view;
        try
        {
            play[0] = Image.createImage("/broom/broom1.png");
            play[1] = Image.createImage("/broom/broom2.png");
        }
        catch(Exception ex) { }
        timer.scheduleAtFixedRate(new Task2(), 0L, flashDuration);//安排指定的任务在指定的延迟后开始进行重复的固定速率执行
    }

    public void paint(Graphics g)
    {
        int x = 0;
        int y = 0;
        this.g = g;
        if(play[swapped] != null)
        {
            view.g_cls(g, 0);
            switch(repeat)
            {
            case 0: // '\0'
                x = 13;
                y = 80;
                break;

            case 1: // '\001'
                x = 35;
                y = 78;
                break;

            case 2: // '\002'
                x = 13;
                y = 80;
                break;

            case 3: // '\003'
                x = 35;
                y = 78;
                break;

            case 4: // '\004'
                x = 86;
                y = 71;
                break;

            case 5: // '\005'
                x = 95;
                y = 72;
                break;

            case 6: // '\006'
                x = 86;
                y = 71;
                break;

            case 7: // '\007'
                x = 95;
                y = 72;
                break;

            case 8: // '\b'
                x = 0;
                y = 72;
                break;
            }
            g.drawImage(play[swapped], GameData.start_x + x, GameData.start_y + y, 20);
        }
    }

    public void killed()
    {
        timer.cancel();
        timer = null;
    }

   
}

⌨️ 快捷键说明

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