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

2012/5/29

Help with creating an array

DAustin15 DAustin15

2012/5/29

#
I had some help with movement a week ago, but since on my monopoly board the 40 board places each is its own class we started to make a array but it doesnt seem to be coding right.
 Properties p=new Facebook();
        addObject(p, 554, 46);
        int i = 39;
        pads[i] = p;
        i--;





import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class Road here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Board extends World
{
 public Properties[] pads = new Properties[40];   
 /**
     * Constructor for objects of class Road.
     * 
     */
    public Board()
    {
        super(850,850,1);
        setBackground("Sociapoly.JPG");
        // This is currently unused, here to use as an example.
        //String bgTxt = "";
        //GreenfootImage img = new GreenfootImage(bgTxt, 30, Color.black, Color.magenta);
        //GreenfootImage bg = getBackground();
        //bg.drawImage(img, (bg.getWidth() - img.getWidth()) / 2, (bg.getHeight() - img.getHeight()) / 2);
        // The following statements sets up the Action menu items (in order given)        
        addObject(new Die1(), 337, 119);
        addObject(new Die2(), 399, 119);
        Properties p=new Facebook();
        addObject(p, 554, 46);
        int i = 39;
        pads[i] = p;
        i--;
danpost danpost

2012/5/29

#
Question: are each of the 40 classes sub-classes of Actor, or is there a sub-class of Actor that the 40 extend?
DAustin15 DAustin15

2012/5/29

#
there is a subclass of actor called properties, and each of the spaces on the board is a property(each is a subclass of properties
DAustin15 DAustin15

2012/5/30

#
We manually did the pads,so it now is this, but we are having a problem which is posted on a new discussion.
 public Properties[] pads = new Properties[40];
    private Properties p;
    private int counter = 39; 
 
[code]java.lang.ArrayIndexOutOfBoundsException: -1
	at Board.<init>(Board.java:235)
	at sun.reflect.GeneratedConstructorAccessor6.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
	at greenfoot.core.Simulation.newInstance(Simulation.java:520)
	at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:406)
	at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:411)
	at greenfoot.core.Simulation.maybePause(Simulation.java:269)
	at greenfoot.core.Simulation.runContent(Simulation.java:201)
	at greenfoot.core.Simulation.run(Simulation.java:194)
/** * Constructor for objects of class Road. * */ public Board() { super(850,850,1); setBackground("Sociapoly.JPG"); // This is currently unused, here to use as an example. //String bgTxt = ""; //GreenfootImage img = new GreenfootImage(bgTxt, 30, Color.black, Color.magenta); //GreenfootImage bg = getBackground(); //bg.drawImage(img, (bg.getWidth() - img.getWidth()) / 2, (bg.getHeight() - img.getHeight()) / 2); // The following statements sets up the Action menu items (in order given) addObject(new Die1(), 337, 119); addObject(new Die2(), 399, 119); p= new Facebook(); addObject(p, 554, 46); pads = p; counter--; p=new BrokenScreen(); addObject(p, 499, 48); pads = p; counter--; p=new Twitter(); addObject(p, 444 ,46); pads = p; counter--; p=new Ebay(); addObject(p, 392 ,46 ); pads = p; counter--; p=new Bing(); addObject(p, 337 , 46 ); pads = p; counter--; p=new YouTube(); addObject(p, 283 , 46); pads = p; counter--; p=new Amazon(); addObject(p, 228 , 46 ); pads = p; counter--; p=new GooglePlus(); addObject(p, 173 , 45 ); pads = p; counter--; p=new ooVoo(); addObject(p,118 ,46 ); pads = p; counter--; p=new GoToJail(); addObject(p,46 ,44 ); pads = p; counter--; p=new Tumblr(); addObject(p,46 ,113 ); pads = p; counter--; p=new Norton(); addObject(p,46 ,167 ); pads = p; counter--; p=new Skype(); addObject(p,47 ,217 ); pads = p; counter--; p=new Skype(); addObject(p,47 ,217 ); pads = p; counter--; p=new Myspace(); addObject(p,46 ,271 ); pads = p; counter--; p=new Yahoo(); addObject(p,44 ,325 ); pads = p; counter--; p=new FourSquare(); addObject(p,45 ,377 ); pads = p; counter--; p=new Msn(); addObject(p,45 ,429 ); pads = p; counter--; p=new Ebay2(); addObject(p,45 ,481 ); pads = p; counter--; p=new Aim(); addObject(p, 46 ,534 ); pads = p; counter--; p=new FreeWifi(); addObject(p,45,605 ); pads = p; counter--; p=new LastFm(); addObject(p,119 ,604 ); pads = p; counter--; p=new Flickr(); addObject(p,174 ,604 ); pads = p; counter--; p=new Amazon3(); addObject(p, 227 , 605 ); pads = p; counter--; p=new Bebo(); addObject(p, 280 , 605 ); pads = p; counter--; p=new Google(); addObject(p, 335, 603 ); pads = p; counter--; p=new Yelp(); addObject(p, 390,605); pads = p; counter--; p=new Gaia(); addObject(p,445,605); pads = p; counter--; p=new Mcafee(); addObject(p,498,606); pads = p; counter--; p=new GamerDNA(); addObject(p,551,606); pads = p; counter--; p=new Jail(); addObject(p,626,606); pads = p; counter--; p=new Ning(); addObject(p,624,535); pads = p; counter--; p=new Wooxie(); addObject(p,625,482); pads = p; counter--; p=new Ebay3(); addObject(p,624,428); pads = p; counter--; p=new Habbo(); addObject(p,625,376); pads = p; counter--; p=new Blekko(); addObject(p,624,326); pads = p; counter--; p=new VirusDetected(); addObject(p,624,272); pads = p; counter--; p=new Delicious(); addObject(p,624,218); pads = p; counter--; p=new Amazon2(); addObject(p,626,167); pads = p; counter--; p=new Zooppa(); addObject(p,624,116); pads = p; counter--; p=new Go(); addObject(p,625,46); pads = p; counter--;
danpost danpost

2012/5/30

#
Now, that I know how things are arranged, I can say the the pads are not neccessary. All you needed to do was add a Property instance variable in the Property class called 'nextProperty' and link all the properties with it.
You need to login to post a reply.