|
|
|
@ -1,9 +1,12 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Fight;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Fight;
|
|
|
|
|
|
|
|
|
|
|
|
public class FighterTurn
|
|
|
|
public class FighterTurn : IEnumerable<FightWorld.Fighter>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private class Node
|
|
|
|
private class Node
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -13,7 +16,8 @@ public class FighterTurn
|
|
|
|
|
|
|
|
|
|
|
|
private Node? _currentNode;
|
|
|
|
private Node? _currentNode;
|
|
|
|
|
|
|
|
|
|
|
|
public FightWorld.Fighter Current => _currentNode?.fighter ?? throw new InvalidOperationException("No current fighter");
|
|
|
|
public FightWorld.Fighter Current =>
|
|
|
|
|
|
|
|
_currentNode?.fighter ?? throw new InvalidOperationException("No current fighter");
|
|
|
|
|
|
|
|
|
|
|
|
public void Next()
|
|
|
|
public void Next()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -84,7 +88,7 @@ public class FighterTurn
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// if removing current, keep current
|
|
|
|
// if removing current, keep current
|
|
|
|
// it will be implicitly deleted by loss of reference on the next Next() call
|
|
|
|
// it will be implicitly deleted by loss of reference on the next Next() call
|
|
|
|
|
|
|
|
|
|
|
|
node.next = node.next.next;
|
|
|
|
node.next = node.next.next;
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -94,4 +98,26 @@ public class FighterTurn
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerator<FightWorld.Fighter> GetEnumerator()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_currentNode == null) return Enumerable.Empty<FightWorld.Fighter>().GetEnumerator();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var list = new List<FightWorld.Fighter>();
|
|
|
|
|
|
|
|
var n = _currentNode;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
list.Add(n.fighter);
|
|
|
|
|
|
|
|
if (n.next == _currentNode)
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
n = n.next;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return list.GetEnumerator();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return GetEnumerator();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|