Im modifying the little crab scenario for my school's comp sci class. On my 3rd level i want it to play certain sounds and music at certain points when conditions are met in the world. When i get to that level it won't work. Help. Code for lvl not working is pasted.
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 60 61 62 63 64 65 66 67 68 69 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Digdug here. * * @author (your name) * @version (a version number or a date) */ public class Digdug extends World { /* * DD = Intro * DDOM= One left * DDEOG = End * DDW = Win */ private GreenfootSound DD; private GreenfootSound DDOM; private GreenfootSound DDEOG; private GreenfootSound DDW; public void sounds() { GreenfootSound DD = new GreenfootSound ( "DD.wav" ); GreenfootSound DDOM = new GreenfootSound ( "DD_OneMore.wav" ); GreenfootSound DDEOG = new GreenfootSound ( "DD_EOG.wav" ); GreenfootSound DDW = new GreenfootSound ( "DD_Win.wav" ); DD.play(); } public void LvlChange() { int actors = numberOfObjects(); if (actors == 3 ) { DD.stop(); DDOM.play(); } if (actors == 2 ) { DDOM.stop(); DDW.play(); Greenfoot.setWorld( new Pacman()); } } /** * Constructor for objects of class Pacman. * */ public Digdug() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 1150 , 600 , 1 ); addObject( new Digdugman(),Greenfoot.getRandomNumber( 1150 ),Greenfoot.getRandomNumber( 600 )); addObject( new Frygar(),Greenfoot.getRandomNumber( 1150 ),Greenfoot.getRandomNumber( 600 )); populate(); } public void populate() { for ( int i= 0 ;i < 2 ; i++) { addObject( new Digdugmon(),Greenfoot.getRandomNumber( 1150 ),Greenfoot.getRandomNumber( 600 )); } } public void act() { LvlChange(); } } |