Пример #1
0
        private static void GetInputsAndShoot()
        {
            var angle = GetAngle();
            var speed = GetSpeed();

            var attempt = new CannonShotAttempt(angle, speed);
            var result  = CannonInstance.Shoot(attempt);

            if (result.Hit)
            {
                Console.Write($"Hit - {CannonInstance.PreviousShotResults.Count} shot(s)");
                Console.Write("Would you like to play again? (Y/N)");
                var answerKey = Console.ReadKey();
                var answer    = answerKey.Key == ConsoleKey.Y;
                if (answer)
                {
                    CannonInstance.Reset();
                    Play();
                }
            }
            else
            {
                Console.WriteLine($"Missed shot landed at {result.ShotDistance}m");
                GetInputsAndShoot();
            }
        }
Пример #2
0
 public CannonShotResult(CannonShotAttempt attempt, double targetDistance)
 {
     Attempt        = attempt;
     TargetDistance = targetDistance;
     ShotDistance   = CalculateShotDistance();
     Hit            = !(ShotDistance >= TargetDistance + 50 || ShotDistance <= TargetDistance - 50);
 }