I am currently working on a small Java game in eclipse, and am knee deep in a few thousand lines of code. Right now, I am specifically attempting to use a String's contents to paint an image, and am wondering if it is possible. If it is it would save me at least a few hundred lines of individual variables for each image.
Pasting the whole program would more than likely prove counter productive due to the length, so I will merely demonstrate what I am attemtping.
What I am attempting to do:
ImageIcon ladder = new ImageIcon (getClass ().getResource ("ladder.png"));
floorContents [currentX] [currentY] = "ladder";
public void paint (Graphics g)
{
if (floorContents [currentX] [currentY] != "none") // painting item where standing
{
floorContents[currentX][currentY].paintIcon (this, g, 0, 0);
}
}
Essentially I am attempting to get the program to see this line:
floorContents[currentX][currentY].paintIcon (this, g, 0, 0);
as this:
ladder.paintIcon (this, g, 0, 0);
If at all possible. This would save me from having to write in each image item seperately.