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

2020/12/1

Highscore

2
3
4
5
6
7
8
danpost danpost

2020/12/7

#
NewbJava wrote...
error on line 44 saying "int cannot be dereferenced".
Okay, "highScore" there should be "highScoreDisplay".
NewbJava NewbJava

2020/12/7

#
danpost wrote...
NewbJava wrote...
error on line 44 saying "int cannot be dereferenced".
Okay, "highScore" there should be "highScoreDisplay".
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));
            highScoreDisplay.setImage(img);
        }
    }
     
    public void act() 
    {  
        Greenfoot.setWorld(new MeteorsWorld()); 
        
        
         
    }    
    
    
}
NewbJava NewbJava

2020/12/7

#
Is this what I needed to do from the previous directions.
danpost danpost

2020/12/7

#
NewbJava wrote...
Is this what I needed to do from the previous directions.
Yes. Now, remove the ", false" from line 14 and add the 3rd constructor given previously.
NewbJava NewbJava

2020/12/7

#
danpost wrote...
NewbJava wrote...
Is this what I needed to do from the previous directions.
Yes. Now, remove the ", false" from line 14 and add the 3rd constructor given previously.
Is this the previous constructor your referring to and do I use this to replace lines 11-14?
public MyWorld(int w, int h, int c, boolean b)
{
    super(w, h, c, b);
}
danpost danpost

2020/12/7

#
NewbJava wrote...
Is this the previous constructor your referring to and do I use this to replace lines 11-14? << Code Omitted >>
Yes -- referring to that. No -- not to replace; but, to add in addition to.
NewbJava NewbJava

2020/12/7

#
danpost wrote...
NewbJava wrote...
Is this the previous constructor your referring to and do I use this to replace lines 11-14? << Code Omitted >>
Yes -- referring to that. No -- not to replace; but, to add in addition to.
but didn't I already at it in lines 29-32
NewbJava NewbJava

2020/12/7

#
but didn't I already add it in lines 29-32?
danpost danpost

2020/12/7

#
NewbJava wrote...
but didn't I already at it in lines 29-32
It not the same thing.
NewbJava NewbJava

2020/12/7

#
danpost wrote...
NewbJava wrote...
but didn't I already at it in lines 29-32
It not the same thing.
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);   
         
        scoreDisplay = new SimpleActor();
        highScoreDisplay = new SimpleActor();
        score = -1;
        highScore = -1;
        adjustScore(1);
         
         
         
          
           
          
    }    
    
    public MyWorld(int w, int h, int c, boolean b)
{
    super(w, h, c, b);
}
    
    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));
            highScoreDisplay.setImage(img);
        }
    }
     
    public void act() 
    {  
        Greenfoot.setWorld(new MeteorsWorld()); 
        
        
         
    }    
    
    
}
NewbJava NewbJava

2020/12/7

#
danpost wrote...
NewbJava wrote...
but didn't I already at it in lines 29-32
It not the same thing.
Ok is this correct?
danpost danpost

2020/12/7

#
Okay, now, errors?
NewbJava NewbJava

2020/12/7

#
danpost wrote...
Okay, now, errors?
On 16 and 17
NewbJava NewbJava

2020/12/7

#
danpost wrote...
Okay, now, errors?
because there there are no classes called SimpleActor
danpost danpost

2020/12/7

#
NewbJava wrote...
On 16 and 17
You probably still have not created an Actor subclass called SimpleActor.
There are more replies on the next page.
2
3
4
5
6
7
8