[英]How can I refer to an as-variable inside a nested Gremlin traversal?
[英]Can a variable refer to a component inside of a FOR?
這是我所擁有的:
有9個法術等級。 法師每天只能施放一定數量的咒語。
我建立了一個選項卡式窗格(9個選項卡),每個選項卡中都有9個空方塊(圖像)。
下面的數字(4、3、2、1和0s)是法師可以施展的法術數量。
我想設置不會被使用的正方形。
例:
如果他可以在等級1上施放4個咒語,則image1square5至image1square9變為不可見。 在第2級,從image2square4到image2square9的3個咒語變得不可見。
我嘗試了這個:
int lvl1, lvl2, lvl3, lvl4, lvl5,lvl6,lvl7,lvl8,lvl9;
lvl1 = 4 +1;
lvl2 = 3 +1;
lvl3 = 3 +1;
lvl4 = 2 +1;
lvl5 = 1 +1;
lvl6 = 0 +1;
lvl7 = 0 +1;
lvl8 = 0 +1;
lvl9 = 0 +1;
for (int i = n1; i <= 9; i++) {
image1square+i.setVisible(false);
}
for (int i = n2; i <= 9; i++) {
image2square+i.setVisible(false);
}
等等...
如何在FOR中使用變量?
使用數組或列表,而不是順序命名變量。
如果要創建基於圖塊的游戲,則多維數組或List<List<?>>
會更合適。
我回去學習,但仍然無法正常工作。 這是我現在擁有的:
我省略了
jImage1Empty1, jImage1Empty2, jImage2Empty1, etc,
但是他們被宣布了。 它們是帶有標簽的jlabel。 我在每個窗格中顯示9張圖像,但是開始后,應該將其中一些設置為setvisible(false)。
int lvl[] = new int[9];
lvl[0] = 4 +1;
lvl[1] = 3 +1;
lvl[2] = 3 +1;
lvl[3] = 2 +1;
lvl[4] = 1 +1;
lvl[5] = 0 +1;
lvl[6] = 0 +1;
lvl[7] = 0 +1;
lvl[8] = 0 +1;
String img1 = "jImage1Empty";
String img2 = "jImage2Empty";
for (int i = 0; i < 9; i++) {
img1 +lvl[0].setVisible(false);
}
for (int i = 0; i < 9; i++) {
img2 +lvl[1].setVisible(false);
}
}
我希望結果是這樣的:
jImage1Empty5.setVisible(false);
jImage1Empty6.setVisible(false);
jImage1Empty7.setVisible(false);
jImage1Empty8.setVisible(false);
jImage1Empty9.setVisible(false);
jImage2Empty4.setVisible(false);
jImage2Empty5.setVisible(false);
jImage2Empty6.setVisible(false);
jImage2Empty7.setVisible(false);
jImage2Empty8.setVisible(false);
jImage2Empty9.setVisible(false);
etc...
But not as string. As a command.
可能嗎? 救命
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.