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

2015/1/6

adding radom numbers to the screen

kylecompton31 kylecompton31

2015/1/6

#
im making a balloon pop math game and I need random questions and answers to come up on the balloons. how would I do this while always having the correct answer on the screen??
xFabi xFabi

2015/1/6

#
Answers are numbers i guess? get a random number by getRandomNumber(x,c) and display them, those are the random numbers. For the solution, just make 2 variables, for the question, for example 4 and 7, the question is what is 4*7. The first number, 4 is x and the 7 is y Then x*y=c and display c This should work if theres only one calculation method is used, eg only add or only substract etc. If you want to use all of them, you'd have to have a method, that tells you which one, but i dont know how to that. Try doing it, and insert your code here, so the others can help you better ;)
kylecompton31 kylecompton31

2015/1/6

#
thanks I just don't have any code yet and I have no clue how to do this so just trying to get started! hahaha
danpost danpost

2015/1/6

#
@xFabi, please review the documentation of the Greenfoot class method 'getRandomNumber' (it only takes one int parameter). @kylecompton31, there are a multitude of ways to make it so the answer is always on the screen. World wrapping (relocating the balloons as they go off one edge to a random location on the opposite edge) is one way, and probably the easiest way.
xFabi xFabi

2015/1/6

#
x,c wasnt actually meant to be values, i just took them to show, that you have to input numbers there :D Edit: ah thats what you meant nvm, i thought you could also define a minimum
You need to login to post a reply.