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

2024/10/17

Help with programming error

ThomasGaldieri ThomasGaldieri

2024/10/17

#
When I was in high school I took a programming course using this platform and made a game with it. I am trying to run it on my Mac lap top but it won't let me run it. I can check all of my Actors as well as see the code in "MyWorld" I cannot share it because "Not all the classes int he scenario are complied. To continue with the export, check for errors." I don't know what errors to be looking for and I definitely don't remember how to fix theme even if I could find them. Below is all the code to my game. Please let me know if you can help me! Thank you!
import greenfoot.*;
public class MyWorld extends World
{
    counter Counter = new counter();
    TitleLetters titleletters = new TitleLetters();
    rocktitle rocktitle = new rocktitle();
    anchortitle anchortitle = new anchortitle();
    bouldertitle bouldertitle = new bouldertitle();
    int x= 500;
    int count=0;
    boolean start = false;
    
    GreenfootSound myMusic = new GreenfootSound("Intense 8 bit music.wav");
    

    public MyWorld()
    { 
        super(800, 700, 1); 
        prepare();
        addObject(Counter, 100, 40 );
        addObject (new rockBarrel(),149, 645);
        addObject (new boulderBarrel(),642,645);
        addObject (new anchorBarrel(),398,645);
        
        
        
        Counter.setScore();
    }

    private void prepare()
    {  
        addObject(titleletters, 403, 350);
        addObject(rocktitle, 149, 690);
        addObject(anchortitle, 398, 685);
        addObject(bouldertitle, 642, 690);
    }

    public counter getCounter()
    {
        return Counter;
    }

    public void act()
    {
        myMusic.playLoop();
        
        if(count>=750)
        {
            x = x-10;
            count=0;
        }
        count++;
        if(Greenfoot.isKeyDown("space")&&start==false)
        {
            removeObject(titleletters);
            start=true;
            Greenfoot.playSound("8d82b5_Mega_Man_Death_Sound_Effect.wav");
            //Greenfoot.playSound("When rushjet1 and danooct1 get bored.wav");
            //Greenfoot.playSound("Barrels.wav3");
        
        }
  
        if(start==true)
        {
            if(Greenfoot.getRandomNumber(x)< 2)
            {
                addObject (new boulder(), Greenfoot.getRandomNumber(700)+50,0);
            }
            if ( Greenfoot.getRandomNumber(x)< 2)
            {
                addObject ( new rock(), Greenfoot.getRandomNumber(700)+50, 0);
            }
            if ( Greenfoot.getRandomNumber(x)< 2)
            {
                addObject ( new anchor(), Greenfoot.getRandomNumber(700)+50 , 0);
            }
            if ( Greenfoot.getRandomNumber(1800)< 2)
            {
                addObject ( new teddybear(), Greenfoot.getRandomNumber(700)+50, 0);
            }
            if ( Greenfoot.getRandomNumber(500)< 2)
            {
                addObject ( new voodoobear(), Greenfoot.getRandomNumber(700)+50, 0);
            }
        }
    }
}

import greenfoot.*;
public class TitleLetters extends Actor
{
    public void act() 
    {
        
    }    
}

import greenfoot.*;
public class anchor extends Actor
{
    private GreenfootImage anchor = new GreenfootImage("Copy of Anchors.png");
    private int speed;
    private boolean isGrabbed;

    public void act() 
    {
        falling();
        checkForMiss();
       
        if (Greenfoot.mousePressed(this) && !isGrabbed)
        {
            // grab the object
            isGrabbed = true;
            // the rest of this block will avoid this object being dragged UNDER other objects
            World world = getWorld();
            MouseInfo mi = Greenfoot.getMouseInfo();
            world.removeObject(this);
            world.addObject(this, mi.getX(), mi.getY());
            return;
        }
        // check for actual dragging of the object
        if ((Greenfoot.mouseDragged(this)) && isGrabbed)
        {
            // follow the mouse
            MouseInfo mi = Greenfoot.getMouseInfo();
            setLocation(mi.getX(), mi.getY());
            return;
        }
        // check for mouse button release
        if (Greenfoot.mouseDragEnded(this) && isGrabbed)
        {
            // release the object
            isGrabbed = false;
            return;
        }
    }
    public void falling()
    {
        setLocation(getX(), getY()+Greenfoot.getRandomNumber(3)+1);
        setRotation(getRotation()+2);
    }
    public void checkForMiss()
    {
        MyWorld world = (MyWorld)getWorld();
        if (isAtEdge())
        {
            gameOver gameover = new gameOver();
            world.addObject(gameover,world.getWidth()/2, world.getHeight()/2);
            //getWorld().removeObject(this);
            Greenfoot.stop();
            ((MyWorld)getWorld()).myMusic.stop();
            Greenfoot.playSound("Curb Your Enthusiasm Theme (8 Bit Version).mp3");
            
            
        }
    }
    public anchor()
    {
        speed = (Greenfoot.getRandomNumber(2)+1);
    }
}    

import greenfoot.*;
import java.util.List;
public class anchorBarrel extends Actor
{
    private int anchorstored;
    private int score = 0;
    private boolean powerup = false;
    private int counter;
    private int getWorld;
    private boolean remove = false;
    private List <Actor> actorlist = null;
    public void act() 
    {
        lookForanchor();
        lookForteddybear();
        lookForvoodoobear();
        remove();
        //score = score +1;

        // if(powerup == true)
        // {
        // if(counter <300)
        // {
        // powerClick();
        // counter++;
        // }
        // else
        // {
        // counter = 0;
        // powerup = false;
        // }
        // }    
    }   

    // public boolean powerClick()
    // {
    // return powerup;
    // }

    public void lookForanchor()
    {
        if ( canSee(anchor.class))
        {
            store(anchor.class);
            score = score +1;
            Greenfoot.playSound("Swords_Collide-Sound_Explorer-2015600826.wav");
        }
    }

    
    public void lookForteddybear()
    {
        MyWorld world = (MyWorld)getWorld();
        if ( canSee(teddybear.class))
        {
            store(teddybear.class);
            Greenfoot.playSound("Fairy Dust Sound Effect.wav");
            powerup = true;
            List <Actor> actors = world.getObjects(null);
            actorlist = actors;
            world.addObject (new rockBarrel(),149, 645);
            world.addObject (new boulderBarrel(),642,645);
            world.addObject (new anchorBarrel(),398,645);
            world.addObject(new counter(), 100, 40 );

            world.addObject(new rocktitle(), 149, 690);
            world.addObject(new anchortitle(), 398, 685);
            world.addObject(new bouldertitle(), 642, 690);

            score = actors.size()-8;
            counter Counter = world.getCounter();
            Counter.addScore(score);
            remove=true;
            //world.removeObjects(actors);
            //count all objects removed and add number to counter

        }
    }
    
    public void lookForvoodoobear()
    {
        MyWorld world = (MyWorld)getWorld();
        if ( canSee(voodoobear.class))
        {
            store(voodoobear.class);
            Greenfoot.playSound("Evil Laugh Cackle-SoundBible.com-957382653.wav");
            powerup = true;
            List <Actor> actors = world.getObjects(null);
            actorlist = actors;
            score = (-1)*getWorld().numberOfObjects()+6;

            counter Counter = world.getCounter();
            Counter.addScore(score);
            world.addObject (new rockBarrel(),149, 645);
            world.addObject (new boulderBarrel(),642,645);
            world.addObject (new anchorBarrel(),398,645);
            world.addObject(new counter(), 100, 40 );

            world.addObject(new rocktitle(), 149, 690);
            world.addObject(new anchortitle(), 398, 685);
            world.addObject(new bouldertitle(), 642, 690);
            remove=true;
            //world.removeObjects(actors);
            //count all objects removed and add number to counter

        }
    }

    public boolean canSee(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        return actor != null; 
    }

    public void store(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        MyWorld world = (MyWorld)getWorld();
        if(actor !=null) {
            getWorld().removeObject(actor);
            counter Counter = world.getCounter();
            Counter.addScore();
        }
    } 
    
    public void remove()
    {
        MyWorld world = (MyWorld)getWorld();
        if(remove==true)
        {
            world.removeObjects(actorlist);
        }
    }
}

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class anchortitle here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class anchortitle extends Actor
{
    /**
     * Act - do whatever the anchortitle wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
}

import greenfoot.*;  
public class boulder extends Actor
{
    private GreenfootImage boulder = new GreenfootImage("rock.png");
    private int speed;
    private boolean isGrabbed;
    public void act() 
    {
        falling();
        checkForMiss();
        if (Greenfoot.mousePressed(this) && !isGrabbed)
        {
            // grab the object
            isGrabbed = true;
            // the rest of this block will avoid this object being dragged UNDER other objects
            World world = getWorld();
            MouseInfo mi = Greenfoot.getMouseInfo();
            world.removeObject(this);
            world.addObject(this, mi.getX(), mi.getY());
            return;
        }
        // check for actual dragging of the object
        if ((Greenfoot.mouseDragged(this)) && isGrabbed)
        {
            // follow the mouse
            MouseInfo mi = Greenfoot.getMouseInfo();
            setLocation(mi.getX(), mi.getY());
            return;
        }
        // check for mouse button release
        if (Greenfoot.mouseDragEnded(this) && isGrabbed)
        {
            // release the object
            isGrabbed = false;
            return;
        }
    }

    public void falling()
    {
        setLocation(getX(), getY()+Greenfoot.getRandomNumber(3)+1);
        setRotation(getRotation()+2);
    }

    public void checkForMiss()
    {
        MyWorld world = (MyWorld)getWorld();
        if (isAtEdge())
        {
            gameOver gameover = new gameOver();
            world.addObject(gameover,world.getWidth()/2, world.getHeight()/2);
            //getWorld().removeObject(this);
            Greenfoot.stop();
            ((MyWorld)getWorld()).myMusic.stop();
            Greenfoot.playSound("Curb Your Enthusiasm Theme (8 Bit Version).mp3");
            
        }
    }

    public boulder()
    {
        speed = (Greenfoot.getRandomNumber(10)+5);
    }
}

import greenfoot.*;
import java.util.List;
public class boulderBarrel extends Actor
{
    private int boulderstored;
    private int score = 0;
    private boolean powerup = false;
    private int counter;
    private int getWorld;
    private boolean remove = false;
    private List <Actor> actorlist = null;
    public void act() 
    {
        lookForboulder();
        lookForteddybear();
        lookForvoodoobear();
        remove();
        //score = score +1;

        // if(powerup == true)
        // {
        // if(counter <300)
        // {
        // powerClick();
        // counter++;
        // }
        // else
        // {
        // counter = 0;
        // }
        // }    
    }    

    public void lookForboulder()
    {
        if ( canSee(boulder.class))
        {
            store(boulder.class);
            score = score +1;
            Greenfoot.playSound("Rockslide_small-Sound_Explorer-1935053448.wav");
        }
    }

    public void lookForteddybear()
    {
        MyWorld world = (MyWorld)getWorld();
        if ( canSee(teddybear.class))
        {
            store(teddybear.class);
            Greenfoot.playSound("Fairy Dust Sound Effect.wav");
            powerup = true;
            List <Actor> actors = world.getObjects(null);
            actorlist = actors;
            world.addObject (new rockBarrel(),149, 645);
            world.addObject (new boulderBarrel(),642,645);
            world.addObject (new anchorBarrel(),398,645);
            world.addObject(new counter(), 100, 40 );

            world.addObject(new rocktitle(), 149, 690);
            world.addObject(new anchortitle(), 398, 685);
            world.addObject(new bouldertitle(), 642, 690);

            score = actors.size()-8;
            counter Counter = world.getCounter();
            Counter.addScore(score);
            remove=true;
            //world.removeObjects(actors);
            //count all objects removed and add number to counter

        }
    }
    
    public void lookForvoodoobear()
    {
        MyWorld world = (MyWorld)getWorld();
        if ( canSee(voodoobear.class))
        {
            store(voodoobear.class);
            Greenfoot.playSound("Evil Laugh Cackle-SoundBible.com-957382653.wav");
            powerup = true;
            List <Actor> actors = world.getObjects(null);
            actorlist = actors;
            score = (-1)*getWorld().numberOfObjects()+6;

            counter Counter = world.getCounter();
            Counter.addScore(score);
            world.addObject (new rockBarrel(),149, 645);
            world.addObject (new boulderBarrel(),642,645);
            world.addObject (new anchorBarrel(),398,645);
            world.addObject(new counter(), 100, 40 );

            world.addObject(new rocktitle(), 149, 690);
            world.addObject(new anchortitle(), 398, 685);
            world.addObject(new bouldertitle(), 642, 690);
            remove=true;
            //world.removeObjects(actors);
            //count all objects removed and add number to counter

        }
    }

    public boolean canSee(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        return actor != null; 
    }

    public void store(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        MyWorld world = (MyWorld)getWorld();
        if(actor !=null) {
            getWorld().removeObject(actor);
            counter Counter = world.getCounter();
            Counter.addScore();
        }
    }
    
    public void remove()
    {
        MyWorld world = (MyWorld)getWorld();
        if(remove==true)
        {
            world.removeObjects(actorlist);
        }
    }
}

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class bouldertitle here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class bouldertitle extends Actor
{
    /**
     * Act - do whatever the bouldertitle wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
}

import greenfoot.*;
public class counter extends Actor
{
    private static int score = 0;
    
    public void act() 
    {
        setImage(new GreenfootImage("Score : " + score, 24, Color.RED, Color.WHITE));
    }    

    public void addScore()
    {
        score++;
    }
    public void addScore(int s)
    {
        score = score+s;
    }
    public void setScore()
    {
        score = 0;
    }
}

import greenfoot.*;
public class gameOver extends Actor
{
   public gameOver()
   {
       setImage(new GreenfootImage("Game Over", 48, Color.RED, Color.WHITE));
   }
}


import greenfoot.*;
public class player extends Actor
{
    private int score = 0;
    public void act() 
    {
        if(Greenfoot.mouseMoved(null))
        {
            MouseInfo mouse = Greenfoot.getMouseInfo();
            setLocation(getX(),mouse.getY());
        }
    }
}

import greenfoot.*;
public class rock extends Actor
{
    private GreenfootImage rock = new GreenfootImage("rock2.png");
    private int speed;
    private boolean isGrabbed;
    public void act() 
    {
        falling();
        checkForMiss();
        if (Greenfoot.mousePressed(this) && !isGrabbed)
        {
            // grab the object
            isGrabbed = true;
            // the rest of this block will avoid this object being dragged UNDER other objects
            World world = getWorld();
            MouseInfo mi = Greenfoot.getMouseInfo();
            world.removeObject(this);
            world.addObject(this, mi.getX(), mi.getY());
            return;
        }
        // check for actual dragging of the object
        if ((Greenfoot.mouseDragged(this)) && isGrabbed)
        {
            // follow the mouse
            MouseInfo mi = Greenfoot.getMouseInfo();
            setLocation(mi.getX(), mi.getY());
            return;
        }
        // check for mouse button release
        if (Greenfoot.mouseDragEnded(this) && isGrabbed)
        {
            // release the object
            isGrabbed = false;
            return;
        }
    }
    public void falling()
    {
        setLocation(getX(), getY()+Greenfoot.getRandomNumber(3)+1);
        setRotation(getRotation()+2);
    }
    public void checkForMiss()
    {
        MyWorld world = (MyWorld)getWorld();
        if (isAtEdge())
        {
            gameOver gameover = new gameOver();
            world.addObject(gameover,world.getWidth()/2, world.getHeight()/2);
            //getWorld().removeObject(this);
            Greenfoot.stop();
            ((MyWorld)getWorld()).myMusic.stop();
            Greenfoot.playSound("Curb Your Enthusiasm Theme (8 Bit Version).mp3");
            
        }
    }
    public rock()
    {
        speed = (Greenfoot.getRandomNumber(2)+1);
    }
}    

import greenfoot.*;
import java.util.List;
public class rockBarrel extends Actor
{
    private int rockstored;
    private int score = 0;
    private boolean powerup = false;
    private int counter;
    private int getWorld;
    private boolean remove = false;
    private List <Actor> actorlist = null;
    public void act() 
    {
        lookForrock();
        lookForteddybear();
        lookForvoodoobear();
        remove();
        //score = score +1;

        // if(powerup == true)
        // {
        // if(counter <300)
        // {
        // powerClick();
        // counter++;
        // }
        // else
        // {
        // counter = 0;
        // }
        // }    
    }    

    public void lookForrock()
    {
        if ( canSee(rock.class))
        {
            store(rock.class);
            score = score +1;
            Greenfoot.playSound("Blastwave_FX_CementWallHit_BW.17122.mp3");
        }
    }

    public void lookForteddybear()
    {
        MyWorld world = (MyWorld)getWorld();
        if ( canSee(teddybear.class))
        {
            store(teddybear.class);
            Greenfoot.playSound("Fairy Dust Sound Effect.wav");
            powerup = true;
            List <Actor> actors = world.getObjects(null);
            actorlist = actors;
            world.addObject (new rockBarrel(),149, 645);
            world.addObject (new boulderBarrel(),642,645);
            world.addObject (new anchorBarrel(),398,645);
            world.addObject(new counter(), 100, 40 );

            world.addObject(new rocktitle(), 149, 690);
            world.addObject(new anchortitle(), 398, 685);
            world.addObject(new bouldertitle(), 642, 690);

            score = actors.size()-8;
            counter Counter = world.getCounter();
            Counter.addScore(score);
            remove=true;
            //world.removeObjects(actors);
            //count all objects removed and add number to counter

        }
    }

    public void lookForvoodoobear()
    {
        MyWorld world = (MyWorld)getWorld();
        if ( canSee(voodoobear.class))
        {
            store(voodoobear.class);
            Greenfoot.playSound("Evil Laugh Cackle-SoundBible.com-957382653.wav");
            powerup = true;
            List <Actor> actors = world.getObjects(null);
            actorlist = actors;
            score = (-1)*getWorld().numberOfObjects()+6;

            counter Counter = world.getCounter();
            Counter.addScore(score);
            world.addObject (new rockBarrel(),149, 645);
            world.addObject (new boulderBarrel(),642,645);
            world.addObject (new anchorBarrel(),398,645);
            world.addObject(new counter(), 100, 40 );

            world.addObject(new rocktitle(), 149, 690);
            world.addObject(new anchortitle(), 398, 685);
            world.addObject(new bouldertitle(), 642, 690);
            remove=true;
            //world.removeObjects(actors);
            //count all objects removed and add number to counter

        }
    }

    public boolean canSee(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        return actor != null;
    }

    public void store(Class clss)
    {
        Actor actor = getOneObjectAtOffset(0, 0, clss);
        MyWorld world = (MyWorld)getWorld();
        if(actor !=null) {
            getWorld().removeObject(actor);
            counter Counter = world.getCounter();
            Counter.addScore();
        }
    }
    public void remove()
    {
        MyWorld world = (MyWorld)getWorld();
        if(remove==true)
        {
            world.removeObjects(actorlist);
        }
    }
}


import greenfoot.*; 
/**
 * Write a description of class rocktitle here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class rocktitle extends Actor
{
    /**
     * Act - do whatever the rocktitle wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
}

import greenfoot.*;  
public class teddybear extends Actor
{
    private GreenfootImage teddybear = new GreenfootImage("teddybear.png");
    private int speed;
    private boolean isGrabbed;
    public void act() 
    {
        falling();
        checkForMiss();
        if (Greenfoot.mousePressed(this) && !isGrabbed)
        {
            // grab the object
            isGrabbed = true;
            // the rest of this block will avoid this object being dragged UNDER other objects
            World world = getWorld();
            MouseInfo mi = Greenfoot.getMouseInfo();
            world.removeObject(this);
            world.addObject(this, mi.getX(), mi.getY());
            return;
        }
        // check for actual dragging of the object
        if ((Greenfoot.mouseDragged(this)) && isGrabbed)
        {
            // follow the mouse
            MouseInfo mi = Greenfoot.getMouseInfo();
            setLocation(mi.getX(), mi.getY());
            return;
        }
        // check for mouse button release
        if (Greenfoot.mouseDragEnded(this) && isGrabbed)
        {
            // release the object
            isGrabbed = false;
            return;
        }
    }

    public void falling()
    {
        setLocation(getX(), getY()+Greenfoot.getRandomNumber(15)+1);
        setRotation(getRotation()+2);
    }

    public void checkForMiss()
    {
        MyWorld world = (MyWorld)getWorld();
        if (isAtEdge())
        {
            //gameOver gameover = new gameOver();
            //world.addObject(gameover,world.getWidth()/2, world.getHeight()/2);
            getWorld().removeObject(this);
            //Greenfoot.stop();
        }
    }

    public teddybear()
    {
        speed = (Greenfoot.getRandomNumber(10)+5);
    }
}

import greenfoot.*;  
public class voodoobear extends Actor
{
    private GreenfootImage voodoobear = new GreenfootImage("teddybear.png");
    private int speed;
    private boolean isGrabbed;
    public void act() 
    {
        falling();
        checkForMiss();
        if (Greenfoot.mousePressed(this) && !isGrabbed)
        {
            // grab the object
            isGrabbed = true;
            // the rest of this block will avoid this object being dragged UNDER other objects
            World world = getWorld();
            MouseInfo mi = Greenfoot.getMouseInfo();
            world.removeObject(this);
            world.addObject(this, mi.getX(), mi.getY());
            return;
        }
        // check for actual dragging of the object
        if ((Greenfoot.mouseDragged(this)) && isGrabbed)
        {
            // follow the mouse
            MouseInfo mi = Greenfoot.getMouseInfo();
            setLocation(mi.getX(), mi.getY());
            return;
        }
        // check for mouse button release
        if (Greenfoot.mouseDragEnded(this) && isGrabbed)
        {
            // release the object
            isGrabbed = false;
            return;
        }
    }

    public void falling()
    {
        setLocation(getX(), getY()+Greenfoot.getRandomNumber(2)+1);
        setRotation(getRotation()+2);
    }

    public void checkForMiss()
    {
        MyWorld world = (MyWorld)getWorld();
        if (isAtEdge())
        {
            //gameOver gameover = new gameOver();
            //world.addObject(gameover,world.getWidth()/2, world.getHeight()/2);
            getWorld().removeObject(this);
            //Greenfoot.stop();
        }
    }

    public voodoobear()
    {
        speed = (Greenfoot.getRandomNumber(10)+5);
    }
}
danpost danpost

2024/10/17

#
After copying all codes into classes in greenfoot, it compiled for me. I did remove some codes, however -- only those related to sounds and images (because I did not have the required files for them. Classes with syntax errors should show with diagonal red stripes through the class icon and lines containing errors should be marked by red at the beginning of the lines. Also, the error within the line may be underlined, however, some syntax errors have these underlines show at places not exactly where the error actually is.
You need to login to post a reply.