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

2016/9/16

score problem

1
2
danpost danpost

2016/9/25

#
From what I can tell, at least one C1 object and one Rahmat object are placed in your Background1 world. I can see that the Background1 world leads to a Level2 world, which would make the Background1 world a first level world. The Q2 world is not clear as far as what it is for. It could be a menu or option type world or it could be a side level world for gameplay. Knowing what it is for would help to better determine what is needed in your code. Another thing that is puzzling is what the Score objects in the Background1 and Q2 classes are for. What value will be shown by those objects? Where are they being updated from?
Dayuyu Dayuyu

2016/9/25

#
Background1 is the first level. Rahmat at Background1 At Background1 i put monkey...when actor(rahmat) touch the monkey the Q2 while appear. Q2 world i make for answer the question...that i put 4 button. c1 object at Q2wourld as button.. a1 right answer then score will increase that i make before and the score is increase. c1 is wrong answer that i try to decrease. After they choose button at Q2 the game will back to Background1. Score objects in the Background1 is i put the score value(view score total after answer right) that why in Q2 classes is for return the value... if i do not put Score objects in the Background1 and Q2 classes the error cannot find symbol will show. correct me if I'm wrong because i new in greentfoot and was just about to learn...
danpost danpost

2016/9/25

#
I must presume that you will have more worlds like the Q2 world for more questions. So, you have multiple gameplay level worlds and will have, or already do have, multiple question worlds. Is this correct?
Dayuyu Dayuyu

2016/9/27

#
yes i have about 12question so the world that have question have 12....i name the world like Q - Q6 for level 1... and level 2 Q21 - Q29..
danpost danpost

2016/9/27

#
Dayuyu wrote...
yes i have about 12question so the world that have question have 12....i name the world like Q - Q6 for level 1... and level 2 Q21 - Q29..
In your Background1 world class:
// change this (and remove from all classes equivalent code, as well)
Score score = new Score();
 
public Score getScore()
{
    return score;
}

// to this
static Score score;

public static Score getScore()
{
    return score;
}
Then, in your Background1 world constructor, add the following line:
score = new Score();
This will allow any of your Q classes or even another world class to access the Score object:
// from any class but the Background1 class
Score score = Background1.getScore();
To decrement the score, you can use this:
Background1.getScore().score--;
You need to login to post a reply.
1
2