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

2019/11/19

Error

Nate2002 Nate2002

2019/11/19

#
I keep getting the java.lang.RuntimeException error when I publish my game, is there anything I can do to fix that, so my game can work on the site?
Nate2002 Nate2002

2019/11/19

#
Here is the code for all of my Worlds
public class MyWorld extends World
{
private int enterDelayCount;
    public boolean added = false;
    static GreenfootSound music = new GreenfootSound("Title Screen.mp3");
    /**
     * Constructor for objects of class MyWorld.
     * 
     */
    public MyWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1000, 600, 1);
        Greenfoot.start();
        prepare();
     
    }
    public void act()
    {
        try
        {
        music.playLoop();
        enterDelayCount ++;
        
        if (Greenfoot.isKeyDown("enter") && enterDelayCount > 60 && !added)
        {

      
            removeObjects(getObjects(InsertCoin.class));

            addObject(new Arrow(),50,425);
            added = true;
            Greenfoot.setSpeed(49);
        }
        
    }
    catch (IllegalStateException p)
        {

        }
}
    private void prepare()
    {
        Single Single = new Single();
        addObject(Single, 500,425);
        Multi Multi = new Multi();
        addObject(Multi, 500, 525);
        InsertCoin InsertCoin = new InsertCoin();
        addObject(InsertCoin, 850, 150);
    }
}
public class SingleWorld extends World
{
    public int time = 0;
    public static int score = 0 ;
    static GreenfootSound music = new GreenfootSound("209 - fire emblem.mp3");
    /**
     * Constructor for objects of class SingleWorld.
     * 
     */
    public SingleWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1);
         GreenfootImage back = getBackground();
        back.setColor(Color.BLACK);
        back.fill();
        prepare();
        score++;
        time++;
    }
    public void act()
    {
        music.playLoop();
        countTime();
        
        if(Greenfoot.getRandomNumber(750) <5)
        {
            addObject(new BadShip(), (Greenfoot.getRandomNumber(200) + 200), (0));
        }
        if(Greenfoot.getRandomNumber(500) <5)
        {
            addObject(new BadShip1(), (Greenfoot.getRandomNumber(200) + 200), (0));
        }
        if(Greenfoot.getRandomNumber(1000) <5)
        {
            addObject(new BadShip2(), (Greenfoot.getRandomNumber(200) + 200), (0));
        }
        if(Greenfoot.getRandomNumber(1000) <5)
        {
            addObject(new Planet1(), ((100)), 0);
        }
        if(Greenfoot.getRandomNumber(1000) <5)
        {
            addObject(new Planet2(), ((700)), 0);
        }
        if(Greenfoot.getRandomNumber(1000) <5)
        {
            addObject(new Planet3(), ((100)), 0);
        }
        if(Greenfoot.getRandomNumber(1000) <5)
        {
            addObject(new Planet5(), ((700)), 0);
        }
    }
    public void countTime()
    {
        time++;
        if(time % 5 == 1)
        {
            addScore(1);
            showScore();
        }
        // showTime();
    }
    public void addScore(int points)
    {
        score = score + points;
        points = time + score;
        showScore();
        

    }
    public void showScore()
    {
        showText("Pts:  " + score, 600, 50);
        // showText("Pts: " + time, 75, 25);

    }
    public void showTime()
    {
       showText("Pts: " + time/60, 600, 50);
       
    }
    private void prepare()
    {
        Ship Ship = new Ship();
        addObject(Ship, 500,500);
        LifeCounter LifeCounter = new LifeCounter();
        addObject(LifeCounter, 200,50);
    }
}
public class MultiWorld extends World
{
    static GreenfootSound music = new GreenfootSound("Multi.mp3");
    /**
     * Constructor for objects of class MultiWorld.
     * 
     */
    public MultiWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1000, 600, 1); 
        GreenfootImage back = getBackground();
        back.setColor(Color.BLACK);
        back.fill();
         prepare();
         Ship1.life=3;
         Ship2.life=3;
    }
    public void act()
    {
        music.playLoop();
        
    }
    private void prepare()
    {
       Ship1 Ship1 = new Ship1();
        addObject(Ship1, 900,500); 
        
       Ship2 Ship2 = new Ship2();
        addObject(Ship2, 100,500); 
        P1Life P1Life = new P1Life();
        addObject(P1Life, 200,50);
        P2Life P2Life = new P2Life();
        addObject(P2Life, 800,50);
    }
}
{
    public int time;
    GreenfootSound music = new GreenfootSound("Winner.mp3");

    /**
     * Constructor for objects of class P1Win.
     * 
     */
    public P1Win()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1);
        prepare();
        
        GreenfootImage back = getBackground();
        back.setColor(Color.BLACK);
        back.fill();
        showText("Player 1 Wins!", 400, 100);
        
    }
    public void act()
    {
        music.playLoop();
        time++;
        if(time==60)
       {
          addObject(new Splode(), (650), (300)); 
          time = 0;
       }
    }
    private void prepare()
    {
        Win1 Win1= new Win1();
        addObject(Win1, 300, 300);
        
    }
}
public class P2Win extends World
{
 public int time;
 GreenfootSound music = new GreenfootSound("Winner.mp3");
    /**
     * Constructor for objects of class P2Win.
     * 
     */
    public P2Win()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1);
        prepare();
        
        GreenfootImage back = getBackground();
        back.setColor(Color.BLACK);
        back.fill();
        showText("Player 2 Wins!", 400, 100);
        
    }
    public void act()
    {
        music.playLoop();
        time++;
        if(time==60)
       {
          addObject(new Splode(), (300), (300)); 
          time = 0;
       }
    }
    private void prepare()
    {
        Win2 Win2= new Win2();
        addObject(Win2, 500, 300);
        
    }
}
public class SingleGameOver extends World
{
public static int highestScore;
    public int score;
    public int time = 0;
  GreenfootSound music = new GreenfootSound("GameOver.mp3");
   
    /**
     * Constructor for objects of class SingleGameOver.
     * 
     */
    public SingleGameOver()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1); 
        GreenfootImage back = getBackground();
        back.setColor(Color.BLACK);
        back.fill();
        prepare();
        if(SingleWorld.score > highestScore)
        {
            highestScore = SingleWorld.score;
            showText("New High Score!",400,300);
            
        }
        else
        {
        showText("Your Score was: "+ SingleWorld.score,400,325);
    }
    showText("Your High Score is: " + highestScore,400,350);
    
    }
    public void act()
    {
        music.playLoop();
        if(Greenfoot.getRandomNumber(600) < 5)
       {
          addObject(new Splode(), (Greenfoot.getRandomNumber(100) +250), (Greenfoot.getRandomNumber(200) + 350)); 
       }
        if(Greenfoot.getRandomNumber(600) < 5)
       {
          addObject(new Splode(), (Greenfoot.getRandomNumber(500) +250), (Greenfoot.getRandomNumber(200) + 350)); 
       }
    }
    private void prepare()
    {
        GameOer GameOer = new GameOer();
        addObject(GameOer, 400,200);
    }
}
nolttr21 nolttr21

2019/11/19

#
You can't have any static variables in the world that is initialized at the start of the scenario.
Nate2002 Nate2002

2019/11/21

#
Thanks it works now :)
You need to login to post a reply.