import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO; 
import java.io.File;
import java.io.IOException; 

public class Pferd  
{    
    private String name;                  
    private Wiese wiese;
    private int x, y;
    private BufferedImage bild;
   
    public Pferd(Wiese pWiese, int pX, int pY, String pName) {
        setzeBild("Pferd.png");
        x = pX;
        y = pY;
        wiese = pWiese;
        name = pName;
    } 
    
    public String gibNamen() {
        return name;
    }
    
    public void zeichnen() {
        Graphics g = wiese.getGraphics(); 
        g.drawImage(bild, x, y-bild.getHeight(), null);
    }
    
    public int gibX() {
        return x;
    }

    public int gibY() {
        return y;
    }

    public void setzePosition(int pX, int pY) {
        x = pX;
        y = pY;
    }
    
    public void loeschen() {
       Graphics g = wiese.getGraphics();  
       g.setColor(Color.GREEN); 
       g.fillRect(x, y-bild.getHeight(), bild.getWidth(), bild.getHeight());
    }
    
    private void setzeBild(String pBildname) {
        // notwendiger Befehl zum Laden einer Bilddatei - wird im 
        // Unterricht noch nicht erklärt.
        try
        {
            bild = ImageIO.read(new File("images/"+ pBildname));
        } 
        catch (IOException e) { e.printStackTrace(); }
    }
    
    private void pause() {
        // Notwendiger Befehl, um die Auführung zu unterbrechen  - 
        // wird im Unterricht noch nicht erklärt.
        try {
            Thread.sleep(500);
        }
        catch(InterruptedException ie) {
        }
    }
    
 }