1

Working on a project in school, I'm a beginner to programming and I have big problems with the making of Bubble Shooter, I need to get all of the balls of the map before it changes to map2..

Trying to make it with listing all of the balls but the program crashes at the end of the first map and gives us the error-report that it can't load a negative value. I figured it was when it was trying to load the gun and wanted to put an if-statement that says that if "allowedBallTypes != null" or zero, as it might be, than it should load the gun.

cannot find symbol - getAllowedBallTypes(); greenfoot java method class

The bubbleworld class:

public BubbleWorld() 
{    
        super(Map.MAX_WIDTH*Map.COLUMN_WIDTH, Map.MAX_HEIGHT*Map.ROW_HEIGHT, 1,false); 

        // Max speed. We use time-based animation so this is purely for smoothness,
        // because Greenfoot is plain stupid. I can't find a way to get 60 Hz so this is
        // what we have to do. Note: Exporting the game seems to cap this to some value < 100. :(
        Greenfoot.setSpeed(100);

        // Load the map.
        map = new Map(this, testMap1);

        // Update the allowed ball types. (i.e. we don't want to spawn a
        // certain color of balls if the map doesn't contain them!)
        map.updateAllowedBallTypes();

        // Create the cannon.
        Cannon cannon = new Cannon();
        addObject(cannon, getWidth()/2, getHeight());

The map class:

       public int[] getAllowedBallTypes()
    {
        return allowedBallTypes;
    }


public void updateAllowedBallTypes()
    {
        int allowedCount = 0;
        boolean[] allowed = new boolean[Ball.typeCount];

        // Only ball types that exist in the map RIGHT NOW as attached balls will be allowed.
        for(Cell c : cells)
        {
            if(c != null && c.getBall() != null && c.isAttached())
            {
                int type = c.getBall().getType();

                if(!allowed[type])
                    allowedCount++;

                allowed[type] = true;
            }
        }

        allowedBallTypes = new int[allowedCount];
        int writeIndex = 0;
        for(int type = 0; type < Ball.typeCount; ++type)
        {
            if(allowed[type])
            {
                allowedBallTypes[writeIndex++] = type;
            }
        }
    }

The Cannon class:

private void prepareBall()
    {
        // Get a random ball type from the list of allowed ones. Only balls currently in the map
        // will be in the list.
        int[] allowedBallTypes = ((BubbleWorld)getWorld()).getMap().getAllowedBallTypes();
        int type = allowedBallTypes[Greenfoot.getRandomNumber(allowedBallTypes.length)];

        // Create it and add it to the world.
        ball = new Ball(type);
        getWorld().addObject(ball, getX(), getY());
    }

2 Answers2

1

Assuming you are getting that error in the pasted snippet of the Cannon class, the error suggests that there is a problem with the getMap() method of BubbleWorld -- can you paste that in so we can see it? It might not be returning the correct type. In general, you need to paste in more code, including complete classes, and say exactly where the error occurs. An easier way might be to upload your scenario with source code to the greenfoot website (www.greenfoot.org -- use the share function in Greenfoot, and make sure to tick the source code box) and give a link to that.

Neil Brown
  • 3,558
  • 1
  • 27
  • 36
0

Based on your code, your map class doesn't seem to have a class-level variable declaration of int[] allowedBallTypes;

JoshDM
  • 4,939
  • 7
  • 43
  • 72
  • It gives the error: cannot find symbol - method getAllowedBallTypes() – Richard Atterfalk Oct 18 '11 at 17:01
  • I've been helping him with this project, but I haven't touched either JAVA or this program before this, so I suggested that he would ask here. – Richard Atterfalk Oct 18 '11 at 17:02
  • I'm a beginner and not 100% sure of what you mean with class level variable declaration, please explain it to me :) – Mattias Wolfenstein Oct 18 '11 at 17:06
  • You have not posted your entire map class; your methods in map refer to the array "allowedBallTypes", but you do not show any place where you have actually declared "allowedBallTypes" as an int[]. I can't get any more specific than that. – JoshDM Oct 19 '11 at 02:37