using System.Collections; namespace PkmnLib.Dynamic.Models; public interface IPokemonParty : IReadOnlyList { /// /// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon. /// IPokemon? SwapInto(IPokemon pokemon, int index); /// /// Swaps two Pokemon in the party around. /// void Swap(int index1, int index2); bool HasUsablePokemon(); } public class PokemonParty : IPokemonParty { private readonly IPokemon?[] _pokemon; public PokemonParty(int size) { _pokemon = new IPokemon[size]; } /// /// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon. /// public IPokemon? SwapInto(IPokemon pokemon, int index) { var old = _pokemon[index]; _pokemon[index] = pokemon; return old; } /// /// Swaps two Pokemon in the party around. /// public void Swap(int index1, int index2) => (_pokemon[index1], _pokemon[index2]) = (_pokemon[index2], _pokemon[index1]); public bool HasUsablePokemon() => _pokemon.Any(p => p != null && p.IsUsable); /// public IEnumerator GetEnumerator() => ((IEnumerable)_pokemon).GetEnumerator(); /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// public int Count => _pokemon.Length; /// public IPokemon? this[int index] => _pokemon[index]; }