我正在创造一个游戏。我需要随机创建对象,但我希望它们有一定数量。这是我随机创建的对象的主要类代码
private void randomTiles() {
int randomXtile = new Random().nextInt(9500) + 20;
int randomYtile = new Random().nextInt(12) + 0;
Tile t = new Tile(randomXtile, randomYtile, 3);
tilearray.add(t);
}
private void updateTiles() {
randomTiles();
for (int i = 0; i < tilearray.size(); i++) {
Tile t = (Tile) tilearray.get(i);
t.update();
}
}
private void paintTiles(Graphics g) {
for (int i = 0; i < tilearray.size(); i++) {
Tile t = (Tile) tilearray.get(i);
g.drawImage(t.getTileImage(), t.getTileX(), t.getTileY(), this);
}
}
tile构造函数是
public Tile(int x, int y, int typeInt) {
tileX = x * 40;
tileY = y * 40;
type = typeInt;
r = new Rectangle();
if (type == 5) {
tileImage = StartingClass.tiledirt;
} else if (type == 8) {
tileImage = StartingClass.tilegrassTop;
} else if (type == 4) {
tileImage = StartingClass.tilegrassLeft;
} else if (type == 6) {
tileImage = StartingClass.tilegrassRight;
} else if (type == 2) {
tileImage = StartingClass.tilegrassBot;
} else if (type == 3) {
tileImage = StartingClass.ice;
hp = 2;
} else {
type = 0;
}
}
我的游戏对象中的某个地方应该来到某个坐标。你能帮我解决这个问题吗?