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

2018/5/8

Having trouble with score counter

DoubleShoot DoubleShoot

2018/5/8

#
Is there anyway to update the score with showText? heres my code
myworld class:

    Counter counter = new Counter();
    public Counter getCounter()
    {
        return counter;
    }
    
    public void displayScore()
    {
        showText("Red: " + redBall, 50, 410);
        score++;
        showText("blue: " + blueBall, 50, 890);
        score++;
    }

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
 
/**
 * Write a description of class Counter here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Counter extends Actor
{
    int score = 0;
    /**
     * Act - do whatever the Counter wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
    }
    

     
    public void addScore()
    {
        score++;
    }
}
danpost danpost

2018/5/9

#
Remove line 2 from the Counter class -- this one:
import java.awt.Color;
You need to login to post a reply.