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

2014/10/28

Ship game help

Fuzzion Fuzzion

2014/10/28

#
Hi, does anyone have code or a link to codes for a welcome message,counter and/or help for this code for random ship movement to hit ship- public class Submarine extends Actor { /** * Act - do whatever the Submarine wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void movearound() { move(4); if (Greenfoot.getRandomNumber(100) < 10) { turn(Greenfoot.getRandomNumber(90) - 45); } if (getX() <= 5 || getX() >= getWorld().getWidth -5) { turn(180); } } }
jimboweb jimboweb

2014/11/10

#
I have made a MoveRandomly class that you can include in your Greenfoot project that will cause another actor to move randomly. The code can be found here: http://mrstewartslessons.com/useful_class_moverandomly.html Simply download the java file into your greenfoot project. Close greenfoot and reopen the project, and you'll see the MoveRandomly class among your actors. Open the code window and change 'Source Code' to 'Documentation' and you'll see directions for including the object and its methods in your actor's code. I also have a StaticText class that can display a welcome message. You can find that class here: http://mrstewartslessons.com/useful_class_static_text.html
You need to login to post a reply.