Пример #1
0
    public void Execute()
    {
        if (this.Settings == null)
        {
            OnNotification(NotificationEventArgs.Create("Invalid Settings"));
        }
        try
        {
            // Check if any elements start already outside the bouderies
            CheckOutOfBounderiesElements();

            foreach (var moves in this.Moves)
            {
                OnNotification(NotificationEventArgs.Create("Hacthing new turtle"));
                this.Turtle = Turtle.Hatch(this.Settings.Turtle, this.Compass.GetOrientation(this.Settings.Turtle.Orientation) ?? new North());

                OnNotification(NotificationEventArgs.Create($"Running sequence: {string.Join(',', moves)}"));

                RunSequence(moves);

                Reset();

                OnNotification(NotificationEventArgs.Create("_______________________________________________"));
            }
        }
        catch (OutBounderiesException e)
        {
            OnNotification(NotificationEventArgs.Create($"'{e.Message}' is outside '{this.Settings.GetType().Name}' limits"));
        }

        OnNotification(NotificationEventArgs.Create("Game completed"));
    }
Пример #2
0
    private void RunSequence(string[] sequences)
    {
        foreach (var s in sequences)
        {
            switch (s)
            {
            case "R":
                this.Rotate(this.Turtle);
                break;

            case "M":
                this.Move(this.Turtle);

                CheckBoundries(this.Turtle);

                if (DetectCollision(this.Turtle))
                {
                    this.landedOnSomething = true;
                    OnNotification(NotificationEventArgs.Create($"{this.Turtle.ToString()} => poor 'turtle' landed on a mine"));
                    break;
                }
                var _foundTheExit = FoundTheExit(this.Turtle);
                if (_foundTheExit)
                {
                    this.landedOnSomething = true;
                    OnNotification(NotificationEventArgs.Create($"{this.Turtle.ToString()} => exit was found"));
                    break;
                }
                OnNotification(NotificationEventArgs.Create(this.Turtle.ToString()));
                break;
            }
        }

        if (!this.landedOnSomething)
        {
            OnNotification(NotificationEventArgs.Create("Out of movements, 'Turtle' was unable to find the exit, nor died!"));
        }
    }