summaryrefslogtreecommitdiff
path: root/MorgSimulator/Framework/EntityIterator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MorgSimulator/Framework/EntityIterator.cs')
-rw-r--r--MorgSimulator/Framework/EntityIterator.cs35
1 files changed, 35 insertions, 0 deletions
diff --git a/MorgSimulator/Framework/EntityIterator.cs b/MorgSimulator/Framework/EntityIterator.cs
new file mode 100644
index 0000000..84976c7
--- /dev/null
+++ b/MorgSimulator/Framework/EntityIterator.cs
@@ -0,0 +1,35 @@
+#nullable enable
+using System.Collections.Generic;
+
+namespace MorgSimulator.Framework
+{
+ public class EntityIterator<T> : IEntityIterator<T> where T : Entity
+ {
+ private readonly List<T> _entities;
+ private int _currentIndex = 0;
+
+ public EntityIterator(List<T> entities)
+ {
+ _entities = entities;
+ }
+
+ public bool HasNext()
+ {
+ return _currentIndex < _entities.Count;
+ }
+
+ public T? Next()
+ {
+ if (!HasNext())
+ return null;
+
+ return _entities[_currentIndex++];
+ }
+
+ public void Reset()
+ {
+ _currentIndex = 0;
+ }
+ }
+}
+#nullable disable