-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRybka.java
More file actions
57 lines (49 loc) · 1.35 KB
/
Rybka.java
File metadata and controls
57 lines (49 loc) · 1.35 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
57
import greenfoot.*;
/**
* Write a description of class Rybka here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Rybka extends Actor
{
/**
* Act - do whatever the Rybka wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(3);
}
/**
* Test if we are close to one of the edges of the world. Return true is we are.
*/
public int czyKoniecEkranu()
{
if(getX() < 10)
return 1;
if(getX() > getWorld().getWidth() - 10)
return 0;
else
return 2;
}
public void ruchLewoPrawo(){
if(czyKoniecEkranu() == 0) {
setRotation(180);
getImage().mirrorVertically();
} else if (czyKoniecEkranu() == 1) {
turnTowards(getWorld().getWidth(),getY());
getImage().mirrorVertically();
}
}
public void zlapRybke(){
Siatka catcher = null;
if(Greenfoot.mousePressed(this)) {
catcher = Siatka.getFishCatcher();
World world = getWorld();
world.addObject(catcher, this.getX(), 0);
catcher.turnTowards(this.getX(), this.getY());
}
catcher = null;
}
}