This site requires JavaScript, please enable it in your browser!
Greenfoot back
ZahDx
ZahDx wrote ...

2014/8/21

I need help it's saying that cannot find symbol all details below

ZahDx ZahDx

2014/8/21

#
Says that I cannot find symbol - Constructor Enemy(ActualToast) It comes up when I try to compile my welt world
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Welt here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Welt extends World
{
    ActualToast target1 = new ActualToast();  
    Tank actual1 = new Tank();  
    //     Tank target2 = new Tank();  
    //     Tank enemy2 = new Tank(target2);  
    //     Tank target3 = new Tank();  
    //     Tank enemy3 = new Tank(target3);  
    Counter counter = new Counter("Score: ");
    private boolean gotTanked = false;
    
    /**
     * Constructor for objects of class Welt.
     * 
     */
    public Welt()
    {    
        super(1300 , 700, 1); 
        prepare();
        setPaintOrder(Counter.class , Tank.class , Tank.class , Bullet.class );
        setActOrder(Tank.class , Bullet.class , Tank.class);
    }
    
    public void act()
    {
        randomTank();
        faster();  
        syncTanks();
    }

    
    private void syncTanks()
    {
        actual1.setLocation(target1.getX() , target1.getY());
        actual1.setRotation(target1.getRotation());
        target1.setRotation(actual1.getRotation());
    }
    
    private void prepare()
    {
        addObject( target1 , 650, 350);        
        addObject( actual1 , 650, 350); 
        
        addObject(counter , getWidth()/16 , getHeight()/20 *19);
    }
    
    public void randomTank()
    {
//         if(Greenfoot.getRandomNumber(600) == 13)
//         {
//             addObject(new Tank(target1), 0 , Greenfoot.getRandomNumber(700) );
//         }
        if(Greenfoot.getRandomNumber(500) == 42)
        {
            addObject(new Enemy(target1), Greenfoot.getRandomNumber(1300) , 0 );
        }
//         if(Greenfoot.getRandomNumber(600) == 69)
//         {
//             addObject(new Tank(target1), 1300 , Greenfoot.getRandomNumber(700) );
//         }
        if(Greenfoot.getRandomNumber(500) == 25)
        {
            addObject(new Tank(target1) , Greenfoot.getRandomNumber(700) , 700 );
        }
    }
    
    public void count()
    {
        counter.add(100);
    }
    
    public void faster()
    {
        if(counter.getValue() == 0) Greenfoot.setSpeed(50);
        
        if(counter.getValue() == 1000) Greenfoot.setSpeed(52);
        if(counter.getValue() == 2000) Greenfoot.setSpeed(54);
        if(counter.getValue() == 3000) Greenfoot.setSpeed(56);
        if(counter.getValue() == 4000) Greenfoot.setSpeed(58);
        if(counter.getValue() == 5000) Greenfoot.setSpeed(60);
        if(counter.getValue() == 6000) Greenfoot.setSpeed(62);
        if(counter.getValue() == 7000) Greenfoot.setSpeed(64);
        if(counter.getValue() == 8000) Greenfoot.setSpeed(66);
        if(counter.getValue() == 9000) Greenfoot.setSpeed(68);
        if(counter.getValue() == 10000) Greenfoot.setSpeed(70);
        if(counter.getValue() == 11000) Greenfoot.setSpeed(72);
        if(counter.getValue() == 12000) Greenfoot.setSpeed(74);
        if(counter.getValue() == 13000) Greenfoot.setSpeed(76);
        if(counter.getValue() == 14000) Greenfoot.setSpeed(78);
        if(counter.getValue() == 15000) Greenfoot.setSpeed(80);
        if(counter.getValue() == 16000) Greenfoot.setSpeed(82);
        if(counter.getValue() == 17000) Greenfoot.setSpeed(84);
        if(counter.getValue() == 18000) Greenfoot.setSpeed(86);
        if(counter.getValue() == 19000) Greenfoot.setSpeed(88);
        if(counter.getValue() == 20000) Greenfoot.setSpeed(90);
        
    }    
}
In this code exactly
if(Greenfoot.getRandomNumber(500) == 42)
        {
            addObject(new Enemy(target1), Greenfoot.getRandomNumber(1300) , 0 );
        }
The error comes up in this line "addObject(new Enemy(target1), Greenfoot.getRandomNumber(1300) , 0 );" My ActualToast actor is as follows
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Target here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ActualToast extends Things
{
    private static final double WALKING_SPEED = 4.0;
     boolean hold = false;
    int buttonsDown = 0;  
    final int btnNEITHER = 0, btnLEFT = 1, btnRIGHT = 3;    
    
    public void act() 
    {
        navigate();
        turnToMouse();
        MouseActions();                
    }
    
    
    public void MouseActions()
    {
        
        if(Greenfoot.getMouseInfo() != null)
        {
            
            if (Greenfoot.mousePressed(null))  
            {  
                MouseInfo mi = Greenfoot.getMouseInfo();  
                buttonsDown += mi.getButton();  
                if (buttonsDown == btnLEFT) hold = true;                                   
                //if (buttonsDown == btnRIGHT) System.out.println("Right button pressed");  
                //if (buttonsDown == btnLEFT + btnRIGHT) System.out.println("Both buttons pressed");  
            }  
            if (buttonsDown != btnNEITHER && Greenfoot.mouseClicked(null))   
            {  
                MouseInfo mi = Greenfoot.getMouseInfo();  
                int wasDown = buttonsDown;  
                buttonsDown -= mi.getButton();  
                int buttonReleased = wasDown - buttonsDown;  
                if (buttonReleased == btnLEFT) hold = false; 
                //if (buttonReleased == btnRIGHT) System.out.println("Right button released");  
                //if (buttonsDown == btnNEITHER) System.out.println("(all buttons released)");  
            }  
            
        }
    }
    
    
    public void move()
    {
        double angle = Math.toRadians( getRotation() );
        int x = (int) Math.round(getX() + Math.cos(angle) * WALKING_SPEED);
        int y = (int) Math.round(getY() + Math.sin(angle) * WALKING_SPEED);
        
        setLocation(x, y);
    }
    
    public void turnToMouse()
    {
        if(hold)
        {
            int x = Greenfoot.getMouseInfo().getX();
            int y = Greenfoot.getMouseInfo().getY();
                
            turnTowards(x , y );
        }
    }
    
    public void navigate()
    {
        if(Greenfoot.isKeyDown("left")) turn(-4);
        if(Greenfoot.isKeyDown("right")) turn(4);
        if(Greenfoot.isKeyDown("up")) move();
    }
}
davmac davmac

2014/8/21

#
On line 63, you have written:
new Enemy(target1)
The problem is that you are trying to pass a parameter, 'target1', to the constructor of the Enemy class. But there is no constructor for the Enemy class which takes that type of parameter. Why are you trying to pass the parameter? Can you check the Enemy class and see if the constructor is defined to take any parameters?
Super_Hippo Super_Hippo

2014/8/21

#
Is there an Enemy class anywhere? It is not in the paint order at least (where the class 'Tank' is twice). Maybe the 'Enemy' class is only a superclass? And as davmac asked, why do you want to pass the new 'ActualToast' object to the new created 'Enemy' object which you want to add?
You need to login to post a reply.