예제 #1
0
        // Takes a Shot at another Player
        public bool ShootAt(Duelist target)
        {
            double missChance = myRandom.NextDouble();

            // For making sure Miss Chance is random
            //Console.WriteLine("\n\n-----" + missChance + "-----\n\n");

            if (GetHitChance() > missChance)
            {
                target.Kill();
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        // Runs the Match, returns winner
        public static Duelist BeginDuelistMatch(List <Duelist> duelistList)
        {
            // Variables
            int numDuelistsLeft = duelistList.Count;

            // Sorts List
            duelistList.Sort();

            // Runs until there is only one Duelist Left
            while (numDuelistsLeft > 1)
            {
                foreach (Duelist currentShooter in duelistList)
                {
                    if (currentShooter.GetIsAlive())
                    {
                        // Finds Target
                        Duelist target = currentShooter.FindTarget(duelistList, currentShooter);

                        // Shoots at Target
                        if (currentShooter.ShootAt(target))
                        {
                            numDuelistsLeft--;
                        }
                    }
                }
            }

            foreach (Duelist winner in duelistList)
            {
                if (winner.GetIsAlive())
                {
                    return(winner);
                }
            }

            // Unreachable
            return(null);
        }
예제 #3
0
        // Utility Methods
        // Finds a Target to shoot at given a List
        public Duelist FindTarget(List <Duelist> targetList, Duelist currentShooter)
        {
            // Variables
            Duelist toShoot     = null;
            int     listSize    = targetList.Count;
            bool    foundTarget = false;

            while (!foundTarget)
            {
                // Goes through the list in reverse
                for (int i = targetList.Count - 1; i >= 0; i--)
                {
                    Duelist target = targetList[i];
                    if (target.GetIsAlive() && !target.Equals(currentShooter))
                    {
                        toShoot     = target;
                        foundTarget = true;
                        break;
                    }
                }
            }

            return(toShoot);
        }