this is my code for the world and scoreboard (class name = score), i have no syntax errors but the text is not appearing. what am i doing wrong?
SPACE:
SCORE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | public class Space extends World { private Player1 P1; Score scoreCounter = new Score( "Score: " ); /** * Constructor for objects of class Space. * */ public Space() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 1000 , 500 , 1 ); Player1 P1 = new Player1(); addObject(P1, 350 , 350 ); addObject(scoreCounter, 950 , 490 ); addRocks(); } |
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 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; import java.awt.Graphics; import java.awt.Font; /** * Write a description of class Score here. * * @author Juwan * @version P.Bravo(2) */ public class Score extends Actor { private static final Color textColor = new Color( 225 , 180 , 150 ); public int vos = 0 ; private String text; private int stringLength; GreenfootImage image = getImage(); Space space = (Space) getWorld(); Font font = image.getFont(); public Score() { this ( "" ); } public Score(String prefix) { text = prefix; stringLength = (text.length() + 2 ) * 10 ; setImage( new GreenfootImage(stringLength, 24 )); image.setFont(font.deriveFont( 24 .0F)); image.setColor(textColor); updateImage(); } /** * Act - do whatever the Score wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { vos++; updateImage(); } public int getVOS() { return vos; } public void updateImage() { image.clear(); image.drawString(text + vos, 1 , 12 ); } } |