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

2012/3/9

Live Scores... :)

Omniscience Omniscience

2012/3/9

#
And I'm back! This time... I'm in need of making a score board, that increments the score of the player after set intervals of time. I am planning on how to do this: here's the pseudo code of how I think to do it (getting practise for the exam)... but how to convert into real java? STRING score = "(integer) i" ; INTEGER i = 0; INTEGER frame = 0; METHOD drawScore { IMG scoreBoard = new Image (dimensions,dimensions); scoreBoard.drawString(score, 0, 0); } METHOD incrementScore { frame = frame + 1; IF (frame % 20 = 0) { i = i+1; }
DonaldDuck DonaldDuck

2012/3/9

#
Using your code, here it is. int i = 0 int score = i ; int frame = 0; void drawScore { GreenfootImage scoreBoard = new Image (dimensions,dimensions); //dimensions up to you scoreBoard.drawString(Integer.toString(score), 0, 0); //string placement should be have the x coordinate (first one) greater than 0 depending on string length and about half way down the image height so that you can see all letters setImage(scoreBoard); } void incrementScore() { frame = frame + 1; if(frame % 20 == 0) { //increase the % x to make the wait time longer i = i+1; } public void act() { incrementScore(); drawScore(); }
You need to login to post a reply.