예제 #1
0
        public static List <Species> PairFromList(ref List <Species> beings)
        {
            // Randomly choose and remove a pair of players from the list

            List <Species> pair = new List <Species>();            // TODO new necessary / difference?
            int            rnd;

            // first pick
            rnd = RndSrc.GetInt(beings.Count);
            pair.Add(beings[rnd]);
            beings.RemoveAt(rnd);

            // second pick
            rnd = RndSrc.GetInt(beings.Count - 1);
            pair.Add(beings[rnd]);
            beings.RemoveAt(rnd);

            return(pair);
        }
예제 #2
0
        public static bool FullFight(ref List <Species> fighters)
        {
            // N rounds of fight until one is dead

            List <Species> pair           = RndSrc.PairFromList(ref fighters); // TODO sanity check here (or exception in method)
            uint           fightRound     = 1;
            bool           fightOn        = true;
            bool           retHasSurvivor = true;

            Console.WriteLine("Fight No " + ++_fightCnt);
            FightersPrint("all fighters:", fighters);
            FightersPrint("upcoming fight pair:", pair);

            // fight all necessary rounds
            while (fightOn)
            {
                fightOn &= FightRound(pair, fightRound);     // both survived?
                fightOn &= (++fightRound < Const.MaxRounds); // MaxRounds?

                //fightOn &= Health.RecoverInFight(fighters);
            }

            // recover survivor, if any
            Species survivor = WhoSurvived(pair);

            if (survivor != null)
            {
                survivor.Health = Const.MaxPercent;
                fighters.Add(survivor);
            }
            else
            {
                retHasSurvivor = false;
            }
            Console.WriteLine(NewLine + "Fight Over, " + GetSurvivedName(survivor) + " won." + NewLine);

            return(retHasSurvivor);
        }
예제 #3
0
        private static void FightOneWay(Species attacker, Species blocker)
        {
            // 30% scatter to players abilities
            double attack = RndSrc.Vary(attacker.AttackMax, 30d, Const.MaxPercent);
            double block  = RndSrc.Vary(blocker.BlockMax, 30d, Const.MaxPercent);

            // calculate BANG result for blocker
            double damage = attack - block;

            if (damage < 0)
            {
                damage = 0;                                                   // fighting can only decrease health
            }
            blocker.Health -= damage;                                         // TODO design: write to health  vs  return health (write protected)?
            blocker.Health -= (double)Const.MaxPercent / Const.MaxFightMoves; // each fight move also exhausts = limit moves (both fighters block)
            if (blocker.Health < 0)
            {
                blocker.Health = 0;                      // TODO check within Property (performance..)?
            }
            // visualize the result of the attack
            Console.WriteLine("{0} attack={1:0}  {2} block={3:0} damage={4:0}", attacker.Name, attack, blocker.Name, block, damage);
            Console.WriteLine(blocker.Name + " " + blocker.getHealthBar());
        }