i am trying to make it so that my crab generates the worms at random locations.... this is my code so far.
in crab class
in my world class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * special constructor that also sets num of worms */ public Crab( int numWorms) //self note, this is a constructor. { setNumberOfWorms(numWorms); setImages(); } /** * set the number of worms in the world */ public void setNumberOfWorms( int numWorms) { if (numWorms > 0 ) { wormsInWorld = numWorms; } } |
1 | static int numWorms = Greenfoot.getRandomNumber(maxWorms-minWorms+ 1 )+minWorms; |
1 2 | // Add my crab populateCrab(crabXPosition, crabYPosition); |
1 2 3 4 5 6 7 8 | /** * Place a crab in the world at xPosition and yPosition */ private void populateCrab( int xPosition, int yPosition) { Crab myCrab = new Crab(numWorms); addObject(myCrab, xPosition, yPosition); } |