Пример #1
0
        public bool TryAddItem(HackerPacketQueueItemType type, HackerPacketQueueItemColour colour)
        {
            if (_items.Count >= MAX_QUEUE_SIZE)
            {
                return(false);
            }

            int halfSize = _items.Count / 2;

            _items.Insert(halfSize, new HackerPacketQueueItem()
            {
                Type = type, Colour = colour
            });

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Called once per frame.
        /// </summary>
        void Update()
        {
            bool tryAddItem = false;
            HackerPacketQueueItemColour colour = HackerPacketQueueItemColour.Red;
            HackerPacketQueueItemType   type   = HackerPacketQueueItemType.Type1;

            if (Input.GetKeyDown(KeyCode.Keypad1) || Input.GetKeyDown(KeyCode.Alpha1))
            {
                tryAddItem = true;
                colour     = HackerPacketQueueItemColour.Red;
                type       = HackerPacketQueueItemType.Type1;
            }
            else if (Input.GetKeyDown(KeyCode.Keypad2) || Input.GetKeyDown(KeyCode.Alpha2))
            {
                tryAddItem = true;
                colour     = HackerPacketQueueItemColour.Blue;
                type       = HackerPacketQueueItemType.Type2;
            }
            else if (Input.GetKeyDown(KeyCode.Keypad3) || Input.GetKeyDown(KeyCode.Alpha3))
            {
                tryAddItem = true;
                colour     = HackerPacketQueueItemColour.Green;
                type       = HackerPacketQueueItemType.Type3;
            }

            if (tryAddItem)
            {
                if (_queue.TryAddItem(type, colour))
                {
                    _commandLineConsole.AddText($"inject-packet {colour.ToString()}");
                }
                else
                {
                    _commandLineConsole.AddText($"inject-packet {colour.ToString()}", "SYSTEM ERROR, PACKET REJECTED", string.Empty);
                }
            }
        }