-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasek.java
More file actions
56 lines (47 loc) · 1.3 KB
/
Pasek.java
File metadata and controls
56 lines (47 loc) · 1.3 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import greenfoot.*;
import java.awt.*;
/**
* Write a description of class Pasek here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Pasek extends Actor
{
int max = 100;
int szerokosc = 200;
int wysokosc = 15;
int pozycja = 1;
int pixelPrzezPozycje = (int)szerokosc/max;
/**
* Act - do whatever the Pasek wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
update();
pozycja++;
zresetujPasek(pozycja);
}
public void update() {
setImage(new GreenfootImage(szerokosc +2, wysokosc+2));
GreenfootImage bar = getImage();
bar.setColor(Color.WHITE);
bar.drawRect(0, 0, szerokosc, wysokosc);
if(pozycja < 35 || pozycja > 65) {
bar.setColor(Color.RED);
bar.fillRect(1,1,pozycja*pixelPrzezPozycje,wysokosc);
} else {
bar.setColor(Color.GREEN);
bar.fillRect(1,1,pozycja*pixelPrzezPozycje,wysokosc);
}
}
public void zresetujPasek(int position) {
if(position == 100) {
this.pozycja = 1;
}
}
public int wezPozycje() {
return pozycja;
}
}