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

2016/9/16

Score Counter

NAMYA0303 NAMYA0303

2016/9/16

#
can anyone pls help me out i dont know what to type in my actor class about counter my world class code -
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class MeteoritePopOut here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MeteoritePopOut extends World
{
    
    /**
     * Constructor for objects of class MeteoritePopOut.
     * 
     */
    public MeteoritePopOut()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1); 
        prepare();
    }
    

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */


 
score score = new score();
 
public score getScore()
{
    return score;
}
}
my score class code-
import greenfoot.*;
import java.awt.Color;
 
public class score extends Actor
{
    int score = 0;
    public void act()   
    {    
        setImage(new GreenfootImage("Score : "+ score, 34, Color.GREEN,  Color.BLACK));
    }
     
    public void addscore()
    {
        score+=2;
    }
}

(i have removed the prepare section from my world class as it was too long while posting this code)
Super_Hippo Super_Hippo

2016/9/16

#
This looks quite the same as this thread.
You need to login to post a reply.