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

2012/3/27

help quickly please

helpme helpme

2012/3/27

#
this error message keeps coming up and i do not know how to fix it help please !?!? no suitable constructor found for Ball(Counter, Counter2) constructor Ball.Ball(Counter2) is not applicable (actual and formal argument lists differ in length) constructor Ball.Ball(Counter) is not applicable (actual and formal argument lists differ in length)
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class PongWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PongWorld  extends World
{

    /**
     * Constructor for objects of class PongWorld.
     * 
     */
    public PongWorld()
    {    
        // Create a new world with 20x20 cells with a cell size of 10x10 pixels.
        super(700, 500, 1);
        Counter counter = new Counter();
        addObject(counter, 49, 78);

        Counter2 counter2 = new Counter2();
        addObject(counter2, 648, 417);

        addObject(new Paddle2(), 350, 50);
        addObject(new Paddle(), 350, 450);

        Ball ball = new Ball(counter,counter2);
        addObject(ball, 350, 250);

        addObject(new BackBoard2(), 350, 500);
        addObject(new BackBoard2(), 300, 500);
        addObject(new BackBoard2(), 250, 500);
        addObject(new BackBoard2(), 200, 500);
        addObject(new BackBoard2(), 150, 500);
        addObject(new BackBoard2(), 100, 500);
        addObject(new BackBoard2(), 50, 500);
        addObject(new BackBoard2(), 00, 500);
        addObject(new BackBoard2(), 400, 500);
        addObject(new BackBoard2(), 450, 500);
        addObject(new BackBoard2(), 500, 500);
        addObject(new BackBoard2(), 550, 500);
        addObject(new BackBoard2(), 600, 500);
        addObject(new BackBoard2(), 650, 500);
        addObject(new BackBoard2(), 700, 500);

        addObject(new BackBoard(), 350, 0);
        addObject(new BackBoard(), 300, 0);
        addObject(new BackBoard(), 250, 0);
        addObject(new BackBoard(), 200, 0);
        addObject(new BackBoard(), 150, 0);
        addObject(new BackBoard(), 100, 0);
        addObject(new BackBoard(), 50, 0);
        addObject(new BackBoard(), 00, 0);
        addObject(new BackBoard(), 400, 0);
        addObject(new BackBoard(), 450, 0);
        addObject(new BackBoard(), 500, 0);
        addObject(new BackBoard(), 550, 0);
        addObject(new BackBoard(), 600, 0);
        addObject(new BackBoard(), 650, 0);
        addObject(new BackBoard(), 700, 0);
    }
}
Morran Morran

2012/3/27

#
Check inside the Ball class. What do the constructors look like? Is there a constructor for Ball that accepts 2 counters?
helpme helpme

2012/3/27

#
this is the ball class
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Ball here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

/**
 * We have won the game.
 */
public class Ball  extends Actor
{       
private int points;

    public boolean canSee(Class clss)

    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        return actor != null;        
    } 

    private Counter Counter;
    
    public Ball(Counter pointCounter)
    {
        Counter = pointCounter; 
    }
    
    private Counter2 Counter2;
    
    public Ball(Counter2 pointCounter2)
    {
        Counter2 = pointCounter2; 
    }
     
    /**
     * Act - do whatever the Ball wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public boolean atWorldEdge()
    {
        if(getX() < 10 || getX() > getWorld().getWidth() - 10)
            return true;
        if(getY() < 10 || getY() > getWorld().getHeight() - 10)
            return true;
        else
            return false;
    }
   
      public void act() 
    {
       move(5);
              
        if (atWorldEdge())
        {
            turn(15);
        }

        if (canSee(Paddle.class))
        {
            turn(15);
        }

        if (canSee(Paddle2.class))
        {
            turn(15);
        }

        if (canSee(BackBoard.class))
        {
              turn(15);
              Counter2.add(1);
        }
        
        if (Counter2.getValue() >= 30)
        {
            gameOver();  
        }  
        
        
        if (canSee(BackBoard2.class))
        {
                turn(15);
                Counter.add(1);
        }

        if (Counter.getValue() >= 30)
        {
            gameOver();  
        }  
           /**
     * We have won the game.
     */
    
    } public void gameOver()
    {
         Greenfoot.stop();
    }       
    }
Morran Morran

2012/3/27

#
Your Ball class only accepts one Counter for each Ball created. You gave one Ball 2 Counters in your PongWorld. Unless you want to have two different Balls for each Counter, you need to have your Ball class accept 2 Counters. It's not too hard, maybe something like this:

    private Counter counter;  //it's easiest to read if your variables do 
    private Counter2 counter2;  //not start with uppercase letters.
      
    //this constructor will accept 2 different Counters, and assign them
    //to the Ball's two Counters.
    public Ball(Counter pointCounter, Counter2 pointCounter2)  
    {  
        counter = pointCounter;   
        counter2 = pointCounter2;   
    }  
     
I hope this helps.
You need to login to post a reply.