public Tuple <int, int> Attack(Challenger target)
        {
            var step = DoAttack(target);

            Logger.Write(this, $"Shoot <{step}>");

            return(ParseStep(step));
        }
Beispiel #2
0
        private void Shoot(Challenger initiator, Challenger target)
        {
            bool hitting;

            do
            {
                Display();
                var step = initiator.Attack(target);
                hitting = target.HandleStep(step.Item1, step.Item2);
                Logger.Write(target, $"HandleStep <{step.Item1}, {step.Item2}>");
            } while (hitting && GetGameState() == State.NextStep);
        }
Beispiel #3
0
        protected override string DoAttack(Challenger target)
        {
            System.Console.Write("Enter your step: ");
            var step = System.Console.ReadLine()?.ToUpper() ?? "-";

            while (!ValidateStep(step, target))
            {
                System.Console.WriteLine("Incorrect input!");
                System.Console.Write("Enter your step: ");
                step = System.Console.ReadLine()?.ToUpper() ?? "-";
            }

            return(step);
        }
Beispiel #4
0
        private bool ValidateStep(string step, Challenger target)
        {
            if (!_stepPattern.IsMatch(step))
            {
                Logger.Write(this, $"ValidateStep({step}): isn't match regex!");
                return(false);
            }

            var pair = ParseStep(step);

            if (target.Map[pair.Item1, pair.Item2] == Map.Ceil.Empty ||
                target.Map[pair.Item1, pair.Item2] == Map.Ceil.Ship)
            {
                return(true);
            }

            Logger.Write(
                this,
                $"ValidateStep({step}): isn't valid"
                + $", cuz target.Map[{pair.Item1}, {pair.Item2}] == {target.Map[pair.Item1, pair.Item2]}"
                );
            return(false);
        }
Beispiel #5
0
 public Game()
 {
     _enemy  = new Enemy();
     _player = new Player();
 }
Beispiel #6
0
 public static void Write(Challenger challenger, string message)
 {
     Write(challenger.GetType().Name + "." + message);
 }
 protected abstract string DoAttack(Challenger target);