给出下一个代码:
// 这是某个大型方法的一部分 //
ArrayList<String> players = this.m_maze.getPlayers();
// define the first node to be the human player , and pop him from the list
// the rest of the nodes are the computer side
Iterator<String> iterator = players.iterator();
// human side
String humanPlayer = iterator.next();
// controller - start a game between the players , at least two players are playing
while (this.m_rounds > 0)
{
String[] choices = this.m_view.getChoiceFromUser();
int usersChoice = Integer.parseInt(choices[0]);
switch (usersChoice)
{
case 1: // then user chose to stay put
{
}
case 2: // then take the next step
{
// let the user make his move
this.m_maze = this.m_model.makeSomeMove(choices[1],humanPlayer,true);
// print out the maze for visualization
this.m_view.drawMaze(m_maze);
// controller - reduce the number of current rounds for the current game
this.m_rounds--;
}
case 31: // then user asked for the closest treasure
{
// put some code here later on
}
case 32: // then user asked for the nearest room
{
// put some code here later on
}
} // end switch case
} // end while
(1).如何放入humanPlayer
每次调用后 ArrayList 的第一个元素makeSomeMove
?
(2).迭代器可以重用吗?因为我使用hasnext()
and next()
... ?
非常感谢
罗恩
如果你想重用迭代器,你必须重新初始化它。
你必须执行Iterator<String> iterator = players.iterator();
每当你想重用迭代器时。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)