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

2014/5/21

I want a score counter!

HBMC HBMC

2014/5/21

#
This is my code for my bug:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.*;
/**
 * Write a description of class bogar here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class bogar extends Actor
{
    int pont = 0;
    /**
     * Act - do whatever the bogar wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        mozgas();
        eves();
    }
    public void mozgas(){
        if(Greenfoot.isKeyDown("left")){
            turn (-3);
        }
        if(Greenfoot.isKeyDown("right")){
            turn (3);
        }
        if(Greenfoot.isKeyDown("down")){
            move(-2);
        }
        if(Greenfoot.isKeyDown("up")){
            move(2);
        }
        // Add your action code here. 
    }
    public void eves (){
        Actor kaja;
        kaja = getOneObjectAtOffset(0,0,kaja.class);
        if(kaja != null){
            World hatter;
            hatter = getWorld();
            hatter.removeObject(kaja);
            pont = pont + 15;
            System.out.println("Eddigi pontjaid: " + pont);
            
            
        }
    
        
    }
    
    public int pont()
    {
        return pont;
    }


        

}
ANd this for my massage:
import greenfoot.*;
import java.awt.Color;

public class Message extends Actor
{
    public Message()
    {
        updateImage("Eddigi pontjaid: " + getWorld().getObjects(bogar.class.pont));
    }
    
    public Message(String text)
    {
        updateImage(text);
    }
    
    public void setText(String text)
    {
        updateImage(text);
    }
    
    private void updateImage(String text)
    {
        setImage(new GreenfootImage(text, 30, Color.black, Color.white));
    }
}
pont=score Eddigi pontjaid=Your score What's wrong?
erdelf erdelf

2014/5/21

#
in your message class in line 8, you are trying to get all the objects of the bogar.class.pont I am not even quite sure what that is doing, but i think it should give you an error because u gave no class change the line to
 updateImage("Eddigi pontjaid: " + ((bogar)getWorld().getObjects(bogar.class).get(0)).pont())); 
You need to login to post a reply.