Hello all. I need some help with storing values into an array of a certain class that is called "BallInfo" in order to spawn in a "Ball" object. Here is the constructor for the Ball object:
I need to use values read in by a file to store into a BallInfo array to be used for the construction of a new Ball. The values read in by the file contain the red, green and blue values of a given Ball respectively. Here is the code inside the World class for reading in the values to spawn in a BallInfo object:
So what I need help with is taking the values from the file being read in to spawn a BallInfo object and storing those values into a BallInfo array and then using that array to spawn in a new ball(s). Here is the structure of the construction of a Ball that I am trying to explain:
I hope I explained it somewhat thoroughly. Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public Ball(BallInfo bi) { ballData = bi; // build an image for this ball. GreenfootImage img = new GreenfootImage(DIAMETER, DIAMETER); // draw an appropriately colored circle in the image img.setColor(bi.getColor()); img.fillOval( 0 , 0 ,DIAMETER,DIAMETER); // use the image just drawn as this ball's image setImage(img); this .ySpeed = 0.05 ; } |
1 2 3 4 5 6 7 8 9 10 | int Y = 35 ; int red, green, blue; while (fReader.hasNext()) { red = fReader.nextInt(); green = fReader.nextInt(); blue = fReader.nextInt(); addObject( new BallInfo(red, green, blue), 85 , Y); Y += 12 ; } |
1 | addObject( new Ball(ballInfo[]), x value, y value); |