I have a game and there's a car that you drive, and when you hit a coin, the car 'eats' the coin and every coin is a point. I have a field 'public int points'. With this piece of code, I want to display the points:
Problem is, the field 'public int points' is an integer, and the img.drawString method expects a string as a parameter.
This is the code for the points system:
Because points is an integer, I can do points + 1 for example. Can I do this with string too, if I change the field 'public int points' to 'public String points'? Can I also do this when points is a string: points = points + "1"?
After this works, how can I display the value of the field points from another class. I want to make another class to draw the text (img.drawString()).
Anyone knows how to solve this?
GreenfootImage img = new GreenfootImage(150, 30); img.drawString(points, 3, 20); setImage(img);
public void getCoin() { while (points < 30) { if (canSee(Coin.class)) { eat(Coin.class); } else { break; // don't touch a coin, so stop the loop } points += 1; // add 1 if(points == 30){ Greenfoot.stop(); } } }