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

2018/11/17

Please Help With setScore and getScore

Sean03 Sean03

2018/11/17

#
    private int Score = 0;

    
    
    /**
     * Act: move up and down when cursor keys are pressed.
     */
    public void act() 
    {
        checkKeyPress();
        if(isTouching(Bacteria.class))
        {
            setScore(getScore() + 20)
            {
                
            }
            
            
        }
    }
Sean03 Sean03

2018/11/17

#
it wont work
drewr1122 drewr1122

2018/11/17

#
i see someones trying to make an Agar.io game...
drewr1122 drewr1122

2018/11/17

#
define set score and get score as two different methods rather than incorporating into the act method. i.e. public int getScore() { return score; }
Sean03 Sean03

2018/11/17

#
    private int Score = 0;

    
    public int getScore()
    {
        return Score;
    }
    /**
     * Act: move up and down when cursor keys are pressed.
     */
    public void act() 
    {
        checkKeyPress();
        if(isTouching(Bacteria.class))
        {
            setScore(getScore() + 20)
            {
                
            }
  
            
        }
    }
Sean03 Sean03

2018/11/17

#
im still get errors about set score
Sean03 Sean03

2018/11/17

#
please help someone
danpost danpost

2018/11/18

#
Sean03 wrote...
im still get errors about set score please help someone
drewr1122 provided one of the two methods. It was your task to create the other one (setScore). However, methods like setScore and getScore are truly only helpful for access to the score from other classes. The WhiteCell class already has access to the score because it is defined in its class -- so those methods are not needed at all (at least for use in the WhiteCell class).
drewr1122 drewr1122

2018/11/19

#
Why would you need a setScore function? are you starting with different scores on different levels? If you want to add scores, create a function that simply adds an integer of change (in other words an amount of points) to your current score.
You need to login to post a reply.