Hey, I'm working at creating a game out of the Robots scenario and one method I use and that should work does nothing instead. Here is the whole code of the problem class:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* RoboterSteuerung ist dafür zuständig,
* dass die Roboter mit Hilfe der Tastatur
* gesteuert werden können.
*
* Enables to control the robots with keys.
*
* @author EHX
* @version 01/07/2014
*/
public class RoboterSteuerung extends Roboter
{
/**
* Alle steuerbaren Roboter und ein Zeiger.
* All controllable robots and a pointer.
*/
Robita robita;
Robby robby;
Robson robson;
Robocount robocount;
Roboter contRob;
public RoboterSteuerung(){
}
/**
* Diese Methode initialisiert zu Beginn die Roboter. Gesteuert wird zuerst Robita.
* Initializes the robots at the beginning and sets the control on Robita.
*/
public void initialize(){
if(robita==null){
robita=(Robita)this.getOneObjectAtOffset(1,1,Robita.class);
}
if(robby==null){
robby=(Robby)this.getOneObjectAtOffset(1,2,Robby.class);
}
if(robson==null){
robson=(Robson)this.getOneObjectAtOffset(1,3,Robson.class);
}
if(robocount==null){
robocount=(Robocount)this.getOneObjectAtOffset(1,4,Robocount.class);
}
contRob=robita;
}
/**
* Die Hauptmethoden: Einfache Steuerbefehle.
* This is the main method with simple controls.
*/
public void generalControls(){
if(Greenfoot.isKeyDown("up")){
contRob.bewegungsfunktion(); //this works, by the way. The function is defined in the Roboter code.
}
if(Greenfoot.isKeyDown("left")){
contRob.dreheLinks();
}
if(Greenfoot.isKeyDown("right")){
contRob.dreheRechts();
}
/**
* The following code should change controls to the next robot,
* but it seems to do nothing instead.
*/
if(Greenfoot.isKeyDown("down")){
if(contRob==robita){
contRob=robby;
}
if(contRob==robby){
contRob=robson;
}
if(contRob==robson){
contRob=robocount;
}
if(contRob==robocount){
contRob=robita;
}
}
}
public void act()
{
initialize();
generalControls();
}
}
