-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWitch.java
More file actions
40 lines (37 loc) · 1.02 KB
/
Copy pathWitch.java
File metadata and controls
40 lines (37 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Witch inherits Actor, set a gif on the World for a short period.
*
* @author Yixin Cai
* @version 2022-10-24
*/
public class Witch extends Actor
{
// instance variables
private int tik;
private GifImage witchGif = new GifImage("witch.gif");
/**
* The constructor of Witch
* @param tik A int to calculate the acts
*/
public Witch(int tik) {
setImage(witchGif.getCurrentImage());
this.tik = tik;
}
/**
* Act - do whatever the Witch wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (tik > 0) {
tik--;
setImage(witchGif.getCurrentImage());
}
else {
// the tik is 0 means the time is off, object will be removed
VehicleWorld vw = (VehicleWorld)getWorld();
vw.removeObject(this);
}
}
}