考虑以下几点:重新初始化不起作用
// 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