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 | import greenfoot.*; /** * This is a stick man. Make him run and jump. * * @author * @version */ public class Stickman extends Actor { /** * Make the stickman act. */ public void act() { //3.31: Make the stickman move to the right so that when you run scenario he walks over to the right side of the screen// move( 5 ); int soundLevel; moveLeftIfNoise(); //The stickman moves at edge if (isAtEdge()) gameOver(); } } /* 3.32 Using an if statemt and the micorphone input method to make sticman move right only when you make some noise * */ public void soundLevel() { int soundLevel // Greenfoot getMicLevel value is stored in the soundLevel// soundLevel = Greenfoot.getMicLevel(); //It checks whether if soundLevel is greater than three// if (soundLevel> 3 ) { /* It allows the stickman to move according to the sound level */ move(soundLevel): } } /** 3.34 Move the code that moves left when you make noise into its own method.Call this method moveLeftIfNoise.Test. * */ public Void moveLeftIfNoise () { /* This method will play sound while moving left */ Greenfoot.playSound( "slurp.wav" ); //This allows the stickman to move left// move(- 4 ); } } /**3.35 Add another method to your class called gameOver.This method should be called if the stickman reaches the edge of the screen */ public void gameOver() { //This predefined method is used to play the sound// Greenfoot.playSound( "slurp.wav" ); //This predefined method is used to stop the stickman Greenfoot.stop(); } } |

