Exemple #1
0
        public void Execute(ProcessorContext processorContext, BrianDuck brianDuck, Cell[] cells)
        {
            if (brianDuck.CarriedItem == Material.None)
            {
                Console.WriteLine("Brian isn't holding anything!");
                return;
            }

            var workbench = cells[processorContext.PointerIndex];

            switch (brianDuck.CarriedItem)
            {
            case Material.Leg:
                workbench.LegCount++;
                break;

            case Material.Top:
                workbench.TopCount++;
                break;

            case Material.Table:
                workbench.TableCount++;
                break;

            case Material.None:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            brianDuck.CarriedItem = Material.None;
        }
Exemple #2
0
        public void Execute(ProcessorContext processorContext, BrianDuck brianDuck, Cell[] cells)
        {
            var cell = cells[processorContext.PointerIndex];

            cell.ByteCount++;
            Debug.WriteLine("Increase ByteCount.  Pointer: {0} ByteCount: {1}", processorContext.PointerIndex, cell.ByteCount);
        }
        void IInstruction.Execute(ProcessorContext processorContext, BrianDuck brianDuck, Cell[] cells)
        {
            var workbench = cells[processorContext.PointerIndex];

            workbench.ByteCount--;
            Debug.WriteLine("Decrease ByteCount.  Pointer: {0} ByteCount: {1}", processorContext.PointerIndex, workbench.ByteCount);
        }
Exemple #4
0
 public void Execute(ProcessorContext processorContext, BrianDuck brianDuck, Cell[] cells)
 {
     Debug.WriteLine("End of Loop");
     if (processorContext.LoopIndexTracker.Any())
     {
         var programIndex = processorContext.LoopIndexTracker.Pop();
         processorContext.InstructionIndex = programIndex;
     }
     else
     {
         Debug.WriteLine("Error");
     }
 }
Exemple #5
0
        void IInstruction.Execute(ProcessorContext processorContext, BrianDuck brianDuck, Cell[] cells)
        {
            var workbench = cells[processorContext.PointerIndex];

            if (workbench.LegCount == 4 && workbench.TopCount == 1)
            {
                workbench.TableCount += 1;
                workbench.LegCount   -= 4;
                workbench.TopCount   -= 1;
            }
            else
            {
                Console.WriteLine("I can't build a table with this!");
            }
        }
Exemple #6
0
        public void Execute(ProcessorContext processorContext, BrianDuck brianDuck, Cell[] cells)
        {
            if (brianDuck.CarriedItem != Material.None)
            {
                Console.WriteLine("Brian is already holding something.  He cannot pickup");
                return;
            }

            var workbench = cells[processorContext.PointerIndex];

            if (workbench.IsEmpty)
            {
                Console.WriteLine("Nothing To PickUp");
                return;
            }

            var material = workbench.PickUp();

            brianDuck.CarriedItem = material;
        }
        public void Execute(ProcessorContext processorContext, BrianDuck brianDuck, Cell[] cells)
        {
            Debug.WriteLine("Start Loop");
            var cell = cells[processorContext.PointerIndex];

            if (cell.ByteCount == 0)
            {
                var track = new Stack <int>();

                for (var instructionIndex = processorContext.InstructionIndex;
                     instructionIndex < processorContext.Instructions.Count;
                     instructionIndex++)
                {
                    var instruction     = processorContext.Instructions[instructionIndex];
                    var instructionType = instruction.GetType();
                    if (instructionType == typeof(StartLoop))
                    {
                        track.Push(instructionIndex);
                    }
                    else if (instructionType == typeof(EndLoop))
                    {
                        track.Pop();
                    }

                    if (track.Count == 0)
                    {
                        Debug.WriteLine("Closing Brace Index: " + instructionIndex);
                        processorContext.InstructionIndex = instructionIndex;
                        break;
                    }
                }
            }
            else
            {
                // Decrease index beacuse the instruction processor will increase the program index. Better to double check the StartLoop.
                processorContext.LoopIndexTracker.Push(processorContext.InstructionIndex - 1);
            }
        }
Exemple #8
0
 public void Execute(ProcessorContext processorContext, BrianDuck brianDuck, Cell[] cells)
 {
     processorContext.PointerIndex--;
     Debug.WriteLine("Move Pointer Left: New Pointer: {0}", processorContext.PointerIndex);
 }