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

2013/3/29

moving and turning objects

1
2
3
4
5
6
7
danpost danpost

2013/3/30

#
Sure.
Gingervitis Gingervitis

2013/3/30

#
I fixed it. Thank you.
Gingervitis Gingervitis

2013/3/30

#
Actually now the worms won't stop going to the crab.... I am going to publish it.... can you let me know when you have it?
danpost danpost

2013/3/30

#
Got it (again).
danpost danpost

2013/3/30

#
In Crab class, in the 'ifCanSeeWP' method, change 'timer1--;' to 'timer2--;'. Looking for more, but that definitely did something!
Gingervitis Gingervitis

2013/3/30

#
I think that fixed it but if you see anything else.... There is no way I could thank you enough. You have helped me so much.
danpost danpost

2013/3/30

#
Your populating code in the Crab class could really be condensed, if you want to work on that.
Gingervitis Gingervitis

2013/3/30

#
Is there a better way to create them? Like a way to multiply a method?
danpost danpost

2013/3/30

#
I do not know what you mean by 'multiply a method'. Obviously, the terminology needs to be improved. I was thinking, at least, that you could use loops to create multiples of the same type object. For example:
// instead of 27 lines of 
createNewWorm();
// you could just say
for (int i=0; i<27; i++) createNewWorm();
Gingervitis Gingervitis

2013/3/30

#
Ahh I see.... ok.... That is so much easier than counting a million lines of code that say the same thing.... Why do you use the variable 'i'? I think I have seen you use that before....
danpost danpost

2013/3/30

#
Ever since I can remember, integer values were designated with letters starting with 'i'. Any valid variable name could easily have been used, however. I do like to stick to the tradition (as habit and recognizability).
Gingervitis Gingervitis

2013/3/30

#
makes sense....
danpost danpost

2013/3/30

#
There is possibly a way to write all the levels as one set of code, changing the value that i is limited to depending on the level.
Gingervitis Gingervitis

2013/3/30

#
for some reason, when I try to change the value of i for round 2, the counter doesn't go past 54 when 57 is need to go onto round 3..... could you fix that code and then the rest to work with i but still keep the amount of worms added I used?
danpost danpost

2013/3/30

#
Sounds like you still have 27 as the limit for 'i', as 27 + 27 = 54 (or 27 * 2 = 54). What you should probably do is something like this:
int numWorms = 0;
if (wormsEaten == 27) numWorms = 30;
else if (wormsEaten <= 288) numWorms = 33;
else if (wormsEaten <= 915) numWorms = 66;
else numWorms = 76;
for (for i=0; i<numWorms; i++) createNewWorm();
There are more replies on the next page.
1
2
3
4
5
6
7