考慮以下幾點:重新初始化不起作用
// get the list of the players , in order to start the game
ArrayList<String> players = this.m_maze.getPlayers();
// human side
String humanPlayer = iterator.next();
String computerPlayer = null;
// define iterator for the players
Iterator<String> iterator = players.iterator();
boolean humanSide = true ,computerSide = false; // assume the human player is starting the game
// controller - start a game between the players , at least two players are playing
while (this.m_rounds > 0)
{
if (humanSide == false && computerSide == true) // then this is the turn of the human side
{
if (iterator.hasNext() == false)
{
// reinitialize the iterator
Iterator<String> iterator = players.iterator();
}
while (iterator.hasNext())
// more code
我嘗試重用迭代器,但我得到一個「複製局部變量的迭代器」編譯錯誤。我怎樣才能重用該迭代器? 謝謝你,羅恩
編輯:
if (iterator.hasNext() == false)
{
// reinitialize the iterator
iterator = players.iterator();
}
while (iterator.hasNext())
{
computerPlayer = iterator.next();
// computer decides what would be his next move , between 1 - 3
這聽起來像你真正想要做的是循環迭代。你有沒有考慮過使用循環數據結構? – 2012-02-04 06:30:40
這是一個非常好的主意,我會考慮到這一點,謝謝! – ron 2012-02-04 06:33:02