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

2016/1/3

I really need help with my programm something went wrong from one Moment from the other and I have to send it to my teacher today evening can you guys have a look pls?

AddiFlash AddiFlash

2016/1/3

#
I want the Mensch1 to change the image when it mets with the Krankmacher but for some Reason it stopped working ten minutes ago can you help me and say, what's wrong with the code? public void changeimage() { image1 = new GreenfootImage("smiley1.png"); image2 = new GreenfootImage("smiley4.png"); image3 = new GreenfootImage("skull.png"); if (canSee(Krankmacher1.class)){ if(Greenfoot.getRandomNumber(100) < 70){ setImage(image2);} } if (canSee(Krankmacher2.class)){ if(Greenfoot.getRandomNumber(100) < 70){ setImage(image2);} } if (canSee(Antikörper.class) && getImage() == image2){ if(Greenfoot.getRandomNumber(200) < 10){ setImage(image1);} } if(canSee(Krankmacher1.class)&& getImage() == image2){ if(Greenfoot.getRandomNumber(100) < 10){ setImage(image3);} } if(canSee(Krankmacher2.class)&& getImage() == image2){ if(Greenfoot.getRandomNumber(20) < 10){ setImage(image3);} }
Super_Hippo Super_Hippo

2016/1/3

#
Why do you get random numbers there?
AddiFlash AddiFlash

2016/1/3

#
because it should be a percent Chance dor that to happen it isn't working without them too.
Super_Hippo Super_Hippo

2016/1/3

#
The problem about the random percentage is that 'canSee' will return 'true' every act cycle the objects overlap each other. Probably you want that it is an infection or not. Then you could have a boolean to save whether or not they are overlapping right now and only get random number to infect the person if it changes from no overlapping to overlapping. Does it work if you remove lines 3 through 5? If you have 'private GreenfootImage image1;' (and 2 and 3) outside methods, then add the 'new GreenfootImage...' there.
danpost danpost

2016/1/3

#
I am sure it will not work like you want without lines 3 through 5 moved to outside the method. As it is, if a mensch does intersect a kranchmacher and does not immediately die, it will never die. This would be due to the fact that the image that will be reference by 'image2' will no longer be the image that was set to the actor as the GreenfootImage objects referenced by the three fields are changed every act method (they may be created from the same file in memory; but, they are still different GreenfootImage instances).
You need to login to post a reply.