// WARNING: This file is auto-generated and any changes to it will be overwritten import lang.stride.*; import java.util.*; import greenfoot.*; /** * Der Igel haust im Walde. */ public class Igel extends Actor { private ArrayList meineWaldfruechte; private int plaetzeImInventar = 2; /** * */ public Igel() { this.getImage().scale(this.getImage().getWidth() / 4, this.getImage().getHeight() / 4); this.meineWaldfruechte = new ArrayList < Waldfrucht > (); } /** * Act - tut, was auch immer Affe tun will. Diese Methode wird aufgerufen, sobald der 'Act' oder 'Run' Button in der Umgebung angeklickt werden. */ public void act() { this.tastensteuerungPruefen(); if (this.isTouching(Waldfrucht.class)) { Waldfrucht w = (Waldfrucht)this.getOneIntersectingObject(Waldfrucht.class); if (this.meineWaldfruechte.size() < this.plaetzeImInventar) { this.meineWaldfruechte.add(w); this.getWorld().removeObject(w); } else { this.getWorld().showText("Kein Platz mehr!", 400, 200); } } } /** * */ public boolean hatTomate() { boolean rueckgabe = false; for (final Waldfrucht eineWaldfrucht : this.meineWaldfruechte) { if (eineWaldfrucht.getName().equals("Tomate")) { rueckgabe = true; } } return rueckgabe; } /** * */ public void mitDenVielenWaldfruechtenProtzen() { int gesamtgewicht = 0; for (final Waldfrucht eineWaldfrucht : this.meineWaldfruechte) { System.out.println("Ich habe das " + eineWaldfrucht.getName()); gesamtgewicht = gesamtgewicht + eineWaldfrucht.getGewicht(); } System.out.println("+++ Gesamtlast: " + gesamtgewicht); } /** * */ public void tastensteuerungPruefen() { if (Greenfoot.isKeyDown("left")) { this.setLocation(this.getX() - 3, this.getY()); } if (Greenfoot.isKeyDown("right")) { this.setLocation(this.getX() + 3, this.getY()); } if (Greenfoot.isKeyDown("up")) { this.setLocation(this.getX(), this.getY() - 3); } if (Greenfoot.isKeyDown("down")) { this.setLocation(this.getX(), this.getY() + 3); } } }