I want to add my end score into my game over screen and winnerscreen...I've tried a few things with system out println
but it didn't work though


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 | public class GAMEOVERSCHERM extends World { /** * Constructor for objects of class GAMEOVERSCHERM. * */ public GAMEOVERSCHERM() { super ( 400 , 300 , 1 ); Greenfoot.playSound( "fail-trombone-03.mp3" ); addObject( new TRYAGAIN(), 200 , 80 ); endScore(); } public void endScore() { Vracht vracht = new Vracht(); Counterve counterve = new Counterve(); drawString(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // previously declared and used instance field int score; // for game over world int wide = getWorld().getWidth() * getWorld().getCellSize(); int high = getWorld().getHeight() * getWorld().getCellSize(); World goWorld = new World(wide, high, 1 ){}; GreenfootImage bg = goWorld.getBackground(); bg.setColor(java.awt.Color.lightGray); bg.fill(); String text = "Game Over\n\nScore: " +score; GreenfootImage textImage = new GreenfootImage(text, 84 , java.awt.Color.orange, null ); bg.drawImage(textImage, (bg.getWidth()-textImage.getWidth())/ 2 , (bg.getHeight()-textImage.getHeight())/ 2 ); Greenfoot.setWorld(goWorld); Greenfoot.stop(); |
1 2 3 | Actor textActor = new Actor(){}; textActor.setImage(textImage); goWorld.addObject(textActor, wide/ 2 , high/ 2 ); |