?? broomevent.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 + -