void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
     DontDestroyOnLoad(gameObject);
     audSource     = this.GetComponent <AudioSource>();
     objectGrabbed = false;
 }
            public TurnAction GetNextDirection(IList <TurnAction> movements, Location loc)
            {
                LocationsTracker.Push(loc);//Register location as visited

                if (movements.Count == 1)
                {
                    try
                    {
                        var now = MovementTool.Reverse(ActionTracker.Pop());
                        StepTracker.Push(new TrackedLocation(loc, now));
                        return(now);
                    }catch (Exception e)
                    {
                        var now = movements[0];
                        StepTracker.Push(new TrackedLocation(loc, now));
                        ActionTracker.Push(now);
                        return(now);
                    }
                }

                var trimHasBeen = movements.Where(s => !BeenToTarget(loc, s)).ToList();

                if (trimHasBeen.Count == 0)
                {
                    var now = MovementTool.Reverse(ActionTracker.Pop());
                    StepTracker.Push(new TrackedLocation(loc, now));
                    return(now);
                }


                TurnAction dirToGoBias;

                try
                {
                    dirToGoBias = MovementTool.Leftify(ActionTracker.Peek());
                }
                catch (Exception)
                {
                    dirToGoBias = movements[new Random().Next(movements.Count)];
                }

                var value = trimHasBeen.Contains(dirToGoBias)
                    ? dirToGoBias
                    : trimHasBeen[new Random().Next(trimHasBeen.Count)];

                StepTracker.Push(new TrackedLocation(loc, value));
                ActionTracker.Push(value);

                return(value);
            }
Ejemplo n.º 3
0
        private void EndStep(StepTracker step)
        {
            if (!object.ReferenceEquals(step, steps.Peek()))
            {
                throw new InvalidOperationException($"Attempting to end a step that isn't running. Currently executing step: {steps.Peek()?.Title}");
            }

            indent -= IndentAmount;
            steps.Pop();

            if (step.Message != null)
            {
                WriteDebugLine(step.Message);
            }
        }
Ejemplo n.º 4
0
        public StepTracker BeginStep(string title)
        {
            if (title is null)
            {
                throw new ArgumentNullException(nameof(title));
            }

            WriteInfoLine(title);

            indent += IndentAmount;
            var currentStep = new StepTracker(this, title);

            steps.Push(currentStep);

            return(currentStep);
        }
 public void RegisterMove(Location loc, bool isInter, TurnAction ac)
 {
     StepTracker.Push(new TrackedLocation(loc, ac));
     LocationsTracker.Push(loc);
     ActionTracker.Push(ac);
 }
Ejemplo n.º 6
0
 public ScopedClassBindings(StepTracker stepTracker)
 {
     this.stepTracker = stepTracker;
 }
Ejemplo n.º 7
0
 public GeneralBindings(StepTracker stepTracker)
 {
     this.stepTracker = stepTracker;
 }