我似乎無法弄清楚這個錯誤,說「世界必須宣佈最終」。有什麼建議?我正在製作一個gridworld項目(匹配遊戲)。段如何製作數組最終?
temparray.add(world.getLocation().getColor());
要求它是最終的......但添加最後world.get等等說非法開始表達。
import info.gridworld.actor.ActorWorld;
import info.gridworld.actor.*;
import info.gridworld.grid.*;
import info.gridworld.world.*;
import java.awt.Color;
import java.util.ArrayList;
public class cardGameDriver extends ActorWorld
{
public static void main(String[] args)
{
World world = new World();
world.show();
world.add(new card1());
world.add(new card1());
world.add(new card2());
world.add(new card2());
world.add(new card3());
world.add(new card3());
world.add(new card4());
world.add(new card4());
world.add(new card5());
world.add(new card5());
world.add(new card6());
world.add(new card6());
world.add(new card7());
world.add(new card7());
world.add(new card8());
world.add(new card8());
world.add(new card9());
world.add(new card9());
world.add(new card10());
world.add(new card10());
world.add(new card11());
world.add(new card11());
world.add(new card12());
world.add(new card12());
world.add(new card13());
world.add(new card13());
world.add(new card14());
world.add(new card14());
world.add(new card15());
world.add(new card15());
world.add(new card16());
world.add(new card16());
world.add(new card17());
world.add(new card17());
world.add(new card18());
world.add(new card18());
System.out.println("Time yourself to see how fast you can make all 18 matches.");
ArrayList<cards> temparray = new ArrayList<cards>();
java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addKeyEventDispatcher(new java.awt.KeyEventDispatcher()
{
public boolean dispatchKeyEvent(java.awt.event.KeyEvent event)
{
String key = javax.swing.KeyStroke.getKeyStrokeForEvent(event).toString();
int x = 0;
if (key.equals("pressed ENTER"))
{
temparray.add(world.getLocation().getColor());
x++;
if(x == 2)
{
if(temparray.get(0) == temparray.get(1))
{
System.out.println("User has made a match!");
}
else
{
System.out.println("Try again!");
}
x = 0;
}
}
return true;
}
});
}
}
我們在AP計算機科學中有這樣一個稱爲網格世界的東西。好時光;-) – Solace
因爲它在你的匿名類的'dispatchKeyEvent'方法中提到。因此它一定是最終的。 – Bart