我最近一直想用 java 构建一个纸牌或二十一点游戏。当我开始编码时,我遇到了一个关于有效导入卡片的所有图像填充的问题。我立即查了一下,但没有得到任何答案。Wy 的问题是为什么你不能这样命名图像:
for (int num = 0; num1 < 40; num++ ){
Image names[num] = getImage ( getDocumentBase (), "c" + (num +1) + ".gif" );
}
如果您发现任何其他问题,请告诉我。先感谢您。这是完整的代码:
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;
}
}
}
PS我知道Kings Queens和Jacks没有被进口。