I have lately been wanting to construct a solitaire or black jack game using java. When I started to code I ran into a problem about efficiently importing all the image filles for the cards. I immediately looked it up but I did not get any answers. Wy question is why cant you name images like this:
for (int num = 0; num1 < 40; num++ ){
Image names[num] = getImage ( getDocumentBase (), "c" + (num +1) + ".gif" );
}
If you find any other problems please let me know. Thank you in advance. this is the full code:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Color;
public class CardsJavaProgram extends Applet {
public void init(){
String names [ ] = { "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10", "h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "h9", "h10"};
for (int num = 0; num1 < 40; num++ ){
Image names[num] = getImage ( getDocumentBase (), "c" + (num +1) + ".gif" );
}
}
public void paint( Graphics screen ){
int x = 10;
for (int num5 = 0; num5 < 5; num5++ ){
screen.drawImage( names[ (int) (Math.random () * 39)], x, 10, 100, 100, this );
x = x + 100;
}
}
}
P.S. I know that the kings queens and jacks are not being imported.
names