Beispiel #1
0
        public Engine(IInputOutputManager inputOutputManager, IRecyclingManager recyclingManager)
        {
            this.inputOutputManager = inputOutputManager;
            this.recyclingManager   = recyclingManager;

            this.recyclingManagerMethods = this.GetRecyclingManagerMethods();
        }
 /// <summary>
 /// Removes all the port translations belonging to the given io manager
 /// </summary>
 /// <param name="ioManager">io manager to remove translations for</param>
 public void RemoveIoManager(IInputOutputManager ioManager)
 {
     for (int i = 0; i < 256; i++)
     {
         if (translations[i].IoManager == ioManager)
             translations[i] = new PortTranslation();
     }
 }
Beispiel #3
0
 public void Execute(
     string[] commandParameters,
     IDictionary <string, IWeapon> weapons,
     IWeaponFactory weaponFactory,
     IInputOutputManager inputOutputManager,
     IGemFactory gemFactory)
 {
     Environment.Exit(0);
 }
 public Engine(
     IInputOutputManager inputOutputManager,
     ICommandDispatcher commandDispatcher,
     IWeaponFactory weaponFactory,
     IGemFactory gemFactory)
 {
     this.inputOutputManager = inputOutputManager;
     this.commandDispatcher  = commandDispatcher;
     this.weapons            = new Dictionary <string, IWeapon>();
     this.weaponFactory      = weaponFactory;
     this.gemFactory         = gemFactory;
 }
Beispiel #5
0
    public void Execute(
        string[] commandParameters,
        IDictionary <string, IWeapon> weapons,
        IWeaponFactory weaponFactory,
        IInputOutputManager inputOutputManager,
        IGemFactory gemFactory)
    {
        string  targetWeaponName = commandParameters[0];
        IWeapon targetWeapon     = weapons[targetWeaponName];

        inputOutputManager.WriteLine($"{targetWeaponName}: {targetWeapon.ToString()}");
    }
        /// <summary>
        /// Adds an IO manager to the multiplexer
        /// </summary>
        /// <param name="ioManager">io manager to add</param>
        /// <param name="multiplexPort">start of the range of multiplexer ports to allocate</param>
        /// <param name="destPort">start of the range of destination ports to use</param>
        /// <param name="length">number of ports to allocate to this io manager</param>
        /// <remarks>
        /// Any existing io managers at these locations will be overwritten
        /// </remarks>
        public void AddIoManager(IInputOutputManager ioManager, byte multiplexPort, byte destPort,
                                    byte length)
        {
            // Validate length
            if (multiplexPort + length > 256 || destPort + length > 256)
                throw new ArgumentOutOfRangeException("length");

            // Add the nessesary translations
            for (int i = 0; i < length; i++)
            {
                translations[multiplexPort + i] =
                    new PortTranslation(ioManager, (byte) (destPort + i));
            }
        }
Beispiel #7
0
    public void Execute(
        string[] commandParameters,
        IDictionary <string, IWeapon> weapons,
        IWeaponFactory weaponFactory,
        IInputOutputManager inputOutputManager,
        IGemFactory gemFactory)
    {
        string targetAxeName = commandParameters[0];
        int    socketIndex   = int.Parse(commandParameters[1]);

        IWeapon targetAxe = weapons[targetAxeName];

        targetAxe.RemoveGem(socketIndex);
    }
Beispiel #8
0
    public void Execute(
        string[] commandParameters,
        IDictionary <string, IWeapon> weapons,
        IWeaponFactory weaponFactory,
        IInputOutputManager inputOutputManager,
        IGemFactory gemFactory)
    {
        string[] tokens       = commandParameters[0].Split(' ');
        string   weaponRarity = tokens[0];
        string   weaponType   = tokens[1];
        string   weaponName   = commandParameters[1];

        IWeapon weapon = weaponFactory.CreateWeapon(weaponType, weaponRarity);

        weapons.Add(weaponName, weapon);
    }
Beispiel #9
0
    public void DispatchCommand(
        string[] commandParameters,
        IDictionary <string, IWeapon> weapons,
        IWeaponFactory weaponFactory,
        IInputOutputManager inputOutputManager,
        IGemFactory gemFactory)
    {
        string commandName = commandParameters[0];

        string[] parameters = commandParameters.Skip(1).ToArray();

        if (!this.commands.ContainsKey(commandName))
        {
            throw new InvalidOperationException($"Command {commandName} not valid!");
        }

        this.commands[commandName].Execute(parameters, weapons, weaponFactory, inputOutputManager, gemFactory);
    }
        /// <summary>
        /// Creates a new simulator for a given program
        /// </summary>
        /// <param name="program">program to simulate</param>
        /// <param name="ioManager">io manager to handle io requests</param>
        /// <exception cref="SimulationException">A program with no instructions is passed</exception>
        public ProgramSimulator(Program program, IInputOutputManager ioManager)
        {
            // Program must have some instructions
            if (program.Instructions.Count == 0)
                throw new SimulationException("Program must have some instructions");

            // Setup default values for properties
            this.Program = program;
            this.IoManager = ioManager;
            this.Registers = new byte[program.Processor.RegisterCount];
            this.ScratchpadRam = new byte[program.Processor.ScratchpadSize];
            this.CallStack = new SimulationStack(program.Processor.StackSize);

            // Register banks?
            int regsCount = program.Processor.RegisterCount;

            if ((program.Processor.Flags & ProcessorFlags.HasAlternateBank) != 0)
                regsCount *= 2;

            this.Registers = new byte[regsCount];

            // Setup simulation visitor
            this.myVisitor = new Visitor(this);
        }
 /// <summary>
 /// Creates a new port translation structure
 /// </summary>
 /// <param name="ioManager">destination io manager</param>
 /// <param name="port">port to map to</param>
 public PortTranslation(IInputOutputManager ioManager, byte port)
 {
     this.IoManager = ioManager;
     this.Port = port;
 }
Beispiel #12
0
 public UserDialogManager(IInputOutputManager inputOutputManager)
 {
     _inputOutputManager = inputOutputManager ?? throw new ArgumentNullException(nameof(inputOutputManager));
 }
 public Engine(IInputOutputManager inputOutputManager, IInterpreter commandInterpreter)
 {
     this.inputOutputManager = inputOutputManager;
     this.commandInterpreter = commandInterpreter;
 }
Beispiel #14
0
 public Engine(IInputOutputManager inputOutputManager, IManagementSystem managementSystem)
 {
     this.inputOutputManager = inputOutputManager;
     this.managementSystem   = managementSystem;
 }
 public Engine(IInputOutputManager inputOutputManager, IParser parser)
 {
     this.inputOutputManager = inputOutputManager;
     this.parser             = parser;
 }
Beispiel #16
0
    public void Execute(string[] commandParameters, IDictionary <string, IWeapon> weapons, IWeaponFactory weaponFactory, IInputOutputManager inputOutputManager, IGemFactory gemFactory)
    {
        string targetAxeName = commandParameters[0];
        int    socketIndex   = int.Parse(commandParameters[1]);

        string[] tokens  = commandParameters[2].Split(' ');
        string   clarity = tokens[0];
        string   type    = tokens[1];
        IGem     gem     = gemFactory.CreateGem(type, clarity);

        IWeapon targetAxe = weapons[targetAxeName];

        targetAxe.AddGem(gem, socketIndex);
    }