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

2015/9/28

Need help with clara pacman (Dont go direction you came in)

Zues Zues

2015/9/28

#
Ok, im trying to work out how to not come in the same direction you came in e.g. the actor is walking right.. when obstacle occurs dont go left aka dont go back to the same direction you came in. Currently i have
1
2
3
4
public static final int goUp = 0;
public static final int goDown = 1;
public static final int goLeft =  2;
public static final int goRight = 3;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void  optionsOfDirection()
 {
     getDirection();
     int chooseADirection = Greenfoot.getRandomNumber(4);
     switch (chooseADirection)
     {
         case goUp: setDirection("up");
         break;
         case goDown: setDirection("down");
         break;
         case goLeft: setDirection("left");
         break;
         case goRight: setDirection("right");
         break;
     }
}
Where getDirection determines the direction you're going
danpost danpost

2015/9/28

#
Please show the code for the 'getDirection' method. If all it does is determine the direction and does not actually change anything, then I cannot see how it would have any influence on what the 'optionsOfDirection' method is doing. Also, lines 4 though 15, which is the final code in the method, will randomly choose any of the possible directions, regardless of which direction it was previously facing.
You need to login to post a reply.