Ok I need help with this... I've looked through tutorials and the forms and am still just lost.
In my Battlefield world I have scoreCounter actor. It works just fine, but I need to return the value of the currentScore on to the Highscore world. I gather that in order to do this I need a "reference" but I don't understand the relationship between these things. How can I pass on the value of currentScore to be used by actors in the Highscore world?
I am not quite sure what code I should share that would be helpful to answering this question, if any. Regardless here is my code for the scoreCounter actor...
You can kind of ignore the "giveScore" part... just part of a sad attempt. Thanks in advance...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; // Because black text isn't going to work. import java.awt.Font; //Because default font is lame. /** * This Actor displays the base score, incrementing while the Player is alive. */ public class ScoreCounter extends Actor { //sets inital score private int score = 0 ; public void act() { updateScore(); giveScore(); } public boolean detectPlayer() { return !getObjectsInRange( 1000 , Player. class ).isEmpty(); } public void updateScore() { // draws a String with the added score in the image. //increases timer over time. if (detectPlayer()) { score=score+ 1 ; } //creates and updates image setImage ( new GreenfootImage( 200 , 40 )); GreenfootImage img = getImage(); //current image img.clear(); //erase old score //customizes font float fontSize = 20 .0f; Font font = img.getFont().deriveFont(fontSize); img.setFont(font); //draws the image img.setColor(Color.WHITE); img.drawString( "Experience: " + score, 0 , 20 ); //display new score } public int giveScore() { int currentScore = score; return currentScore; } } |