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

2019/6/20

Adding score counter

dionzeka99 dionzeka99

2019/6/20

#
Hello guys, I am programming the Space Invaders game and I created a Counter class to add score each time my player kills an Alien. Anyway I have three kind of aliens and I want to add a different number of score to any of my aliens Example : Alien 1 ; +20, Alien 2 ; + 30 etcc.. Here's my code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * 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 Counter() 
    {
      setImage(new GreenfootImage("Score : " + score, 30, Color.WHITE, Color.BLACK));
    }   
    
    public void act() 
    {
      setImage(new GreenfootImage("Score : " + score, 30, Color.WHITE, Color.BLACK));
    }   
    
    public void addScore()
    {
      score++;
    }
}
Counter Class
danpost danpost

2019/6/20

#
Do you create and add a Counter object into the world? What is your Actor class substructure like (what extends what)? What is the current codes for the bullets and the aliens?
You need to login to post a reply.