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

2014/5/2

Greenfoot calling an array

kayuhnjayuhn kayuhnjayuhn

2014/5/2

#
I am trying to set this up so I can call the array. I'm assuming this will actually work. How would I call this so it will read all the cars instead of just having to code the if (canSee()) for each car?
if (canSee(car))
        {
            setLocation(414,584);
        }
  private String[] car = 
    { "carGreen", "carBlue", "carRed" };
danpost danpost

2014/5/2

#
Do you have a class for your car objects? if so, supply its name (post the class header).
kayuhnjayuhn kayuhnjayuhn

2014/5/2

#
The car objects are their own class.
danpost danpost

2014/5/2

#
If you are using the Animal class 'canSee' method, then:
if (canSee(Car.class))
should check for all cars.
You need to login to post a reply.