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

2013/10/30

my program stop

sophiefordream sophiefordream

2013/10/30

#
my greenfoot's object not move when i click on one object to make it disappear it appear error like this..link :error please help me@_@
danpost danpost

2013/10/30

#
For better chance of help, upload your scenario on the site or show some code in the discussion thread.
sophiefordream sophiefordream

2013/10/30

#
this is the coding import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class babyDolphin here. * * @author (your name) * @version (a version number or a date) */ public class babyDolphin extends Actor { private static final int EAST = 0; private static final int WEST = 1; private int direction; /** * Act - do whatever the babyDolphin wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(Greenfoot.mouseClicked(this)) { getWorld().removeObject(this); System.out.println("mouse clicked on baby Dolphin!"); } if ( canMove() ) { move(); } else { turnRandom(); } } public void move() { if (!canMove()) { return; } switch(direction) { case EAST : setLocation(getX() + 1, getY()); break; case WEST : setLocation(getX() - 1, getY()); break; } } public boolean canMove() { int x = getX(); int y = getY(); switch(direction) { case EAST : x++; break; case WEST : x--; break; } if ( x == 599 || x == 0 ) { return false; } else { return true; } } public void turnRandom() { // get a random number between 0 and 3... int turns = Greenfoot.getRandomNumber(10); // ...an turn left that many times. for(int i=0; i<turns; i++) { turnLeft(); } } public void turnLeft() { switch(direction) { case EAST : setDirection(WEST); break; case WEST : setDirection(EAST); break; } } public void setDirection(int direction) { this.direction = direction; switch(direction) { case EAST : setRotation(0); break; case WEST : setRotation(0); break; default : break; } } { } }
sophiefordream sophiefordream

2013/10/30

#
i'm new in greenfoot enviroment hope you can help me
danpost danpost

2013/10/30

#
Try switching the 'if (canMove())' block with the 'if(Greenfoot.mouseClicked(this))' block in the act method (notice I stated the blocks--not the statements). The way you have it now, it is possible that the actor is removed from the world in the first block and errors creep up in the second because you cannot get the actors location while not in the world.
sophiefordream sophiefordream

2013/10/30

#
wow you're great thank you~ can i ask one more question? if i want to make the object move not the same means randomly....how to make that works?
danpost danpost

2013/10/30

#
Your turnRandom method in the babyDolphin class is way overcomplicated. You should only need to do something like this in it:
if (Greenfoot.getRandomNumber(200) == 0) turnLeft();
sophiefordream sophiefordream

2013/10/31

#
thanks.....^^
You need to login to post a reply.