-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateLamp.java
47 lines (43 loc) · 1.22 KB
/
GenerateLamp.java
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
41
42
43
44
45
46
47
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class GenerateLamp here.
*
* @Pyrozen
* @version (a version number or a date)
*/
public class GenerateLamp extends Actor
{
private int randomSpacing = 0;
private int randNum = 0;
private int counter = 0;
public GenerateLamp()
{
randomSpacing = Greenfoot.getRandomNumber(10);
}
public void act()
{
randNum = Greenfoot.getRandomNumber(60);
counter++;
if(counter == randomSpacing)
{
generateLampBaru(randNum);
counter = 0;
randomSpacing = 100 + Greenfoot.getRandomNumber(100);
}
if(getY() == getWorld().getHeight())
{
getWorld().removeObject(this);
}
}
public void generateLampBaru(int space)
{
int state = 0;
TrafficLight lampu1;
state = Greenfoot.getRandomNumber(3);
lampu1 = new TrafficLight();
lampu1.setState(state);
ZebraCross zebra = new ZebraCross(state);
getWorld().addObject(zebra, getWorld().getWidth()/2, 0);
getWorld().addObject(lampu1, getWorld().getWidth()/2+100, 0);
}
}