コード例 #1
0
        public void Execute(IGameEngine gameEngine, IKeyInfo keyInfo)
        {
            gameEngine.PushStatus("Drop Which Item?");
            var key = KeyInfo.GetInput();

            var slotId = (int)key.Key - (int)ConsoleKey.A;

            if (slotId < 0 || slotId >= gameEngine.Player.Inventory.BackPack.Size)
            {
                gameEngine.PushStatus("Invalid Item.");
                return;
            }

            var slot = gameEngine.Player.Inventory.BackPack[slotId];

            if (slot.IsEmpty)
            {
                gameEngine.PushStatus("Nothing to drop.");
                return;
            }

            var item = slot.Item;

            slot.ClearItem();
            item.Position = gameEngine.Player.Position;
            gameEngine.AddItem(item);
        }
コード例 #2
0
ファイル: GameEngine.cs プロジェクト: CloneDeath/ArmeniRpg
        public virtual void Run(IConsoleWindow window)
        {
            _statusList.Enqueue("Press ? for Help.");

            IsRunning = true;

            new SpawnEnemiesCommand().Execute(this);
            new SpawnItemsCommand().Execute(this);

            while (IsRunning)
            {
                Console.CursorVisible = false;

                var mapWidth  = window.Area.Width * 2 / 3;
                var mapHeight = window.Area.Height - 1;

                var mapArea = window.CreateConsoleArea(new Area(new Position(0, 1), new Size(mapWidth, mapHeight)));
                mapArea.Clear();
                _renderer.Render(this, mapArea);

                var playerArea = window.CreateConsoleArea(new Area(
                                                              new Position(mapWidth, 1),
                                                              new Size(window.Area.Width - mapWidth, mapHeight)));
                playerArea.Clear();
                _playerRenderer.Render(this, playerArea);


                var statusArea = window.CreateConsoleArea(new Area(Position.Zero, new Size(window.Area.Width, 1)));
                statusArea.Clear();
                while (_statusList.Any())
                {
                    statusArea.Clear();
                    var status = _statusList.Dequeue();
                    if (_statusList.Any())
                    {
                        status += " <more>";
                    }
                    statusArea.Write(Position.Zero, status);
                    window.Render();
                    if (_statusList.Any())
                    {
                        KeyInfo.GetInput();
                    }
                }

                window.Render();

                _commandFactory.Execute(this, KeyInfo.GetInput());

                if (_characters.Count != 0)
                {
                    continue;
                }

                IsRunning = false;
                window.Clear();
                window.Write(Position.Zero, "All your enemies are dead. Congratulations!");
                window.Write(new Position(0, 1), "You are the only one left on earth.");
                window.Render();
            }
        }