Пример #1
0
        public Fighter GetNextPlayer()
        {
            if (Fighters.Count == 0 || Fighters.All(entry => !entry.CanPlay()))
            {
                return(null);
            }

            int counter = 0;
            int index   = (Index + 1) < Fighters.Count ? Index + 1 : 0;

            while (!Fighters[index].CanPlay() && counter < Fighters.Count)
            {
                index = (index + 1) < Fighters.Count ? index + 1 : 0;

                counter++;
            }

            if (!Fighters[index].CanPlay()) // no fighter can play
            {
                Index = -1;
                return(null);
            }

            return(Fighters[index]);
        }
Пример #2
0
        /// <summary>
        /// Get all fighters who will play before the turn of <paramref name="fighter"/>
        /// </summary>
        /// <param name="fighter"></param>
        /// <returns></returns>
        public Fighter[] GetNextPlayers(Fighter fighter)
        {
            var result = new List <Fighter>();

            if (CurrentPlayer == fighter || Fighters.Count == 0 || Fighters.All(entry => !entry.CanPlay()))
            {
                return(new Fighter[0]);
            }

            var currentFighter = GetNextPlayer();
            int index          = (Index + 1) < Fighters.Count ? Index + 1 : 0;

            while (currentFighter != fighter)
            {
                if (currentFighter.CanPlay())
                {
                    result.Add(currentFighter);
                }

                index = (index + 1) < Fighters.Count ? index + 1 : 0;
            }

            return(result.ToArray());
        }