-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGracz.java
More file actions
60 lines (53 loc) · 1.81 KB
/
Gracz.java
File metadata and controls
60 lines (53 loc) · 1.81 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
58
59
60
import greenfoot.*;
import java.io.IOException;
/**
* Write a description of class Gracz here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Gracz extends Actor
{
private GameOver gameOver;
/**
* Act - do whatever the Gracz wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(Greenfoot.isKeyDown("space") && czyJestPilka()) {
dodajPilke();
}
pokazGameOver();
}
public void dodajPilke() {
Pilka pilka;
Pasek bar = (Pasek)getWorld().getObjects(Pasek.class).get(0);
if (bar.wezPozycje() >= 35 && bar.wezPozycje() <= 65) {
pilka = new PilkaOK();
} else {
pilka = new PilkaNiecelna();
}
getWorld().addObject(pilka, (int)(getWorld().getWidth()*0.80272328), (int)(getWorld().getHeight()*0.5484375));
}
public boolean czyJestPilka() {
if (getWorld().getObjects(Pilka.class).size() == 0) {
return true;
}
return false;
}
public void pokazGameOver() {
Uzytkownik uzytkownik = (Uzytkownik)(getWorld().getObjects(Uzytkownik.class).get(0));
if(uzytkownik.wezLicznikBledow() > 2) {
try {
Statystyki statystyki = Statystyki.getInstance();
statystyki.ustawWynikGracza(uzytkownik.getNickName(), uzytkownik.getScore());
statystyki.zapiszStatystykiDoPliku();
} catch (IOException e) {
System.out.println("IOException caught during file operations");
}
gameOver = new GameOver();
getWorld().addObject(gameOver,(int)getWorld().getWidth()*3/6, (int)getWorld().getWidth()/3);
}
}
}