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

📄 angerevent.java

📁 关于j2me的宠物游戏!!!!!!!!!!! 希望打架提出意见
💻 JAVA
字号:
/*
 * AngerEvent.java
 *
 * Created on 2006年5月5日, 上午10:43
 *
 * 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 AngerEvent
{
    class Task1 extends TimerTask
    {

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

        Task1()
        {
        }
    }


    public void add_data() //对该事件记录的值进行处理
    {
        GameData.Intelligence += 5;
        if(GameData.Intelligence > 100)
            GameData.Intelligence = 100;
        GameData.Capacity--;
        if(GameData.Capacity < 0)
            GameData.Capacity = 0;
    }

    public AngerEvent(GameView view)
    {
        swapped = 0;
        repeat = 0;
        image_bg = null;
        timer = new Timer();//创建一个任务时间列表
        flashDuration = 1000;
        anger = new Image[2];
        this.view = view;
        try
        {
            anger[0] = Image.createImage("/anger/dog_anger1.png");
            anger[1] = Image.createImage("/anger/dog_anger2.png");
        }
        catch(Exception ex) { }
        timer.scheduleAtFixedRate(new Task1(), 0L, flashDuration);
    }

    public void paint(Graphics g)
    {
        this.g = g;
        if(anger[swapped] != null)
        {
            view.g_cls(g, 0);
            g.drawImage(anger[swapped], 20 + GameData.start_x, 72 + GameData.start_y, 20);
        }
    }

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

    GameView view;
    private Graphics g;
    int swapped;
    private int repeat;
    private Image image_bg;
    private Timer timer;
    private int flashDuration;  //动画持续时间
    Image anger[];
}

⌨️ 快捷键说明

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