UPD. Hello, I know how code below is working. I know that cross, and circle are pointing to Cross(), and Circle() method. But I am still filling little confuse with this part of code. Can you explain it for me?
public GameMoves()
{
cross = Cross();
circle = Circle();
}
All code
static void Main(string[] args)
{
GameMoves game = new GameMoves();
IEnumerator enumerator = game.Cross();
while (enumerator.MoveNext())
{
enumerator = (IEnumerator)enumerator.Current;
}
}
}
public class GameMoves
{
private IEnumerator cross;
private IEnumerator circle;
public GameMoves()
{
cross = Cross();
circle = Circle();
}
private int move = 0;
public IEnumerator Cross()
{
while (true)
{
Console.WriteLine("X, step {0}", move);
move++;
if (move > 9)
yield break;
yield return circle;
}
}
public IEnumerator Circle()
{
while (true)
{
Console.WriteLine("O, step {0}", move);
move++;
if (move > 9)
yield break;
yield return cross;
}
}
}