Hi, so I am working on a game for school and I need to make a scoreboard. When I first made it, it wasn't actually counting whenever I picked something up like it was meant to. I asked my friends for help but for some reason their code didn't work for me. What can I do? I need the answer ASAP since I am going on holiday tomorrow and can't work on it there. Lines 45 - 60 below are related to my scoreboard.
That's my code ^^^^^
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | import greenfoot.*; /** * This class defines a crab. Crabs live on the beach. */ public class Crab extends Actor { private String[] down; private String[] up; public String[] left; public String[] right; public int frameCounterLeft; public int frameCounterRight; public int frameCounterDown; public int frameCounterUp; public int wormsEaten; public Crab() { down = new String[ 4 ]; for ( int n = 0 ; n<down.length;n++) { down[n]= "SansDown" +n+ ".gif" ; } up = new String[ 4 ]; for ( int n = 0 ; n<up.length;n++) { up[n]= "SansUp" +n+ ".gif" ; } left = new String[ 4 ]; for ( int n = 0 ; n<left.length;n++) { left[n]= "SansLeft" +n+ ".gif" ; } right = new String[ 4 ]; for ( int n = 0 ; n<right.length;n++) { right[n]= "SansRight" +n+ ".gif" ; } frameCounterLeft= 0 ; frameCounterRight= 0 ; frameCounterDown= 0 ; frameCounterUp= 0 ; } public void act() { wormsEaten = 0 ; movement (); getWorld().showText( "Score: " +wormsEaten, 100 , 50 ); if ( isTouching(Worm. class ) ) { wormsEaten = wormsEaten + 1 ; removeTouching(Worm. class ); Greenfoot.playSound( "slurp.wav" ); } if (wormsEaten == 6 ) { WinWorld win = new WinWorld(); Greenfoot.setWorld(win); } } public void movement () { if (Greenfoot .isKeyDown( "a" )) { move(- 5 ); if (frameCounterLeft< 4 ) { setImage (left[frameCounterLeft]); frameCounterLeft++; } else { frameCounterLeft= 0 ; } } if (Greenfoot .isKeyDown( "d" )) { move( 5 ); if (frameCounterRight< 4 ) { setImage (right[frameCounterRight]); frameCounterRight++; } else { frameCounterRight= 0 ; } } if (Greenfoot .isKeyDown( "s" )) { setLocation(getX(),getY()+ 5 ); if (frameCounterDown< 4 ) { setImage (down[frameCounterDown]); frameCounterDown++; } else { frameCounterDown= 0 ; } } if (Greenfoot .isKeyDown( "w" )) { setLocation(getX(),getY()- 5 ); if (frameCounterUp< 4 ) { setImage (up[frameCounterUp]); frameCounterUp++; } else { frameCounterUp= 0 ; } } } } |