Hi everyone,
It seems to be more difficult than I thought:
How you can show a variable (Energy) from different objects that are in a robot-class? I have done it so far, but when I want to tell what the text should represent (->Energy) it comes a failure:
The Text-Class:
The Informator-Class:
The World-Class:
I'll be really grateful if someone knows the answer
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
public class CounterEnergy extends Actor
{
private int Energy_c3p0;
private int Energy_r2d2;
private int Energy_no5;
public CounterEnergy()
{
Energy_c3p0 = Informator(pName("c3p0")).energiestand; //c3p0 should be the name of the Object that is in the Informator-Class
Energy_r2d2 = Informator(pName("r2d2")).energiestand; //r2d2 should be the name of the Object that is in the Informator-Class
Energy_no5 = Informator(pName("no5")).energiestand; //no5 should be the name of the Object that is in the Informator-Class
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Informator extends Roboter
{
private String Name;
public int energiestand;
private boolean kannBewegen;
private int anzahlSchrauben;
public Informator(String pName, int pEnergiestand)
{
Name = pName;
energiestand = pEnergiestand;
kannBewegen = true;
anzahlSchrauben = 5;
}
public void act()
{
World myWorld = getWorld();
World world = (World)myWorld;
CounterEnergy CE = world.getCounter();
} import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class RoboterWelt extends World
{
private CounterEnergy CE;
private Informator c3p0;
private Informator r2d2;
private Informator no5;
public RoboterWelt()
{
super(14, 10, zellenGroesse);
setBackground("images/Bodenplatte.png");
setPaintOrder(Roboter.class, Schraube.class, Akku.class,Wand.class);
Greenfoot.setSpeed(20);
prepare();
}
public CounterEnergy getCounter()
{
return CE;
}
public void prepare()
{
CE = new CounterEnergy();
addObject(CE,0,0);
c3p0 = new Informator("c3po", 120);
addObject(c3p0,6,2);
c3p0.setRotation(180);
r2d2 = new Informator("r2d2", 80);
addObject(r2d2,1,5);
no5 = new Informator("no5", 20);
addObject(no5,3,3);
}
