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

2015/10/13

Need help making a frogger game

A.Derendorf A.Derendorf

2015/10/13

#
Hey there! Me and my friends are trying to make a game of frogger for our tech class. We received instructions on how to do it but our teacher has not been very clear. Right now we are trying to get the cars to spawn and move across the road randomly. We have a problem with the `"addObject" statement. Here is our code:
public int pickLane(){
    int lane;
    
    lane = Greenfoot.getRandomNumber(4);
    
    return lane;
    
}

public void tryAddingCar(){
    if (Greenfoot.getRandomNumber(100) < 3)
    {
        int lane;
        int speed;
        Car randomCar;
        int x;
        int y;
        
        
        lane = pickLane();
        speed = pickSpeed();
        
        if (lane == 0){
            randomCar = new Car(0);
        }
        else if (lane == 1){
            randomCar = new Car(0); 
        }
        else if (lane == 2){
            randomCar = new Car(0); 
        }
        else if (lane == 3){
            randomCar = new Car(0); 
        }
        else {
          randomCar = new Car(0);  
        }
        addObject(randomCar,400,200);
        randomCar.setSpeed(pickSpeed());
            


    }
}

public int pickSpeed(){
    int speed;
    
    speed = 2+Greenfoot.getRandomNumber(7);
    
    return speed;
}
The error message we get when trying to compile is : cannot find symbol - method addObject(Car,int,int) This is according to the instructions the only missing link we need for this to work. If you can find any errors please let me know.
danpost danpost

2015/10/13

#
The 'addObject' method is a World class method. This means that you need a world for the object to be added into. If the code given was located in a World subclass, you would not get that error message. Providing your class structure to the class this code is located could help.
A.Derendorf A.Derendorf

2015/10/15

#
Thanks man! We actually figured it out later. We are new at this but we know you are a beast danpost. Thanks again for your services to the forum.
You need to login to post a reply.