Hi guys,
I'm working on an airport simulation program for a school project and I've stumbled upon a little problem. I have a world (like all Gf games) and it's called Airport. What I want is to create a counter in the world which starts with a value of 0 and the number increases and when it's equal to a specific number, let's say 10, a new object of the class Aircraft has to be created. The problem is that the counter never reaches the specific number I need, so no new objects of Aircraft are being created.
Here's my code of the world:
Can anyone see the problem? I'm not getting any syntax errors, but it doesn't work because of my mistake, which I can't find. The method createPlane() is the method I'm creating to reach the effect I need.
Thanks in advance!
BTW, I'm in my first year, so I'm a rookie, please explain a little bit what you say when you explain the problem. Thanks!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * De klasse Airport dient voor het presenteren van een luchthaven. Via deze klasse worden aanvliegende vliegtuigen * bestuurd en worden vertrekkende vliegtuigen in een bepaalde richting gestuurd. * * @author (Erol & Hakan Simsir) * @version (V1, 10/11/2013/) */ public class Airport extends World { /** * Constructor for objects of class Airport. * */ private int counter; public Airport() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(1000, 600, 1); constructAirport(); } // voeg alle objecten toe aan de wereld public void constructAirport(){ addObject(new Runway(), 510, 100); addObject(new Tarmac(), 507, 447); addObject(new Gate(), 311, 490); addObject(new Gate(), 461, 490); addObject(new Gate(), 611, 490); addObject(new Gate(), 761, 490); addObject(new Terminal(), 517, 563); addObject(new Aircraft(), 70, 520); createPlane(); //addObject(new SplashScreen(), 500, 300); } public void createPlane() { counter = counter + 1; if (counter == 10){ addObject(new Aircraft(), 70, 520); counter = 0; System.out.println(counter); } } }