This site requires JavaScript, please enable it in your browser!
Greenfoot back
swacks
swacks wrote ...

2015/7/20

when i was coding (trying to make a life counter i came up with problems im posting the code on making a life counter

1
2
swacks swacks

2015/8/2

#
there may be a few mistakes that you could point out where they are in the code because im battling to make the life counter.i would be very grateful for any such advice that may help ;-)
swacks swacks

2015/8/4

#
do you think i should restart the code of the lifecounter and the lifecounter parts in the other classes
danpost danpost

2015/8/4

#
I think you should simplify the code as I suggested and then post the changes you made so that we have something to work on.
swacks swacks

2015/8/5

#
ill keep that in mind in the meanwhile this is a seperate question to that on discussion 1 i dont think that would actually effect copying from one user to another or would errors on the first user cause this problem (ask why im moving from user to user i want to have a backup incase something happens to my coding do you have any advice that i could use to make this happen
swacks swacks

2015/8/5

#
ive messed it up
import greenfoot.*;

/**
 * all history of bobsworld.
 * 
 * @author (A.T.P) 
 * @version (2.4.2)
 */
public class BobWorld extends World
{

    /**
     * Constructor for objects of class BobWorld.
     * 
     */
    public BobWorld()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(700, 500, 1); 

        prepare();
    }

    
    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        Bob bob = new Bob();
        addObject(bob,29,35);
        
        Score score = new Score();
        addObject(score,45,15);

      
        

        bob.setLocation(94, 251);
        bob.setLocation(106, 232);
        bob.setLocation(67, 185);
        bob.setLocation(72, 162);
        bob.setLocation(76, 177);
        bob.setLocation(75, 177);
        bob.setLocation(75, 175);
        bob.setLocation(85, 204);
        BobFood bobfood = new BobFood();
        addObject(bobfood, 468, 205);
        bob.setLocation(86, 204);
        bob.setLocation(100, 191);
        bob.setLocation(98, 191);
        bob.setLocation(134, 168);
        bob.setLocation(95, 206);
        bobfood.setLocation(451, 210);
        BobEater bobeater = new BobEater();
        addObject(bobeater, 81, 140);
        BobEater bobeater2 = new BobEater();
        addObject(bobeater2, 74, 334);
        bob.setLocation(201, 235);
        bobfood.setLocation(451, 181);
        bob.setLocation(202, 235);
        bob.setLocation(203, 235);
        bob.setLocation(207, 216);
        bobeater.setLocation(84, 142);
        bobeater.setLocation(85, 150);
        bobeater2.setLocation(76, 315);
        BobFood bobfood2 = new BobFood();
        addObject(bobfood2, 465, 46);
        BobFood bobfood3 = new BobFood();
        addObject(bobfood3, 468, 314);
        BobFood bobfood4 = new BobFood();
        addObject(bobfood4, 286, 95);
        BobFood bobfood5 = new BobFood();
        addObject(bobfood5, 306, 289);
        BobFood bobfood6 = new BobFood();
        addObject(bobfood6, 326, 201);
        BobFood bobfood7 = new BobFood();
        addObject(bobfood7, 552, 103);
        BobFood bobfood8 = new BobFood();
        addObject(bobfood8, 541, 263);
        BobFood bobfood9 = new BobFood();
        addObject(bobfood9, 139, 34);
        BobFood bobfood10 = new BobFood();
        addObject(bobfood10, 181, 340);
        BobFood bobfood11 = new BobFood();
        addObject(bobfood11, 69, 213);
        BobFood bobfood12 = new BobFood();
        addObject(bobfood12, 182, 124);
        Instructions instructions = new Instructions();
        addObject(instructions, 272, 395);
        instructions.setLocation(282, 389);
        bobeater2.setLocation(76, 304);
        BobEater bobeater3 = new BobEater();
        addObject(bobeater3, 73, 312);
        BobEater bobeater4 = new BobEater();
        addObject(bobeater4, 389, 100);
        BobEater bobeater5 = new BobEater();
        addObject(bobeater5, 545, 202);
        bobeater3.setLocation(76, 312);
        bobeater3.setLocation(346, 329);
        bobeater3.setLocation(344, 329);
        score.setLocation(44, 15);
        score.setLocation(27, 18);
        score.setLocation(27, 24);
        removeObject(bobfood6);
        removeObject(bobfood);
        removeObject(bobfood9);
        bobfood3.setLocation(469, 313);
        removeObject(bobfood3);
        bobfood4.setLocation(286, 98);
        removeObject(bobfood4);
        bobfood12.setLocation(198, 87);
        bobfood5.setLocation(306, 260);
        bobfood2.setLocation(396, 179);
        bobfood2.setLocation(405, 167);
        bobfood8.setLocation(491, 312);
        bobfood8.setLocation(491, 310);
        bobfood7.setLocation(543, 57);
        bobfood10.setLocation(154, 340);
        bobfood11.setLocation(56, 214);
        bobfood11.setLocation(56, 215);
        bobfood5.setLocation(307, 257);
        bobfood2.setLocation(434, 132);
        bobfood2.setLocation(416, 116);
        bobeater4.setLocation(402, 115);
        bobeater4.setLocation(378, 98);
        bobfood2.setLocation(421, 136);
        bobfood2.setLocation(421, 135);
        instructions.setLocation(361, 489);
        bobfood8.setLocation(573, 404);
        bobfood5.setLocation(326, 395);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(154, 340);
        bobfood10.setLocation(50, 426);
        bobfood11.setLocation(67, 217);
        bobfood2.setLocation(378, 245);
        bobeater3.setLocation(378, 363);
        bobeater2.setLocation(86, 306);
        bobeater.setLocation(154, 80);
        bobeater3.setLocation(381, 411);
        bobeater3.setLocation(384, 430);
        bobeater2.setLocation(110, 341);
        score.setLocation(52, 23);
        score.setLocation(51, 22);
        score.setLocation(50, 16);
    }
}
error:constructor Bob in class Bob cannot be applied to given types required score; found no arguments; reason:actual and formal arguments list differ in length how can you explain this error in simple english
danpost danpost

2015/8/6

#
Apparently, in your Bob class you have a
public Bob(Counter counter)
but you do not have a
public Bob()
Your line 31 in your BobWorld class requires a constructor that starts with the last code line in this post.
danpost danpost

2015/8/6

#
At any time, you can start a new version of the project by saving it using the menubar option "Scenario>Save as..." and giving the project a new name. The project will remain with its original name as one file and you will be ready to edit the project with the new name working in a new scenario folder.
swacks swacks

2015/8/6

#
import greenfoot.*;

/**
 * a bob in the game will eat the Bobfood on your command.
 * 
 * @author (A.T.P) 
 * @version (2.4.2)
 */
public class Bob extends Beings
{
  
    private int points = 0;
    private Score Score;
    

    
    
    
    
       
        
       
          
          
 
    
   
    public Bob(Score pointScore)
    {
        Score = pointScore;
        
    }

    /**
     * Act - do whatever the Bob wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(3);
        checkKeys();
        tryToEat();
    }    

    /**
     * once reached world edge you must turn away
     */
    public void turnAtWorldEdge()
    {  if (atWorldEdge())
        {
            turn(4);
        }
    }

    /**
     * check whether the keys are being pressed or not if they are follow the command
     */
    public void checkKeys()
    {
        if( Greenfoot.isKeyDown("left"))
        {
            turn(-6);   
        }
        if( Greenfoot.isKeyDown("right"))
        {
            turn(6);
        }
        if( Greenfoot.isKeyDown("up"))
        {
            move(5);   
        }
        if( Greenfoot.isKeyDown("down"))
        {
            move(-5);
        }
    }

    /**
     * Check whether we can see Bobfood.if we can,eat it.
     */
    void tryToEat()
    {
        if(canSee(BobFood.class))
        {
            eat(BobFood.class);
            Greenfoot.playSound("slurp.wav");
            Score.add(5);
            createNewBobFood();
        }

    }

    /**
     * add new BobFood into the world at a random location
     */
    private void createNewBobFood()
    {
        BobFood newBobFood;
        newBobFood=new BobFood();

        World world;
        world=getWorld();

        int worldWidth = world.getWidth();
        int worldHeight = world.getHeight();

        int x = Greenfoot.getRandomNumber(worldWidth);
        int y = Greenfoot.getRandomNumber(worldHeight);

        world.addObject(newBobFood,x,y);
    }
    
    
    

    /**
     * adds the method gameover when that happens a sound is produced
     */
    public void gameOver()
    {
        Greenfoot.playSound("game-over.wav");
        Greenfoot.stop();

    }
}
there is no bob(counter counter)
danpost danpost

2015/8/6

#
swacks wrote...
there is no bob(counter counter)
Sorry, I meant that there apparently is this line:
public Bob(Score score)
which was referring to your line 28 above. Still, since you do not have a
public Bob()
constructor in the class, you cannot create a Bob object with
Bob bob = new Bob()
You need to, unless you add a constructor with no parameter, create a Bob object with
Bob bob = new Bob(score)
where score is declared with
Score score;
making it a Score object reference. The 'score' reference should be set to a Score object prior to creating the Bob object as there is no check in the Bob class to see if the value is 'null' before calling methods on the 'Score' object field of the class.
swacks swacks

2015/8/16

#
i better just watch the videos again
You need to login to post a reply.
1
2