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

2015/2/7

Increasing speed based on Score

Montrigil30 Montrigil30

2015/2/7

#
Hello, I´d like to increase the speed of my Lobsters or of the scenario, still unsure which one, based on the Score of eaten Worms. My Problem is that i only want to increase the speed ONCE when it reaches my fixed points (20, 40...) so naturally this doesnt work because the system does that as long as the score is 20 and so on:
if(score == 20 && 40) //etc.
{
      speed = speed+1
}
I also tried something with boolean but it didnt work out, probably because i messed up ^-^ Soooooo how can i do that (Best would be if you just tell me your idea, not show your code, i wanna improve :) )?
danpost danpost

2015/2/7

#
This is more of a math problem, not a logic puzzle. Look at the set { 20, 40, 60, 80 ... } -- there is a ratio between the speed you want and the value of the score. Well, okay, look at the set of values added to the initial speed { 1, 2, 3, 4 ... }. The first set is the second set with each value multiplied by 20. Conversely, the second set is the first set divided by 20. If the 'speed' field is of 'int' type, then no in-between values can possibly be reached -- that is 'score/20' will be zero when the score is below 20; it will be one when the score is between 20 and 39; etc. Hope this rang the bell.
Montrigil30 Montrigil30

2015/2/7

#
Thanks so much for your quick response! Really good solution, i feel like you made me go a huge step towards actually using logic in programming (Im only a newbie) Thank you again, I was stuck with this problem for so long :D
You need to login to post a reply.