コード例 #1
0
ファイル: TargetDialog.cs プロジェクト: scossgrove/RougeTiler
        public void DrawVisibleItems(BufferContainer buffer, Appearence[,] source, VectorBase heroPosition)
        {
            var viewPortMatrix = GetMatrixViewPort(source, heroPosition);

            var matrixWidth  = viewPortMatrix.GetUpperBound(0) + 1;
            var matrixHeight = viewPortMatrix.GetUpperBound(1) + 1;

            for (var rowIndex = 0; rowIndex < matrixHeight; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < matrixWidth; columnIndex++)
                {
                    var currentTile = viewPortMatrix[columnIndex, rowIndex].Clone();

                    if (!currentTile.IsExplored || currentTile.IsInShadow || currentTile.IsHidden)
                    {
                        buffer.Write($" ", columnIndex, rowIndex, ConsoleColor.DarkRed);
                    }
                    else
                    {
                        var foreGroundColour = currentTile.ForeGroundColor == null ? ConsoleColor.White : ColourUtilities.ConvertToConsoleColor(currentTile.ForeGroundColor);
                        var backGroundColour = currentTile.BackGroundColor == null ? ConsoleColor.Black : ColourUtilities.ConvertToConsoleColor(currentTile.BackGroundColor);

                        buffer.Write(currentTile.Glyph, columnIndex, rowIndex, foreGroundColour, backGroundColour);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///     This is to handle the writing of a message to the buffer.
        ///     Need to remember to add padding
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="message"></param>
        /// <param name="foregroundColor"></param>
        /// <param name="backgroundColor"></param>
        public void WriteAt(BufferContainer buffer, int x, int y, string message, ConsoleColor foregroundColor = ConsoleColor.White, ConsoleColor backgroundColor = ConsoleColor.Black, bool ignorePadding = false)
        {
            if (message == null)
            {
                return;
            }

            // Drawing Logic
            // 1. Add padding to position
            // 2. Truncate the message. (AUTO)
            var transformedX = x;
            var transformedY = y;

            if (!ignorePadding)
            {
                transformedX = x + Padding_Left;
                transformedY = y + Padding_Top;

                if (message.Length > MaxWidth)
                {
                    message = message.Substring(0, MaxWidth - 3) + "...";
                }
            }
            else
            {
                if (message.Length > Width)
                {
                    message = message.Substring(0, Width - 3) + "...";
                }
            }

            buffer.Write($"{message}", transformedX, transformedY, foregroundColor, backgroundColor);
        }
コード例 #3
0
        public override void Draw(BufferContainer buffer)
        {
            buffer.Write("What name shall the bards use to sing of", Left + 0, Top + 1);
            buffer.Write("your hero's adventures?", 0, Top + 2);

            if (string.IsNullOrWhiteSpace(PlayerName))
            {
                buffer.Write(DefaultName, Left + 0, Top + 4, ConsoleColor.Black, ConsoleColor.Yellow);
                buffer.Write(string.Empty.PadRight(Right - Left - 2 - DefaultName.Length, ' '), Left + 0, Top + 4 + DefaultName.Length, ConsoleColor.White, ConsoleColor.Black);
            }
            else
            {
                buffer.Write(string.Empty.PadRight(Right - Left - 2, ' '), Left + 0, Top + 4);
                buffer.Write(PlayerName, Left + 0, Top + 4);
                buffer.Write(" ", Left + 0 + PlayerName.Length, Top + 4, ConsoleColor.Black, ConsoleColor.Yellow);
            }

            buffer.Write("[A-Z] Enter name, [Del] Delete letter", Left + 0, Top + 6, ConsoleColor.Gray);
            buffer.Write("[Tab] Generate Random Name", Left + 0, Top + 7, ConsoleColor.Gray);
            buffer.Write("[Enter] Create hero, [Esc] Cancel", Left + 0, Top + 8, ConsoleColor.Gray);
        }
コード例 #4
0
        public override void Draw(BufferContainer buffer)
        {
            for (var y = 0; y < chars.Count; y++)
            {
                for (var x = 0; x < chars[y].Length; x++)
                {
                    var charColor = charColors[y][x];
                    var color     = colors[charColor.ToString()];
                    buffer.Write(chars[y][x].ToString(), Left + x + 4, Top + y + 1, color);
                }
            }


            NumberOfHeroes = Storage.Heroes.Count;

            buffer.Write("Which hero shall you play?", Left + 0, Top + 18);
            buffer.Write("[L] Select a hero, [↕] Change selection, [N] Create a new hero, [D] Delete hero", Left + 0, Top + 18 + NumberOfHeroes + 3, ConsoleColor.Gray);

            if (NumberOfHeroes == 0)
            {
                buffer.Write("(No heroes. Please create a new one.)", Left + 0, Top + 20, ConsoleColor.Gray);
            }

            for (var i = 0; i < Storage.Heroes.Count; i++)
            {
                var hero = Storage.Heroes[i];

                var fore          = ConsoleColor.White;
                var secondaryFore = ConsoleColor.Gray;
                var back          = ConsoleColor.Black;

                if (i == SelectedHeroIndex)
                {
                    fore          = ConsoleColor.Black;
                    secondaryFore = ConsoleColor.White;
                    back          = ConsoleColor.Yellow;
                }

                buffer.Write(hero.Name, Left + 6, Top + 20 + i, fore, back);
                buffer.Write($"Level {hero.Level}", Left + 25, Top + 20 + i, secondaryFore);
                buffer.Write(hero.HeroClass.Name, Left + 35, Top + 20 + i, secondaryFore);
            }
        }
コード例 #5
0
 public override void Draw(BufferContainer buffer)
 {
     buffer.Write("Oh well, death comes to all of us!", Left + 0, Top + 1);
 }
コード例 #6
0
        public override void Draw(BufferContainer buffer)
        {
            var debugger = Debugger.Instance;

            var startOfGetMatrixViewPort = DateTime.Now;
            var viewPortMatrix           = GetMatrixViewPort();
            var endOfGetMatrixViewPort   = DateTime.Now;

            var matrixWidth  = viewPortMatrix.GetUpperBound(0) + 1;
            var matrixHeight = viewPortMatrix.GetUpperBound(1) + 1;

            // TODO: view port tranformation...
            // 1. the top two row for the ruler
            // 2. the left three rows for the ruler
            // 3. the rest of the matrix cut down.

            var startOfDrawingMatrixViewPort = DateTime.Now;

            for (var rowIndex = 0; rowIndex < matrixHeight; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < matrixWidth; columnIndex++)
                {
                    var currentTile = viewPortMatrix[columnIndex, rowIndex];

                    if (Option.ShowAll)
                    {
                        var foreGroundColour = currentTile.ForeGroundColor == null ? ConsoleColor.White : ColourUtilities.ConvertToConsoleColor(currentTile.ForeGroundColor);
                        var backGroundColour = currentTile.BackGroundColor == null ? ConsoleColor.Black : ColourUtilities.ConvertToConsoleColor(currentTile.BackGroundColor);
                        buffer.Write(currentTile.Glyph, Left + columnIndex, Top + rowIndex, foreGroundColour, backGroundColour);
                    }
                    else
                    {
                        if (!currentTile.IsExplored)
                        {
                            buffer.Write($".", Left + columnIndex, Top + rowIndex, ConsoleColor.DarkRed);
                        }
                        else if (currentTile.IsInShadow)
                        {
                            buffer.Write(currentTile.Glyph, Left + columnIndex, Top + rowIndex, ConsoleColor.DarkGray);
                        }
                        else if (currentTile.IsHidden)
                        {
                            buffer.Write($".", Left + columnIndex, Top + rowIndex, ConsoleColor.DarkGreen);
                        }
                        else
                        {
                            var foreGroundColour = currentTile.ForeGroundColor == null ? ConsoleColor.White : ColourUtilities.ConvertToConsoleColor(currentTile.ForeGroundColor);
                            var backGroundColour = currentTile.BackGroundColor == null ? ConsoleColor.Black : ColourUtilities.ConvertToConsoleColor(currentTile.BackGroundColor);
                            buffer.Write(currentTile.Glyph, Left + columnIndex, Top + rowIndex, foreGroundColour, backGroundColour);
                        }
                    }
                }
            }

            // Stage Statistics
            var currentLine = 0;

            buffer.Write($"Number of Unexplored: {GameState.Instance.Game.CurrentStage.numberAlreadyExplored} [{GameState.Instance.Game.CurrentStage.percentageAlreadyExplored}%].", Left, Top + matrixHeight + currentLine++);
            buffer.Write($"Current Level: {GameState.Instance.Game.CurrentStage.StageNumber}.", Left, Top + matrixHeight + currentLine++);

            var endOfDrawingMatrixViewPort = DateTime.Now;


            var timeTakenToGettingMatrixViewPort = endOfGetMatrixViewPort - startOfGetMatrixViewPort;
            var timeTakenToDrawingMatrixViewPort = endOfDrawingMatrixViewPort - startOfDrawingMatrixViewPort;

            debugger.LogToDisk($"  $ Time for getting viewport: {timeTakenToGettingMatrixViewPort.TotalMilliseconds}", LogLevel.Debug);
            debugger.LogToDisk($"  $ Time for drawing: {timeTakenToDrawingMatrixViewPort.TotalMilliseconds}", LogLevel.Debug);
        }
コード例 #7
0
        public override void Draw(BufferContainer buffer)
        {
            var lineOffset = 0;

            if (!string.IsNullOrWhiteSpace(Title))
            {
                buffer.Write(Title + ":", Left, lineOffset + Top, ConsoleColor.DarkYellow, BackgroundColor);
                lineOffset++;
            }

            // Stuff for all writting
            var prefixLength = 0;

            if (!string.IsNullOrWhiteSpace(LinePrefix))
            {
                prefixLength = LinePrefix.Length;
            }

            foreach (var line in Lines)
            {
                var workingLine = line.Trim();

                if (prefixLength > 0)
                {
                    buffer.Write(LinePrefix, Left, lineOffset + Top, ForegroundColor, BackgroundColor);
                }

                if (MaxWidth >= workingLine.Length + prefixLength)
                {
                    buffer.Write(workingLine, Left + prefixLength, lineOffset + Top, ForegroundColor, BackgroundColor);
                }
                else
                {
                    if (CanWrap)
                    {
                        var maxWrappedLineLength = MaxWidth - prefixLength;
                        var numerOfLoops         = workingLine.Length / maxWrappedLineLength;
                        for (var lineLooper = 0; lineLooper <= numerOfLoops; lineLooper++)
                        {
                            var start = lineLooper * maxWrappedLineLength;
                            var end   = start + maxWrappedLineLength;

                            var output = string.Empty;
                            if (end > workingLine.Length)
                            {
                                output = line.Substring(start);
                            }
                            else
                            {
                                output = workingLine.Substring(start, end - start);
                            }
                            output = output.Trim().PadRight(maxWrappedLineLength, ' ');

                            buffer.Write(output, Left + prefixLength, lineOffset + Top, ForegroundColor, BackgroundColor);

                            lineOffset++;
                        }
                        lineOffset--; // WriteAt(prefixLength, lineOffset, line, ForegroundColor, BackgroundColor);
                    }
                    else
                    {
                        // This will cause truncation and elispes being inserted.
                        buffer.Write(workingLine, Left + prefixLength, lineOffset + Top, ForegroundColor, BackgroundColor);
                    }
                }

                lineOffset++;
            }
        }
コード例 #8
0
 public override void Draw(BufferContainer buffer)
 {
     buffer.Write("Congratulations, You won the game!", Left + 0, Top + 1);
 }