Basically, what I'm asking is, how can I multiply an integer (that may change between use) and a set number to create the size of the world? I'm sure this is possible, as I've seen it done somewhere before.
/** base world used to get user data defining the new world */
public MyWorld()
{
super(1, 1, 1);
GreenfootImage bg = null;
int boardNum = 0;
for (;;)
{
// etc. (getting 'image')
if (bg == null) bg = image;
else
{
GreenfootImage old = new GreenfootImage(bg);
bg = new GreenfootImage(old.getWidth()+image.getWidth(), old.getHeight());
bg.drawImage(old, 0, 0);
bg.drawImage(image, old.getWidth(), 0);
}
boardNum++;
}
Greenfoot.setWorld(new MyWorld(bg));
}
/** construct a new user-defined world */
public MyWorld(GreenfootImage bg)
{
super(bg.getWidth(), bg.getHeight(), 1);
setBackground(bg);
// etc.public class HorizontalBackground extends World
{
private String boardPositions;
/**
*
*/
public HorizontalBackground()
{
super(8332, 1000, 1);
boardPositions = JOptionPane.showInputDialog("Enter the order of the boards, separated by a space.\nExample: 1 2 2 1");
String[] boards = boardPositions.split(" ");
if ((boardPositions != null) && (boardPositions.isEmpty() != true))
{
int x = 0;
for(int i=0; i<boards.length; i++)
{
GreenfootImage image = new GreenfootImage("Horizontal Hexagon Board (33x10) " + boards[i] + ".png");
getBackground().drawImage(image, x, 0); // draw image on background
x += image.getWidth(); // set new x-coordinate for next image draw
}
}
else
{
JOptionPane.showMessageDialog(null, "One of the fields are empty, please try again!");
}
}
}