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

2019/1/2

every 20000 points I want to get a extra ship

thehood thehood

2019/1/2

#
Hi, I have created a score counter. Everytime I destroy an alien ship I get 100 points. I would like add in my code that every 20000 points I get an extra ship.. Can someone help me with this? Tx!
danpost danpost

2019/1/2

#
1
2
3
4
// in pseudo-code
int pastScore = getScore();
addScore(100);
if (pastScore/20000 != getScore()/20000) addExtraShip();
thehood thehood

2019/1/3

#
Hi Danpost, many thanks for your quick reply. It worked out great! but I am trying to find out how this actually works. Is it because we are working with integers? Example: 700/500 = 1 800/500 = 1 so still equal but 900/500 = 1 and 1000/500 = 2 so I get an extra ship? tx again.
danpost danpost

2019/1/3

#
thehood wrote...
I am trying to find out how this actually works. Is it because we are working with integers?
Yes. Because the score is an integer value, dividing by a non-factor integer causes the result to be rounded to an integer.
You need to login to post a reply.