Objektorientierte Programmierung WS 2013/2014 - Datei Feder.java
import java.awt.*;
class Feder implements PBElement { // Feder, die die Kugel nach oben abstoesst
// Größenangaben
final static int length = 25;
final static int height = 6;
// die Position
private Rectangle location;
// Konstruktor
public Feder(int x, int y) {
location = new Rectangle(x + 12, y, 1, 20);
}
// Methoden des Interfaces
public boolean intersects(Ball b) // Ball b beruehrt das Hinderniss
{
return b.region().intersects(location);
}
public void paint(Graphics g) // Zeichne das Hinderniss
{
g.setColor(Color.yellow);
g.fillRect(location.x, location.y, length, height);
g.drawLine(location.x, location.y, location.x + length, location.y + 10);
g.drawLine(location.x + length, location.y + 10, location.x,
location.y + 20);
g.drawLine(location.x, location.y + 20, location.x + length,
location.y + 30);
}
public void hit(Ball b) // reagiere auf die Beruehrung von b
{ // wenn der Ball abwaerts faellt, wird er aufwaerts gefedert
if (b.dy > 0) {
b.setMotion(b.dx, -b.dy - 0.5);
}
}
}
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 14.01.2014


