Elle B.
asked 01/09/23How to make object move 3 steps ahead randomly in any direction (JAVA)
The following code allows for a "bird" to move one step on GUI in any random direction. How do you make the bird move 3 steps ahead at once randomly in any direction?
double r = Math.random();
if (r < 0.25)
return NORTH;
else if (r < 0.5)
return SOUTH;
else if (r < 0.75)
return EAST;
else
return WEST;
}
Thank you for help in advance.
2 Answers By Expert Tutors
Judy R. answered 01/22/23
Hello I am 22 years experienced Online Tutor and Assignment Helper for Computer Science and Math. I have been teaching IT Professionals, students from different grades, and Graduate and Post Graduate students for more than 22 years. I am ready to help you with your learning requirements, assignments, tests, and projects. For further discussion about the assignment or project help you need, please add me on skype and my skype id is nettuitions Thanks
Since x=0 is left is west and y=0 is top is north, based on the random direction, x or y is modified by 3 within the limits of the gui (x = 0 -> width-1, y = 0 -> height-1): north is y - 3, south is y + 3, east is x + 3, west is x - 3.
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Judy R.
Hello I am 22 years experienced Online Tutor and Assignment Helper for Computer Science and Math. I have been teaching IT Professionals, students from different grades, and Graduate and Post Graduate students for more than 22 years. I am ready to help you with your learning requirements, assignments, tests, and projects. For further discussion about the assignment or project help you need, please add me on skype and my skype id is nettuitions Thanks01/22/23