Exemplo n.º 1
0
        public static void AttackRound(Character attacker, Character defender, BattleLogger newlog, ref int roundNr)
        {
            Random rnd = new Random();


            double tryToHit     = rnd.NextDouble() * 100;
            double hitLimit     = attacker.CritChance + attacker.HitChance;
            double damageSpread = attacker.Damage * ((rnd.NextDouble() - 0.5) / 2);
            double damageDone   = attacker.Damage + damageSpread;

            if (tryToHit > hitLimit)
            {
                Console.WriteLine($"{(attacker.IsPlayer == true ? "You" : attacker.CharacterName)} missed!!! How unfortunate!!");
                damageDone = 0;
                newlog.logRound(roundNr.ToString(), attacker.CharacterName, damageDone.ToString(), defender.CharacterName, defender.Health.ToString());
                return;
            }
            if (tryToHit <= attacker.CritChance)
            {
                double criticalDamageDone = Math.Round((Double)damageDone * 1.25, 2);
                defender.Health = defender.Health - criticalDamageDone < 0 ?
                                  0 : Math.Round((Double)(defender.Health - criticalDamageDone), 2);
                Console.WriteLine($"{(attacker.IsPlayer == true ? "You" : attacker.CharacterName)}" +
                                  $" critically hit {(attacker.IsPlayer == true ? defender.CharacterName : "you")}, dealing {criticalDamageDone} damage");
                newlog.logRound(roundNr.ToString(), attacker.CharacterName, damageDone.ToString(), defender.CharacterName, defender.Health.ToString());
                return;
            }
            damageDone      = Math.Round((Double)damageDone - defender.Block, 2);
            damageDone      = damageDone <= 0 ? 0 : damageDone;
            defender.Health = defender.Health - damageDone < 0 ? 0 : Math.Round((Double)(defender.Health - damageDone), 2);

            Console.WriteLine($"{(attacker.IsPlayer == true ? "You" : attacker.CharacterName)}" +
                              $" hit {(attacker.IsPlayer == true ? defender.CharacterName : "you")}, dealing {damageDone} damage ");
            newlog.logRound(roundNr.ToString(), attacker.CharacterName, damageDone.ToString(), defender.CharacterName, defender.Health.ToString());
        }
Exemplo n.º 2
0
        public bool EngageBattle()
        {
            BattleLogger newlog       = new BattleLogger();
            int          roundNr      = 1;
            Random       rnd          = new Random();
            bool         bothAreAlive = true;
            bool         isAlive      = true;

            while (bothAreAlive)
            {
                double playerSpeed   = _player.Speed * (rnd.NextDouble() - 0.5);
                double opponentSpeed = _opponent.Speed * (rnd.NextDouble() - 0.5);
                bool   playerAttack  = playerSpeed >= opponentSpeed ? true : false;

                Console.WriteLine($"Round {roundNr}");
                if (playerAttack)
                {
                    Round.AttackRound(_player, _opponent, newlog, ref roundNr);
                }
                else
                {
                    Round.AttackRound(_opponent, _player, newlog, ref roundNr);
                }



                if (_player.Health <= 0)
                {
                    Console.WriteLine("You are dead!");
                    isAlive = false;

                    _ = newlog.WriteLog();

                    return(isAlive);
                }
                if (_opponent.Health <= 0)
                {
                    Console.WriteLine("Your opponent is dead!");

                    _ = newlog.WriteLog();

                    return(isAlive);
                }

                Console.WriteLine($"Your health is: {_player.Health}");
                Console.WriteLine($"The opponent health is: {_opponent.Health}");
                roundNr++;


                Console.ReadKey();
            }

            return(isAlive);
        }