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

Report as inappropriate.

davmac
davmac presents ...

2011/1/14

tut-access-p2

This scenario is part of a HOW-TO about accessing objects from another.
See the tutorial here: http://www.greenfoot.org/doc/howto-1
---------

This is a simple game. Press space bar to fire a shot at the asteroids which go past overhead. There is a delay between each shot so you must aim carefully.

The counter at the bottom left is a score counter.

This scenario represents the "finished product" that you should have after completing the HOW-TO!

23344 views / 108 in the last 7 days

9 votes | 0 in the last 7 days

Tags: game with-source howto

This scenario is a member of: Grand Designs


open in greenfoot
Your browser is ignoring the <APPLET> tag.
btj9btj9

2011/11/1

Thank you so very much for giving a tutorial on a simple counter!!!!!
ProdigyProdigy

2012/5/20

Thanks a ton for this.
franmanfranman

2012/10/10

Alright so I've tried to do the exercise myself. I've followed the instructions as told and compare to the answer. It seems the code matches and while I compiled it the counter does not change every time I shot an asteroid. Please help.
amal_Azabamal_Azab

2012/11/15

thanks I tried my self and I found it very useful
Cool! I was having a hard time trying to figure it out. Thanks!
Au79Au79

2014/3/22

Thank you very much!, this is very helpful!
jordan93jordan93

2015/3/24

THANKS ! it was cool!
JMB123JMB123

2015/4/8

OMG thank you... I might become famous for this all thanks to you..YOU...Dave just. just thanks!
Not working for me :( Compiling works, no errors getting returned. But if a shot hits an asteroid it says: ------------------------------------------------------------------------------------- java.lang.NullPointerException at Shot.hitAnAsteroid(Shot.java:58) at Shot.act(Shot.java:34) at greenfoot.core.Simulation.actActor(Simulation.java:594) at greenfoot.core.Simulation.runOneLoop(Simulation.java:552) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205) -------------------------------------------------------------------------------------------------- private void hitAnAsteroid() { Space spaceWorld = (Space) getWorld(); // get a reference to the world XX Counter counter = spaceWorld.getCounter(); // get a reference to the counter XX counter.bumpCount(5); } -------------------------------------------------------------------------------------------------- that´s the code, the line marked with X´s is supposedly containing the error... but i dont get it Any help appreciated :)
Super_HippoSuper_Hippo

2017/6/14

I guess you changed the code of the class. You added at least four lines of code. The original one works without errors. What did you change (for example in the act method)? It would probably be the best to open a new discussion with a link to this scenario instead.

See all comments

Want to leave a comment? You must first log in.

Who likes this?

猎鹰ndnd Samaguana Au79 epicm512 PStigerID Loncle jontin vinsent comphandler