コード例 #1
0
ファイル: TimeLine.cs プロジェクト: Seth-/BehaviorIsManaged
        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
ファイル: TimeLine.cs プロジェクト: Seth-/BehaviorIsManaged
        /// <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());
        }