It greatly lowers the bar for building graphical applications in Java this is important because the quick positive feedback inspires students to work with the code more. There are just a few classes to learn in order to make full use of the platform. The Greenfoot API is made up of only five classes (for details, see Greenfoot Java docs). The two primary classes that will be used in any scenario are World and Actor. These two are the base classes for everything that will have a visual representation in the scenario. ![]() World represents the canvas and provides the cell size and coordinate system for positioning the Actors. ![]() Actors are visual representations of objects which can interact with one another and the world. Both of these classes have an act() method which should be overridden with the desired behavior for the World or Actor. The act() method will be called by Greenfoot in a round-robin fashion on each object and this process will repeat as long as the scenario is running. This is a simplistic threading model however, it provides a great opportunity for students to learn about the consequences of wasteful processes and encourages efficient code. If I'm missing anything, I fix it.This feature also gives the student an opportunity to think about asynchronous solutions without burdening them with other complexities such as synchronization. If anyone could help me that would be great. So when the lobster that has be added to the world eats the crab, I want that crab to lose a life, but when I try to compile, I get an error on the CrabWorld class that it could not find the method mentioned. If(Greenfoot.getRandomNumber(100)= getWorld().getWidth()-10) * Randomly places worms at random periods * Prepare the world for the start of the program. * Constructor for objects of class CrabWorld. Private Counter score = new Counter("Score: ") * place random worms in the world over time. * Creates the crab Enviornment with a counter, crab and lobster. I need to access the Crab instance (created in the CrabWorld, if that matters) from from the Lobster Class.Ĭrabworld: import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) I have tried calling ((CrabWorld) getWorld), but I don't need to access the CrabWorld. This method would change the lives of the crab. But the important part that I am having trouble with is calling a method from the lobster to the Crab instance created by the CrabWorld. For your sake, I'll just post the well documented code for you to read. It contains 5 classes named Crab, Lobster, Worm, Counter, and CrabWorld. ![]() Every time you eat a worm, the score goes up by 10. There is a lobster that randomly roams around and if comes in contact with the crab, the crab dissapears. I'm makeing a game where you play the crab and move around to collect worms. I have become familiar on how to call certain methods between classes, and also differences between static and non-static. I have just started programming some things with Greenfoot, learning java along the way.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |