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

2012/6/25

Counter Trouble

1
2
erdelf erdelf

2012/6/26

#
pls write how you made it
erdelf erdelf

2012/6/26

#
this would help. Edit: sry for double post
CrazyGamer1122 CrazyGamer1122

2012/6/26

#
how i made the counter?
CrazyGamer1122 CrazyGamer1122

2012/6/26

#
erdelf, i reviewed the video "Joy of code number 27, and realized i just forgot to add something to the world's code.
erdelf erdelf

2012/6/26

#
ok
CrazyGamer1122 CrazyGamer1122

2012/6/26

#
i have just updated the game with the counter.
CrazyGamer1122 CrazyGamer1122

2012/6/26

#
I was just wondering....... the code you added---- (space.finished() ) would i be able to delay that until the man eats a certain number of burgers?
erdelf erdelf

2012/6/26

#
yes, of course. make an integer and then ask if his value is the certain number
CrazyGamer1122 CrazyGamer1122

2012/6/26

#
can u put an example of how i would write that?
CrazyGamer1122 CrazyGamer1122

2012/6/26

#

import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class person here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class person extends Actor
{
    private Counter counter;
      
    public person(Counter count)
    {
      counter = count;    
    }    
       
       
    
    /**
     * Act - do whatever the person wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()
    {    
        if(!space.getEnd())
        {
            if (Greenfoot.isKeyDown("right"))
            {    
                turn (2);
            } 
            if (Greenfoot.isKeyDown("left"))
            {    
                turn (-2);
            }

            if (Greenfoot.isKeyDown("up"))
            {    
                move (2);
            }  
            if (Greenfoot.isKeyDown("down"))
            {    
                move (-75);
            }    
            Actor burger;
            burger = getOneObjectAtOffset(0, 0, burger.class);
            if (burger != null)
            {
                World world;
                world = getWorld();
                world.removeObject(burger);
                Counter cp = (Counter) (getWorld().getObjects(Counter.class).get(0));
                if(cp.getScore() > 2 /* x 2 */) // replace this
                {
                    setImage(new GreenfootImage("YOU WIN",180, Color.WHITE, Color.YELLOW));
                    space.finished();
                }
                cp.addScore();
                setLocation(290, 200);
            }
                createNewBurger();
            }
            
            {
            private void createNewBurger()
            {
              burger newburger;
              newburger = new burger();
              World world
              world = getWorld();
              int x = Greenfoot.getRandomNumber(600);
              int y = Greenfoot.getRandomNumber(480);

              world.addObject(newburger, x, y);
    
            }
  
            }   
     }
}
the error is in the private void crete new burger.... it says "illegal start of expression"... could you revise/edit it for me?
CrazyGamer1122 CrazyGamer1122

2012/6/26

#
please disregard the previous post...... i have a new error
at greenfoot.core.Simulation.runContent(Simulation.java:210)
	at greenfoot.core.Simulation.run(Simulation.java:203)
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
	at greenfoot.Actor.failIfNotInWorld(Actor.java:663)
	at greenfoot.Actor.getX(Actor.java:157)
	at alligator.<init>(alligator.java:27)
	at space.prepare(space.java:38)
	at space.<init>(space.java:25)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
	at greenfoot.core.Simulation.newInstance(Simulation.java:578)
	at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:408)
	at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:465)
	at greenfoot.core.Simulation.maybePause(Simulation.java:279)
	at greenfoot.core.Simulation.runContent(Simulation.java:210)
	at greenfoot.core.Simulation.run(Simulation.java:203)
CrazyGamer1122 CrazyGamer1122

2012/6/26

#
please help me with this..... im done editing the last few things i need to add to the game and this just keeps popping up every time i try to compile...
danpost danpost

2012/6/26

#
In the code you provided, you have the wrong bracket at line 64, and if my count is right, 2 extra brackets at the end. The new error is in the alligator class, in its constructor. You are probably using either 'getX' / 'getY', or one of the 'getObjects' commands, which will not work in the constructor.
You need to login to post a reply.
1
2