Sammyy2323 wrote...
ok, and I would keep the CreateBalls method and then make the Ball method also? (sorry for asking questions, final project is due in like 2 days and I need to make sure this is correct)
Ball ball = new Ball(i);
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Ball0 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ball0 extends Actor
{
private static final String [] Colors = {"RED", "BLUE", "GREEN", "YELLOW"};
private int value;
Ball0 ball = new Ball0(i);
public Ball0(int id)
{
value = id;
setImage(new GreenfootImage(Colors[value] +"-ball.png"));
}
public String getColor()
{
return Colors[value];
}
public void CreateBalls()
{
int [] num = new int [4];
num [0] = 5+Greenfoot.getRandomNumber(6);
num [1] = 5+Greenfoot.getRandomNumber(6);
num [2] = 5+Greenfoot.getRandomNumber(6);
num [3] = 5+Greenfoot.getRandomNumber(6);
for (int i=0; i<num.length; i++)
{
for (int n=0; n<num[i]; n++)
{
}
}
}
} public void CreateBalls()
{
int [] num = new int [4];
num [0] = 5+Greenfoot.getRandomNumber(6);
num [1] = 5+Greenfoot.getRandomNumber(6);
num [2] = 5+Greenfoot.getRandomNumber(6);
num [3] = 5+Greenfoot.getRandomNumber(6);
for (int i=0; i<num.length; i++)
{
for (int n=0; n<num[i]; n++)
{
Ball0 ball = new Ball0(i);
addObject(Ball0, 300, 200);
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends World
{
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 600, 1);
prepare();
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
}
public void CreateBalls()
{
int [] num = new int [4];
num [0] = 5+Greenfoot.getRandomNumber(6);
num [1] = 5+Greenfoot.getRandomNumber(6);
num [2] = 5+Greenfoot.getRandomNumber(6);
num [3] = 5+Greenfoot.getRandomNumber(6);
for (int i=0; i<num.length; i++)
{
for (int n=0; n<num[i]; n++)
{
Ball0 ball = new Ball0(i);
addObject(ball, 300, 200);
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Ball0 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ball0 extends Actor
{
private static final String [] Colors = {"RED", "BLUE", "GREEN", "YELLOW"};
private int value;
public Ball0(int id)
{
value = id;
setImage(new GreenfootImage(Colors[value] +"-ball.png"));
}
public String getColor()
{
return Colors[value];
}
}