Objektorientierte Programmierung WS 2013/2014 - Datei Punkt.java
import java.awt.*;
class Punkt implements PBElement { // Punkt, der den Zähler hochzählt
// Größenangaben
final static int radius = 17;
// Punktanzahl gesamt
static int score;
// Wert dieses Punktes
int value;
// die Position
private Rectangle location;
// Konstruktor
public Punkt(int x, int y, int v) {
location = new Rectangle(x - radius, y - radius, 2 * radius, 2 * radius);
value = v;
}
// 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.pink);
g.fillOval(location.x, location.y, 2 * radius, 2 * radius);
g.setColor(Color.black);
g.drawOval(location.x, location.y, 2 * radius, 2 * radius);
g.drawString(value + "", location.x + 3, location.y + radius + 5);
}
public void hit(Ball b) // reagiere auf die Beruehrung von b
{ // Punktzähler hochzählen
score += value;
// runter von dem Punkt:
while (location.intersects(b.region())) {
b.move();
}
}
// Zählerstand anzeigen
public static void showScore(Graphics g) {
g.setColor(Color.yellow);
g.drawString(score + "", 6, 40);
}
}
Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 06.01.2014


