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

2020/12/1

Highscore

1
2
3
4
5
6
7
NewbJava NewbJava

2020/12/7

#
danpost wrote...
NewbJava wrote...
I think this is correct now
Except for the name of your actors in prepare at lines 24 and 25.
should I delete those lines?
danpost danpost

2020/12/7

#
NewbJava wrote...
should I delete those lines?
Not if you want the score and high score displayed in the world. Use "scoreDisplay" and "highScoreDisplay" (without the quotes, of course).
NewbJava NewbJava

2020/12/7

#
danpost wrote...
NewbJava wrote...
should I delete those lines?
Not if you want the score and high scores displayed in the world. Use "scoreDisplay" and "highScoreDisplay".
public class MeteorsWorld extends MyWorld
{

    
    public MeteorsWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);  
        prepare(); 
        
    } 
    public void addMeteor() 
    { 
     addObject(new Meteors(),getWidth()-1,Greenfoot.getRandomNumber(getHeight()));
    }
    private void prepare() 
    {  
        Rocket Rocket = new Rocket(); 
        addObject(Rocket,100,200); 
        Rocket.setLocation(70,200);  
        addObject(scoreDisplay,55,380); 
        addObject(highScoreDisplay,525,25);
         
         
    } 
    public void Switchscreen() 
 { 
     boolean noRockets = getObjects(Rocket.class).isEmpty(); 
     if (noRockets == true) 
     { 
        Greenfoot.setWorld(new Playagain()); 
  
  
   } 
} 












}
danpost danpost

2020/12/7

#
Any errors now?
NewbJava NewbJava

2020/12/7

#
danpost wrote...
NewbJava wrote...
should I delete those lines?
Not if you want the score and high score displayed in the world. Use "scoreDisplay" and "highScoreDisplay" (without the quotes, of course).
there is an error on line 8 that "constructor MyWorld in class MyWorld can not be applied to given type"
NewbJava NewbJava

2020/12/7

#
danpost wrote...
Any errors now?
there is an error on line 8 that "constructor MyWorld in class MyWorld can not be applied to given type"
NewbJava NewbJava

2020/12/7

#
danpost wrote...
Any errors now?
import greenfoot.*;  
 
public class MyWorld extends World
{ 
    static Actor scoreDisplay;
    static Actor highScoreDisplay;
    public static int score;
    static int highScore;  
    
      
    public MyWorld()
    {    
         
        super(600, 400, 1, false);   
         
        scoreDisplay = new Scoreboard();
        highScoreDisplay = new HighScore(); 
        score = -1;
        highScore = -1;
        adjustScore(1); 
         
         
         
          
           
          
    }   
       
     
    static void adjustScore(int amt)
    {
        score += amt;
        GreenfootImage img = new GreenfootImage("Score: "+score, 24, Color.RED, Color.BLACK);
         
        if (score > highScore)
        {
            highScore = score;
            img = new GreenfootImage("High score: "+highScore, 24, Color.RED, Color.BLACK);
            highScoreDisplay.setImage(img);
        }
    } 
     
    public void act() 
    {  
        Greenfoot.setWorld(new MeteorsWorld()); 
        
        
         
    }    
    
    
}
NewbJava NewbJava

2020/12/7

#
danpost wrote...
Any errors now?
lines 16 an 17 have errors because those classes have been deleted.
danpost danpost

2020/12/7

#
NewbJava wrote...
there is an error on line 8 that "constructor MyWorld in class MyWorld can not be applied to given type"
You seem to have removed the other constructor from MyWorld. Refer back and restore it back into the class. Also, you change the super call in the main MyWorld constructor. Restore it, also. Then, add the following 3rd constructor to the class:
public MyWorld(int w, int h, int c, boolean b)
{
    super(w, h, c, b);
}
danpost danpost

2020/12/7

#
NewbJava wrote...
lines 16 an 17 have errors because those classes have been deleted.
You seem to have changed those lines also. Restore them.
NewbJava NewbJava

2020/12/7

#
danpost wrote...
NewbJava wrote...
there is an error on line 8 that "constructor MyWorld in class MyWorld can not be applied to given type"
You seem to have removed the other constructor from MyWorld. Refer back and restore it back into the class. Also, you change the super call in the main MyWorld constructor. Restore it, also. Then, add the following 3rd constructor to the class:
public MyWorld(int w, int h, int c, boolean b)
{
    super(w, h, c, b);
}
 
public class MyWorld extends World
{
    static Actor scoreDisplay;
    static Actor highScoreDisplay;
    static int score;
    static int highScore;
      
    public MyWorld()
    {
        super(800, 600, 1);
        scoreDisplay = new SimpleActor();
        highScoreDisplay = new SimpleActor();
        score = -1;
        highScore = -1;
        adjustScore(1);
    }
      
    public MyWorld(int w, int h, int c)
    {
        super(w, h, c);
    }
      
    static void adjustScore(int amt)
    {
        score += amt;
        GreenfootImage img = new GreenfootImage("Score: "+score, 24, Color.RED, new Color(0, 0, 0, 0));
        scoreDisplay.setImage(img);
        if (score > highScore)
        {
            highScore = score;
            img = new GreenfootImage("High score: "+highScore, 24, Color.RED, new Color(0, 0, 0, 0));
            highScore.setImage(img);
        }
    }
      
    public void act()
    {
        Greenfoot.setWorld(new MeteorWorld());
    }
}
NewbJava NewbJava

2020/12/7

#
do you mean to refer back to this?
danpost danpost

2020/12/7

#
NewbJava wrote...
do you mean to refer back to this?
Yes
NewbJava NewbJava

2020/12/7

#
danpost wrote...
NewbJava wrote...
do you mean to refer back to this?
Yes
import greenfoot.*;  
 
public class MyWorld extends World
{ 
    static Actor scoreDisplay;
    static Actor highScoreDisplay;
    public static int score;
    static int highScore;  
    
      
    public MyWorld()
    {    
         
        super(600, 400, 1, false);   
         
        scoreDisplay = new SimpleActor();
        highScoreDisplay = new SimpleActor();
        score = -1;
        highScore = -1;
        adjustScore(1);
         
         
         
          
           
          
    }    
    
    public MyWorld(int w, int h, int c)
    {
        super(w, h, c);
    }
       
     
    static void adjustScore(int amt)
    {
        score += amt;
        GreenfootImage img = new GreenfootImage("Score: "+score, 24, Color.RED, new Color(0, 0, 0, 0));
        scoreDisplay.setImage(img);
        if (score > highScore)
        {
            highScore = score;
            img = new GreenfootImage("High score: "+highScore, 24, Color.RED, new Color(0, 0, 0, 0));
            highScore.setImage(img);
        }
    }
     
    public void act() 
    {  
        Greenfoot.setWorld(new MeteorsWorld()); 
        
        
         
    }    
    
    
}
NewbJava NewbJava

2020/12/7

#
danpost wrote...
NewbJava wrote...
do you mean to refer back to this?
Yes
error on line 44 saying "int cannot be dereferenced".
There are more replies on the next page.
1
2
3
4
5
6
7