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

2017/1/17

Invalid Moves.

I'm quite new to Greenfoot and i came across a problem. My program uses user input to move a character around the 8x8 grid world by entering the number of blocks the user wants the character to move up/down then left/right. If the user enters and invalid move (one that takes the character off the world) i would like the character to go back the position at the start of the turn and alert the player that the move was invalid. To move my character i first check the current location of the character by using getX and GetY then substitute it into and equation with the user inputs to determine the new co-ordinates. Then use set location to move the character to the co-ordinates. The size of my world is the follow: "super(11, 8, 60); " the 3 extra rows are covered by a scoreboard which the player can not go under either. Anyone got any solutions?
Hondrok Hondrok

2017/1/17

#
KennethTheSuperMelon wrote...
I'm quite new to Greenfoot and i came across a problem. My program uses user input to move a character around the 8x8 grid world by entering the number of blocks the user wants the character to move up/down then left/right. If the user enters and invalid move (one that takes the character off the world) i would like the character to go back the position at the start of the turn and alert the player that the move was invalid. To move my character i first check the current location of the character by using getX and GetY then substitute it into and equation with the user inputs to determine the new co-ordinates. Then use set location to move the character to the co-ordinates. The size of my world is the follow: "super(11, 8, 60); " the 3 extra rows are covered by a scoreboard which the player can not go under either. Anyone got any solutions?
Can you show us your code?
Super_Hippo Super_Hippo

2017/1/17

#
When you get the target location, compare the x and y to the size of your world, so if it is negative or 8 or higher, instead of moving, you print out a message (or create an object which uses an image with the message).
You need to login to post a reply.