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

2012/10/31

MAKE A GOAL COUNT

DOGGY DOGGY

2012/10/31

#
IM MAKING A GAME ONLY NOW IM BUSY CODING THE SCORE PART. I HAVE TWO GOALS (WHICH ARE ACTUALLY PICTURES PUT IN THE GAME AS AN GOAL. I WANT THE GAME TO ADD AN POINT TO THE SCORE OF THE PLAYER ONCE THE OTHER PLAYER MANAGED TO GET THE BALL IN THE GOAL. I ALREADY STARTED A SMALL CODE WHICH GOES BY: public void checkGoal1() { if (getOneIntersectingObject(Voetbal.class)!= null) { //what it need to do } } THIS IS MY GOAL1 CLASS, I ALSO HAVE AN GOAL2 CLASS, A SCOREBORD CLASS, A MENU CLASS AND A BALL CLASS I USED THE getOneIntersectingObject TO NOTIFY THE INTERACTION BETWEEN THE BALL AND THE GOAL. CAN ANYBODY HELP ME?
Gevater_Tod4711 Gevater_Tod4711

2012/10/31

#
You probably want the score on the scorebord. So you need to count up a variable in the scorebord like this:
//in the goal 1 class;
//you need to import java.util.List to use this;

public void checkGoal1() {
    if (getOneIntersectingObject(Voetbal.class) != null) {
        List<Scorebord> scorebord = getWorld().getObjects(Scorebord.class);
        if (!scorebord.isEmpty()) {
            Scorebord score = scorebord.get(0);
            score.countUpGoal_1();
        }
    }
}



//in the scorebord class;

private int score_1 = 0;
private int score_2 = 0;

public void countUpGoal_1() {
    score_1++;
}

public void countUpGoal_2() {
    score_2++;
}
also you need the scorebord to print the scores. Otherwile you cant see them.
DOGGY DOGGY

2012/11/1

#
THANKYOU FOR YOUR REPLY, IM TRYING TO WRITE THE CODE FOR THE SCOREBORD TO PRINT THE SCORES BUT THIS IS MY FIRST TIME WORKING WITH A SCOREBORD. SO I DONT REALLY KNOW HOW TO WRITE THIS CAN YOU HELP ME WITH THIS?
Gevater_Tod4711 Gevater_Tod4711

2012/11/1

#
if it's your first time to programm a scoreboard you should use the greenfoot scoreboard. You just have to click on the edit button in your scenario and click import class. Then you choose the counter and import it. The rest probably is already programmed by greenfoot.
You need to login to post a reply.