You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.3 KiB
56 lines
1.3 KiB
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Fight;
|
|
|
|
public class FighterFormation
|
|
{
|
|
private readonly List<FightWorld.Fighter?> _fighters;
|
|
|
|
public FighterFormation(int slots = 3)
|
|
{
|
|
_fighters = [];
|
|
for (var i = 0; i < slots; i++)
|
|
{
|
|
_fighters.Add(null);
|
|
}
|
|
}
|
|
|
|
public FightWorld.Fighter? GetFighterAtPosition(int position)
|
|
{
|
|
Debug.Assert(position >= 0, "position>=0");
|
|
Debug.Assert(position < _fighters.Count, "position does not exist");
|
|
|
|
return _fighters[position];
|
|
}
|
|
|
|
public void SetFighterAtPosition(int position, FightWorld.Fighter value)
|
|
{
|
|
Debug.Assert(position >= 0, "position>=0");
|
|
Debug.Assert(position < _fighters.Count, "position does not exist");
|
|
|
|
_fighters[position] = value;
|
|
}
|
|
|
|
public bool ContainsFighter(FightWorld.Fighter fighter)
|
|
{
|
|
return _fighters.Contains(fighter);
|
|
}
|
|
|
|
public int GetFirstEmptySlot()
|
|
{
|
|
for (var i = 0; i < _fighters.Count; i++)
|
|
{
|
|
if (_fighters[i] == null)
|
|
return i;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
public int GetEmptySlotCount()
|
|
{
|
|
return _fighters.Count(fighter => fighter == null);
|
|
}
|
|
} |