Beispiel #1
0
        private IRace GetPlayerRace(IConsoleWindow console)
        {
            Console.Clear();
            console.Clear();
            console.Write(Position.Zero, ConsoleColor.Green, "Choose A Race: ");
            for (var i = 0; i < AvailableRaces.Count; i++)
            {
                var currentRace = AvailableRaces[i];
                console.Write(new Position(0, i + 1), $"{i + 1}: " +
                              $"{currentRace.Name} - " +
                              $"(Health: {currentRace.Health}, Damage: {currentRace.Damage})");
            }

            while (true)
            {
                console.Render();
                var raceNumber = ConsoleInputReader.ReadKey();

                if (int.TryParse(raceNumber.KeyChar.ToString(), out int index) && index >= 1 && index <= AvailableRaces.Count)
                {
                    return(AvailableRaces[index - 1]);
                }

                console.Write(new Position(0, AvailableRaces.Count + 1), "Please enter a valid race number.");
            }
        }
Beispiel #2
0
 protected virtual string GetPlayerName(IConsoleWindow console)
 {
     console.Write(Position.Zero, ConsoleColor.Green, "Enter Player's Name: ");
     console.Render();
     Console.ForegroundColor = ConsoleColor.White;
     return(ConsoleInputReader.ReadLine());
 }
Beispiel #3
0
        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();
            }
        }