public BufferedConsoleOutput(int width, int height, IConsoleOutput consoleOutput)
 {
     _height = height;
     _consoleOutput = consoleOutput;
     _backBuffer = new ConsoleBuffer(width, height, _consoleOutput.DefaultForegroundColor, _consoleOutput.DefaultBackgroundColor);
     _frontBuffer = new ConsoleBuffer(width, height, _consoleOutput.DefaultForegroundColor, _consoleOutput.DefaultBackgroundColor);
 }
Beispiel #2
0
 public override void Render (ConsoleBuffer buffer)
 {
     base.Render(buffer);
     if (Orientation == Orientation.Vertical)
         buffer.DrawVerticalLine(0, 0, RenderSize.Height, EffectiveColor, Stroke);
     else
         buffer.DrawHorizontalLine(0, 0, RenderSize.Width, EffectiveColor, Stroke);
 }
Beispiel #3
0
 public override void Render (ConsoleBuffer buffer)
 {
     if (Source == null)
         return;
     if (Background != null)
         buffer.FillBackgroundRectangle(new Rect(RenderSize), Background.Value);
     buffer.DrawImage(Source, new Rect(RenderSize));
 }
Beispiel #4
0
        public void Chars_out_of_range_should_have_the_default_value_if_requested()
        {
            var cb = new ConsoleBuffer(4, 4, ConsoleColor.White, ConsoleColor.Black);

            var ch = cb.Get(100, 100, false);
            Assert.AreEqual(' ', ch.Char);
            Assert.AreEqual(ConsoleColor.White, ch.ForegroundColor);
            Assert.AreEqual(ConsoleColor.Black, ch.BackgroundColor);
        }
Beispiel #5
0
		public static void SetupConsole()
		{
			if (ConsoleBuffer == null)
			{
				ConsoleBuffer = new ConsoleBuffer();

				RC.App = ConsoleBuffer;
			}
		}
        public void Create ()
        {
            var buffer = new ConsoleBuffer(42);

            buffer.LineCharRenderer.Should().BeSameAs(LineCharRenderer.Box);
            buffer.Width.Should().Be(42);
            buffer.Height.Should().Be(0);
            buffer.Clip.Should().Be(new Rect(0, 0, 42, Size.Infinity));
        }
Beispiel #7
0
		public static void ShutdownConsole()
		{
			if (ConsoleBuffer != null)
			{
				ConsoleBuffer = null; 

				RC.App = RC.Sys; 
			}
		}
Beispiel #8
0
        public void A_set_value_should_be_correctly_retrievable()
        {
            var cb = new ConsoleBuffer(4, 4, ConsoleColor.White, ConsoleColor.Black);

            cb.Set(1, 1, '!', ConsoleColor.Blue, ConsoleColor.DarkCyan);

            var ch = cb.Get(1, 1, false);
            Assert.AreEqual('!', ch.Char);
            Assert.AreEqual(ConsoleColor.Blue, ch.ForegroundColor);
            Assert.AreEqual(ConsoleColor.DarkCyan, ch.BackgroundColor);
        }
Beispiel #9
0
        public void Clear_should_reset_all_chars_to_default_value()
        {
            var cb = new ConsoleBuffer(4, 4, ConsoleColor.White, ConsoleColor.Black);
            cb.Clear();

            for (int y=0;y<4;y++)
                for (int x = 0; x < 4; x++)
                {
                    var ch = cb.Get(x, y);
                    Assert.AreEqual(' ', ch.Char);
                    Assert.AreEqual(ConsoleColor.White, ch.ForegroundColor);
                    Assert.AreEqual(ConsoleColor.Black, ch.BackgroundColor);
                }
        }
        public void DrawLine ()
        {
            var buffer = new ConsoleBuffer(3);

            buffer.DrawLine(Line.Vertical(1, 0, 3), Red);
            buffer.DrawLine(Line.Horizontal(0, 1, 3), Green, LineWidth.Wide);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Red };
            var cg = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.HorizontalWide, ForegroundColor = Green };
            var cx = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.HorizontalWide | LineChar.Vertical, ForegroundColor = Green };

            buffer.GetLine(0).Should().Equal(c0, cr, c0);
            buffer.GetLine(1).Should().Equal(cg, cx, cg);
            buffer.GetLine(2).Should().Equal(c0, cr, c0);
        }
        public void InvalidArguments ()
        {
            var buffer = new ConsoleBuffer(42);
            IList<ConsoleColor> colorMap = ColorMaps.Dark;
            IList<ConsoleColor> colorMapInvalid = new ConsoleColor[15];
            ApplyColorMapCallback processChar = (ref ConsoleChar c) => { };

            new Action(() => buffer.LineCharRenderer = null).ShouldThrow<ArgumentNullException>()
                .Which.ParamName.Should().Be("value");
            new Action(() => buffer.ApplyColorMap(new Rect(), null, processChar)).ShouldThrow<ArgumentNullException>()
                .Which.ParamName.Should().Be(nameof(colorMap));
            new Action(() => buffer.ApplyColorMap(new Rect(), colorMapInvalid, processChar)).ShouldThrow<ArgumentException>()
                .Which.ParamName.Should().Be(nameof(colorMap));
            new Action(() => buffer.ApplyColorMap(new Rect(), colorMap, null)).ShouldThrow<ArgumentNullException>()
                .Which.ParamName.Should().Be(nameof(processChar));
        }
        public void DrawHorizontalLine ()
        {
            var buffer = new ConsoleBuffer(5);

            buffer.DrawHorizontalLine(0, 0, 5, Red);
            buffer.DrawHorizontalLine(1, 1, 3, Green);
            buffer.DrawHorizontalLine(-1, 3, 10, Blue, LineWidth.Wide);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar { LineChar = LineChar.Horizontal, ForegroundColor = Red };
            var cg = new ConsoleChar { LineChar = LineChar.Horizontal, ForegroundColor = Green };
            var cb = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.HorizontalWide, ForegroundColor = Blue };

            buffer.GetLine(0).Should().Equal(cr, cr, cr, cr, cr);
            buffer.GetLine(1).Should().Equal(c0, cg, cg, cg, c0);
            buffer.GetLine(2).Should().Equal(c0, c0, c0, c0, c0);
            buffer.GetLine(3).Should().Equal(cb, cb, cb, cb, cb);
        }
        public void BoxLineCharRendererBox2x2Wide()
        {
            var buffer = new ConsoleBuffer(5)
            {
                LineCharRenderer = LineCharRenderer.Box
            };

            buffer.DrawHorizontalLine(0, 0, 5, null, LineWidth.Wide);
            buffer.DrawHorizontalLine(0, 2, 5, null, LineWidth.Wide);
            buffer.DrawHorizontalLine(0, 4, 5, null, LineWidth.Wide);
            buffer.DrawVerticalLine(0, 0, 5, null, LineWidth.Wide);
            buffer.DrawVerticalLine(2, 0, 5, null, LineWidth.Wide);
            buffer.DrawVerticalLine(4, 0, 5, null, LineWidth.Wide);

            GetRenderedText(buffer).Should().BeLines(
                "╔═╦═╗",
                "║ ║ ║",
                "╠═╬═╣",
                "║ ║ ║",
                "╚═╩═╝");
        }
        public void BoxLineCharRendererPixels()
        {
            var buffer = new ConsoleBuffer(3)
            {
                LineCharRenderer = LineCharRenderer.Box
            };

            buffer.DrawHorizontalLine(0, 0, 1);
            buffer.DrawHorizontalLine(2, 0, 1);
            buffer.DrawHorizontalLine(0, 2, 1, null, LineWidth.Wide);
            buffer.DrawHorizontalLine(2, 2, 1, null, LineWidth.Wide);
            buffer.DrawVerticalLine(0, 0, 1);
            buffer.DrawVerticalLine(2, 0, 1, null, LineWidth.Wide);
            buffer.DrawVerticalLine(0, 2, 1);
            buffer.DrawVerticalLine(2, 2, 1, null, LineWidth.Wide);

            GetRenderedText(buffer).Should().BeLines(
                "┼ ╫",
                "   ",
                "╪ ╬");
        }
        public void BoxLineCharRendererBox2x2MixedAlt()
        {
            var buffer = new ConsoleBuffer(5)
            {
                LineCharRenderer = LineCharRenderer.Box
            };

            buffer.DrawHorizontalLine(0, 0, 5);
            buffer.DrawHorizontalLine(0, 2, 5, null, LineWidth.Wide);
            buffer.DrawHorizontalLine(0, 4, 5);
            buffer.DrawVerticalLine(0, 0, 5, null, LineWidth.Wide);
            buffer.DrawVerticalLine(2, 0, 5);
            buffer.DrawVerticalLine(4, 0, 5, null, LineWidth.Wide);

            GetRenderedText(buffer).Should().BeLines(
                "╓─┬─╖",
                "║ │ ║",
                "╠═╪═╣",
                "║ │ ║",
                "╙─┴─╜");
        }
        public void BoxLineCharRendererBox2x2Mixed()
        {
            var buffer = new ConsoleBuffer(5)
            {
                LineCharRenderer = LineCharRenderer.Box
            };

            buffer.DrawHorizontalLine(0, 0, 5, null, LineWidth.Wide);
            buffer.DrawHorizontalLine(0, 2, 5);
            buffer.DrawHorizontalLine(0, 4, 5, null, LineWidth.Wide);
            buffer.DrawVerticalLine(0, 0, 5);
            buffer.DrawVerticalLine(2, 0, 5, null, LineWidth.Wide);
            buffer.DrawVerticalLine(4, 0, 5);

            GetRenderedText(buffer).Should().BeLines(
                "╒═╦═╕",
                "│ ║ │",
                "├─╫─┤",
                "│ ║ │",
                "╘═╩═╛");
        }
Beispiel #17
0
        public static bool UseKey()
        {
            Player pl = Program.ObteJuego().pl;

            ConsoleBuffer.ObteBuffer().InsertText("La habitación esta cerrada con llave");
            ConsoleBuffer.ObteBuffer().InsertText("¿Que objeto quieres usar para abrir la habitación?");
            pl.ListOfItems();
            ConsoleBuffer.ObteBuffer().PrintText(ConsoleBuffer.ObteBuffer().height - 3);
            ConsoleBuffer.ObteBuffer().PrintBackground();
            ConsoleBuffer.ObteBuffer().Print(1, ConsoleBuffer.ObteBuffer().height - 2, ">");
            ConsoleBuffer.ObteBuffer().SmallMap();
            ConsoleBuffer.ObteBuffer().PrintScreen();
            Console.SetCursorPosition(2, ConsoleBuffer.ObteBuffer().height - 2);
            Item[] bag = pl.GetBag();
            bool   obj = int.TryParse(Console.ReadLine(), out int num);

            if (obj && pl.GetBag().Length > num && num >= 0 && bag[num] != null)
            {
                if (bag[num].GetName().Equals("Llave vieja"))
                {
                    ConsoleBuffer.ObteBuffer().InsertText("Has usado " + bag[num].GetName());
                    bag[num] = null;
                    Item.Ordenar(bag);
                    return(true);
                }
                else
                {
                    ConsoleBuffer.ObteBuffer().InsertText("No parece que " + bag[num].GetName() + " encaje");
                }
            }
            else if (obj)
            {
                ConsoleBuffer.ObteBuffer().InsertText("Ese numero no es válido");
            }
            else
            {
                ConsoleBuffer.ObteBuffer().InsertText("Tiene que ser un numero");
            }
            return(false);
        }
Beispiel #18
0
        private static void WriteBuffer(ConsoleBuffer buffer)
        {
            var buf  = new ConsoleNatives.CharInfo[buffer.Width * buffer.Height];
            var rect = new ConsoleNatives.SmallRect(0, 0, (short)buffer.Width, (short)buffer.Height);

            for (var y = 0; y < buffer.Height; y++)
            {
                for (var x = 0; x < buffer.Width; x++)
                {
                    if (!buffer[x, y].HasValue)
                    {
                        continue;
                    }

                    buf[x + y * buffer.Width].Char.UnicodeChar = buffer[x, y].Value.Value;
                    buf[x + y * buffer.Width].Attributes       = (short)((int)buffer[x, y].Value.ForegroundColor | ((int)buffer[x, y].Value.BackgroundColor << 4));
                }
            }

            ConsoleNatives.WriteConsoleOutput(ConsoleNatives.GetStdHandle(ConsoleNatives.STD_OUT_HANDLE), buf,
                                              new ConsoleNatives.Coord((short)buffer.Width, (short)buffer.Height), new ConsoleNatives.Coord(0, 0), ref rect);
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            Console.Title = "StdPaint Image Example";

            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "JPEG Image (*.jpg,*.jpeg)|*.jpg,*.jpeg|PNG Image (*.png)|*.png|GIF Image (*.gif)|*.gif|All files (*.*)|*.*";
            if (open.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Console.WriteLine("This program works best with a small, square font. Please change your settings, then press a key...");
            Console.ReadKey();

            image = ImageLoader.FromFile(open.FileName);

            Painter.Starting += Painter_Starting;
            Painter.Paint    += Painter_Paint;

            Painter.Run(64, 64, 30);
        }
        public void DrawLine()
        {
            var buffer = new ConsoleBuffer(3);

            buffer.DrawLine(Line.Vertical(1, 0, 3), Red, LineWidth.Single, DrawLineFlags.CapFull);
            buffer.DrawLine(Line.Horizontal(0, 1, 3), Green, LineWidth.Double, DrawLineFlags.CapFull);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar {
                LineChar = LineCharVertical, ForegroundColor = Red
            };
            var cg = new ConsoleChar {
                LineChar = LineCharHorizontalDouble, ForegroundColor = Green
            };
            var cx = new ConsoleChar {
                LineChar = LineCharHorizontalDoubleVertical, ForegroundColor = Green
            };

            buffer.GetLine(0).Should().Equal(c0, cr, c0);
            buffer.GetLine(1).Should().Equal(cg, cx, cg);
            buffer.GetLine(2).Should().Equal(c0, cr, c0);
        }
Beispiel #21
0
        public void DrawLine()
        {
            var buffer = new ConsoleBuffer(3);

            buffer.DrawLine(Line.Vertical(1, 0, 3), Red);
            buffer.DrawLine(Line.Horizontal(0, 1, 3), Green, LineWidth.Wide);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar {
                LineChar = LineChar.Vertical, ForegroundColor = Red
            };
            var cg = new ConsoleChar {
                LineChar = LineChar.Horizontal | LineChar.HorizontalWide, ForegroundColor = Green
            };
            var cx = new ConsoleChar {
                LineChar = LineChar.Horizontal | LineChar.HorizontalWide | LineChar.Vertical, ForegroundColor = Green
            };

            buffer.GetLine(0).Should().Equal(c0, cr, c0);
            buffer.GetLine(1).Should().Equal(cg, cx, cg);
            buffer.GetLine(2).Should().Equal(c0, cr, c0);
        }
Beispiel #22
0
        public void Show(GameServer server, GameClient client)
        {
            while (true)
            {
                arena = ArenaGenerator.Generate(server.GameAssets, seed, biome_count);
                UpdateItems();

                ConsoleBuffer mapbuf = arena.MapBuffer(tempView);
                buffer = new ConsoleBuffer();
                buffer.InsertBuffer(mapbuf, 0, 0);
                buffer.SetCursorPosition(mapbuf.Width, 0);
                buffer.WriteVertical("".PadRight(25, '▌'));

                buffer.SetCursorPosition(mapbuf.Width, 7);
                buffer.Write("█".PadRight(30, '─'));

                buffer.SetCursorPosition(mapbuf.Width + 1, 1);

                this.ReadMenu();

                if (Selected == proitems.Length - 1)
                {
                    return;
                }
                if (Selected == proitems.Length - 2)
                {
                    GameState gs = new GameState(arena, max_players, port, game_name);
                    server.Open(gs);

                    IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
                    new ConnectingMenu().Show(client, ep);

                    client.Close();
                    server.Close();
                    return;
                }
            }
        }
Beispiel #23
0
        public static bool PickItemFromRoom()
        {
            Player pl = Program.ObteJuego().pl;

            if (pl.currentRoom.RoomHasItem())
            {
                ConsoleBuffer.ObteBuffer().InsertText("¿Que objeto quieres coger?");
                Item[] tempRoomItems = pl.currentRoom.GetRoomItems();
                pl.currentRoom.ListOfItems();
                ConsoleBuffer.ObteBuffer().PrintBackground();
                ConsoleBuffer.ObteBuffer().PrintText(ConsoleBuffer.ObteBuffer().height - 3);
                ConsoleBuffer.ObteBuffer().Print(1, 0, "PRINCIPAL");
                ConsoleBuffer.ObteBuffer().Print(1, ConsoleBuffer.ObteBuffer().height - 2, ">");
                ConsoleBuffer.ObteBuffer().SmallMap();
                ConsoleBuffer.ObteBuffer().PrintScreen();
                Console.SetCursorPosition(2, ConsoleBuffer.ObteBuffer().height - 2);
                bool obj = int.TryParse(Console.ReadLine(), out int num);

                if (!obj)
                {
                    ConsoleBuffer.ObteBuffer().InsertText("Solo acepta numeros");
                    return(false);
                }

                if (num >= 0 && num <= tempRoomItems.Length - 1 && tempRoomItems[num] != null)
                {
                    pl.PickItem(num);
                    Item.Ordenar(tempRoomItems);
                    return(true);
                }
                else
                {
                    ConsoleBuffer.ObteBuffer().InsertText("Ese número no es válido");
                }
            }
            ConsoleBuffer.ObteBuffer().InsertText("No hay nada que coger");
            return(false);
        }
        public P_MainMenu(P_Render renderer, IP_UpdateManager updater)
        {
            _Render         = new TilerIsADummy.PrototypeMapGen.PrototypeComponents.P_MainMenuRenderComponent(this);
            _Render.Graphic = new char[_Render.SizeX * _Render.SizeY];
            ConsoleBuffer imbad = new ConsoleBuffer(_Render.SizeX, _Render.SizeY);

            imbad.BufferWritePosition((_Render.SizeX / 2) - (MenuHeading.Length / 2), (_Render.SizeY) / 2);
            imbad.BufferWrite(MenuHeading);
            imbad.BufferWritePosition(_Render.SizeX + 1, _Render.SizeY - 3);
            imbad.BufferWrite(PressFooConfirm);
            imbad.BufferWritePosition(_Render.SizeX + 1, _Render.SizeY - 2);
            imbad.BufferWrite(PressFooExit);
            imbad.BufferWritePosition(0, 0);
            //imbad.BufferWrite("Such is the secret core of your creed, the other half of your double standard: it is immoral to live by your own effort, but moral to live by the effort of others—it is immoral to consume your own product, but moral to consume the products of others—it is immoral to earn, but moral to mooch—it is the parasites who are the moral justification for the existence of the producers, but the existence of the parasites is an end in itself—it is evil to profit by achievement, but good to profit by sacrifice—it is evil to create your own happiness, but good to enjoy it at the price of the blood of others. Your code divides mankind into two castes and commands them to live by opposite rules: those who may desire anything and those who may desire nothing, the chosen and the demand, the riders and the carriers, the eaters and the eaten. What standard determines your caste? What passkey admits you to the moral elite? The passkey is lack of value. Whatever the value involved, it is your lack of it that gives you a claim upon those who don’t lack it. It is your need that gives you a claim to rewards. If you are able to satisfy your need, your ability annuls your right to satisfy it. But a need you are unable to satisfy gives you first right to the lives of mankind. If you succeed, any man who fails is your master; if you fail, any man who succeeds is your serf. Whether your failure is just or not, whether your wishes are rational or not, whether your misfortune is undeserved or the result of your vices, it is misfortune that gives you a right to rewards. It is pain, regardless of its nature or cause, pain as a primary absolute, that gives you a mortgage on all of existence.");
            _Render.Graphic = imbad.bufferarray;


            Renderer = renderer;
            Updater  = updater;

            this.AcceptP_Render(Renderer);
            this.AcceptUpdater(Updater);
        }
Beispiel #25
0
        /// <summary>
        /// Render options and return selected ones
        /// </summary>
        /// <returns></returns>
        private IEnumerable <int> RenderAndSelectOptions()
        {
            List <int> selected = new List <int>();
            var        startAt  = 0;
            var        row      = 0;

            Console.CursorVisible = false;
            ConsoleBuffer.MemoriseBufferPosition(BUFFER_NAME);

            bool exit = false;

            while (!exit || selected.Count == 0)
            {
                RenderOptions(selected, startAt, row);
                var key = Console.ReadKey();
                // Update params according to key press
                (exit, startAt, row, selected) =
                    ExecuteAction(key.Key, startAt, row, selected);
            }
            Console.CursorVisible = true;

            return(selected);
        }
Beispiel #26
0
        public static void Show(string title, ref string result, int width = 35)
        {
            ConsoleBuffer buf = new ConsoleBuffer(width, 5);

            buf.ForegroundColor = ConsoleColor.Yellow;

            // window borders
            buf.Write("/".PadRight(width - 1, '-') + "\\");
            buf.SetCursorPosition(0, buf.Height - 1);
            buf.Write("\\".PadRight(width - 1, '-') + "/");
            buf.SetCursorPosition(0, 1);
            buf.WriteVertical("|||");
            buf.SetCursorPosition(width - 1, 1);
            buf.WriteVertical("|||");

            // Title
            buf.SetCursorPosition(4, 0);
            buf.Write(" " + title + " ");

            // Textbox frame
            buf.SetCursorPosition(2, 2);
            buf.Write(">");

            int Xoffset = (80 - width) / 2;
            int Yoffset = 9;

            buf.DrawSelf(Xoffset, Yoffset);
            Console.SetCursorPosition(4 + Xoffset, 2 + Yoffset);
            bool vis = Console.CursorVisible;

            Console.ForegroundColor = buf.ForegroundColor;
            Console.BackgroundColor = buf.BackgroundColor;

            Console.CursorVisible = true;
            result = Console.ReadLine();
            Console.CursorVisible = vis;
        }
Beispiel #27
0
        public void ListOfItems()
        {
            string text = "    ";
            int    acc  = 0;

            for (int j = 0; j < item.Length; j++)
            {
                if (item[j] != null)
                {
                    string temp = "[" + j + "]->" + item[j].GetName();
                    if (text.Length + temp.Length > 100)
                    {
                        ConsoleBuffer.ObteBuffer().InsertText(text);
                        text = "    ";
                    }
                    text += temp + "  ";
                    acc++;
                }
            }
            if (!text.Equals("    "))
            {
                ConsoleBuffer.ObteBuffer().InsertText(text);
            }
        }
Beispiel #28
0
        public void DrawHorizontalLine()
        {
            var buffer = new ConsoleBuffer(5);

            buffer.DrawHorizontalLine(0, 0, 5, Red);
            buffer.DrawHorizontalLine(1, 1, 3, Green);
            buffer.DrawHorizontalLine(-1, 3, 10, Blue, LineWidth.Wide);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar {
                LineChar = LineChar.Horizontal, ForegroundColor = Red
            };
            var cg = new ConsoleChar {
                LineChar = LineChar.Horizontal, ForegroundColor = Green
            };
            var cb = new ConsoleChar {
                LineChar = LineChar.Horizontal | LineChar.HorizontalWide, ForegroundColor = Blue
            };

            buffer.GetLine(0).Should().Equal(cr, cr, cr, cr, cr);
            buffer.GetLine(1).Should().Equal(c0, cg, cg, cg, c0);
            buffer.GetLine(2).Should().Equal(c0, c0, c0, c0, c0);
            buffer.GetLine(3).Should().Equal(cb, cb, cb, cb, cb);
        }
        public void DrawHorizontalLineCapFull()
        {
            var buffer = new ConsoleBuffer(5);

            buffer.DrawHorizontalLine(0, 0, 5, Red, LineWidth.Single, DrawLineFlags.CapFull);
            buffer.DrawHorizontalLine(1, 1, 3, Green, LineWidth.Single, DrawLineFlags.CapFull);
            buffer.DrawHorizontalLine(-1, 3, 10, Blue, LineWidth.Double, DrawLineFlags.CapFull);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar {
                LineChar = LineCharHorizontal, ForegroundColor = Red
            };
            var cg = new ConsoleChar {
                LineChar = LineCharHorizontal, ForegroundColor = Green
            };
            var cb = new ConsoleChar {
                LineChar = LineCharHorizontalDouble, ForegroundColor = Blue
            };

            buffer.GetLine(0).Should().Equal(cr, cr, cr, cr, cr);
            buffer.GetLine(1).Should().Equal(c0, cg, cg, cg, c0);
            buffer.GetLine(2).Should().Equal(c0, c0, c0, c0, c0);
            buffer.GetLine(3).Should().Equal(cb, cb, cb, cb, cb);
        }
        public void FillForegroundHorizontalLine()
        {
            var buffer = new ConsoleBuffer(5);

            buffer.FillForegroundHorizontalLine(0, 0, 5, Red, '-');
            buffer.FillForegroundHorizontalLine(1, 1, 3, Green, '=');
            buffer.FillForegroundHorizontalLine(-1, 3, 10, Blue, '_');

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar {
                Char = '-', ForegroundColor = Red
            };
            var cg = new ConsoleChar {
                Char = '=', ForegroundColor = Green
            };
            var cb = new ConsoleChar {
                Char = '_', ForegroundColor = Blue
            };

            buffer.GetLine(0).Should().Equal(cr, cr, cr, cr, cr);
            buffer.GetLine(1).Should().Equal(c0, cg, cg, cg, c0);
            buffer.GetLine(2).Should().Equal(c0, c0, c0, c0, c0);
            buffer.GetLine(3).Should().Equal(cb, cb, cb, cb, cb);
        }
        public void FillBackgroundHorizontalLine()
        {
            var buffer = new ConsoleBuffer(5);

            buffer.FillBackgroundHorizontalLine(0, 0, 5, Red);
            buffer.FillBackgroundHorizontalLine(1, 1, 3, Green);
            buffer.FillBackgroundHorizontalLine(-1, 3, 10, Blue);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar {
                BackgroundColor = Red
            };
            var cg = new ConsoleChar {
                BackgroundColor = Green
            };
            var cb = new ConsoleChar {
                BackgroundColor = Blue
            };

            buffer.GetLine(0).Should().Equal(cr, cr, cr, cr, cr);
            buffer.GetLine(1).Should().Equal(c0, cg, cg, cg, c0);
            buffer.GetLine(2).Should().Equal(c0, c0, c0, c0, c0);
            buffer.GetLine(3).Should().Equal(cb, cb, cb, cb, cb);
        }
        public void DrawRectangleSimple ()
        {
            var buffer = new ConsoleBuffer(3);

            buffer.DrawRectangle(new Rect(0, 0, 3, 3), Red, LineWidth.Single);

            var c0 = new ConsoleChar();
            var cx = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.Vertical, ForegroundColor = Red };
            var ch = new ConsoleChar { LineChar = LineChar.Horizontal, ForegroundColor = Red };
            var cv = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Red };

            buffer.GetLine(0).Should().Equal(cx, ch, cx);
            buffer.GetLine(1).Should().Equal(cv, c0, cv);
            buffer.GetLine(2).Should().Equal(cx, ch, cx);
        }
        public void FillForegroundHorizontalLine ()
        {
            var buffer = new ConsoleBuffer(5);

            buffer.FillForegroundHorizontalLine(0, 0, 5, Red, '-');
            buffer.FillForegroundHorizontalLine(1, 1, 3, Green, '=');
            buffer.FillForegroundHorizontalLine(-1, 3, 10, Blue, '_');

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar { Char = '-', ForegroundColor = Red };
            var cg = new ConsoleChar { Char = '=', ForegroundColor = Green };
            var cb = new ConsoleChar { Char = '_', ForegroundColor = Blue };

            buffer.GetLine(0).Should().Equal(cr, cr, cr, cr, cr);
            buffer.GetLine(1).Should().Equal(c0, cg, cg, cg, c0);
            buffer.GetLine(2).Should().Equal(c0, c0, c0, c0, c0);
            buffer.GetLine(3).Should().Equal(cb, cb, cb, cb, cb);
        }
        public void FillForegroundVerticalLine ()
        {
            var buffer = new ConsoleBuffer(4);

            buffer.FillForegroundVerticalLine(0, 0, 5, Red, '|');
            buffer.FillForegroundVerticalLine(1, 1, 3, Green, ':');
            buffer.FillForegroundVerticalLine(3, -1, 10, Blue, '*');

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar { Char = '|', ForegroundColor = Red };
            var cg = new ConsoleChar { Char = ':', ForegroundColor = Green };
            var cb = new ConsoleChar { Char = '*', ForegroundColor = Blue };

            buffer.GetLine(0).Should().Equal(cr, c0, c0, cb);
            buffer.GetLine(1).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(2).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(3).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(4).Should().Equal(cr, c0, c0, cb);
        }
        public void FillBackgroundVerticalLine ()
        {
            var buffer = new ConsoleBuffer(4);

            buffer.FillBackgroundVerticalLine(0, 0, 5, Red);
            buffer.FillBackgroundVerticalLine(1, 1, 3, Green);
            buffer.FillBackgroundVerticalLine(3, -1, 10, Blue);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar { BackgroundColor = Red };
            var cg = new ConsoleChar { BackgroundColor = Green };
            var cb = new ConsoleChar { BackgroundColor = Blue };

            buffer.GetLine(0).Should().Equal(cr, c0, c0, cb);
            buffer.GetLine(1).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(2).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(3).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(4).Should().Equal(cr, c0, c0, cb);
        }
 public override void Render (ConsoleBuffer buffer)
 {
     buffer.FillForegroundRectangle(new Rect(RenderSize), null, Char);
 }
Beispiel #37
0
 protected override void RenderOverride(ConsoleBuffer buffer)
 {
     base.RenderOverride(buffer);
     buffer.FillForegroundRectangle(new Rect(RenderSize), null, Char);
 }
        public void FillBackgroundLine ()
        {
            var buffer = new ConsoleBuffer(3);

            buffer.FillBackgroundLine(Line.Vertical(1, 0, 3), Red);
            buffer.FillBackgroundLine(Line.Horizontal(0, 1, 3), Green);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar { BackgroundColor = Red };
            var cg = new ConsoleChar { BackgroundColor = Green };

            buffer.GetLine(0).Should().Equal(c0, cr, c0);
            buffer.GetLine(1).Should().Equal(cg, cg, cg);
            buffer.GetLine(2).Should().Equal(c0, cr, c0);
        }
Beispiel #39
0
        public static bool LookAtBag()
        {
            Item[] bag = Program.ObteJuego().pl.GetBag();
            for (int i = 0; i < bag.Length; i++)
            {
                int ii = i;
                int x  = 0;
                if (ii >= 5)
                {
                    ii -= 5;
                    x   = 1;
                }
                if (bag[i] != null)
                {
                    if (bag[i].GetType().BaseType == typeof(ItemEquipable))
                    {
                        ItemEquipable equipo = (ItemEquipable)bag[i];
                        ConsoleBuffer.ObteBuffer().Print(1 + 50 * x, 2 + ii * 3, equipo.GetName());
                        string texto = "";
                        if (equipo.ModifierHp() < 0)
                        {
                            texto += "HP(" + equipo.ModifierHp() + ") ";
                        }
                        else
                        {
                            texto += "HP(+" + equipo.ModifierHp() + ") ";
                        }

                        if (equipo.ModifierAtt() < 0)
                        {
                            texto += "ATT(" + equipo.ModifierAtt() + ") ";
                        }
                        else
                        {
                            texto += "ATT(+" + equipo.ModifierAtt() + ") ";
                        }

                        if (equipo.ModifierDef() < 0)
                        {
                            texto += "DEF(" + equipo.ModifierDef() + ") ";
                        }
                        else
                        {
                            texto += "DEF(+" + equipo.ModifierDef() + ") ";
                        }

                        ConsoleBuffer.ObteBuffer().Print(5 + 50 * x, 3 + ii * 3, texto);
                    }
                    else if (bag[i].GetType() == typeof(ItemPocion))
                    {
                        ItemPocion consumable = (ItemPocion)bag[i];
                        ConsoleBuffer.ObteBuffer().Print(1 + 50 * x, 2 + ii * 3, consumable.GetName());
                        if (consumable.GetPocionType() == ItemPocion.PocionType.hp)
                        {
                            ConsoleBuffer.ObteBuffer().Print(1 + 50 * x, 3 + ii * 3, "    +" + consumable.GetFlatCant().ToString() + "% HP");
                        }
                        else
                        {
                            ConsoleBuffer.ObteBuffer().Print(1 + 50 * x, 3 + ii * 3, "    +" + consumable.GetFlatCant().ToString() + "% Mana");
                        }
                    }
                    else
                    {
                        ConsoleBuffer.ObteBuffer().Print(1 + 50 * x, 2 + ii * 3, bag[i].GetName());
                    }
                }
            }
            ConsoleBuffer.ObteBuffer().PrintBackground();
            ConsoleBuffer.ObteBuffer().Print(1, ConsoleBuffer.ObteBuffer().height - 2, "Pulsa cualquier boton para salir");
            ConsoleBuffer.ObteBuffer().Print(1, 0, "MOCHILA");
            ConsoleBuffer.ObteBuffer().SmallMap();
            ConsoleBuffer.ObteBuffer().PrintScreen();
            Console.ReadKey();
            return(true);
        }
Beispiel #40
0
 public static bool GetRoomDescr()
 {
     ConsoleBuffer.ObteBuffer().InsertText(Program.ObteJuego().pl.currentRoom.GetDescriptionTotal());
     return(true);
 }
Beispiel #41
0
        public static bool GetStats()
        {
            ConsoleBuffer.ObteBuffer().PrintBackground();
            Item[] bagitem = Program.ObteJuego().pl.GetGemas();
            int    modh    = 0;
            int    moda    = 0;
            int    modd    = 0;

            for (int i = 0; i < bagitem.Length; i++)
            {
                if (bagitem[i] != null && bagitem[i].GetType() == typeof(ItemGema))
                {
                    ItemGema gema = (ItemGema)bagitem[i];
                    modh += gema.ModifierHp();
                    moda += gema.ModifierAtt();
                    modd += gema.ModifierDef();
                }
            }
            ItemWeapon weapon = Program.ObteJuego().pl.GetWeapon();

            if (weapon != null)
            {
                modh += weapon.ModifierHp();
                moda += weapon.ModifierAtt();
                modd += weapon.ModifierDef();
            }
            ItemArmor armor = Program.ObteJuego().pl.GetArmor();

            if (armor != null)
            {
                modh += armor.ModifierHp();
                moda += armor.ModifierAtt();
                modd += armor.ModifierDef();
            }
            ConsoleBuffer.ObteBuffer().Print(1, 0, "STATS");

            ConsoleBuffer.ObteBuffer().Print(2, 3, "Nvl. " + Program.ObteJuego().pl.GetLevel() + "  Exp. " + Program.ObteJuego().pl.Experiencia);

            if (modh == 0)
            {
                ConsoleBuffer.ObteBuffer().Print(2, 5, "VIDA (HP)-> " + Program.ObteJuego().pl.GetHealth() + "/" + Program.ObteJuego().pl.GetMHealth() + " --> Capacidad de aguante");
            }
            else
            {
                ConsoleBuffer.ObteBuffer().Print(2, 5, "VIDA (HP)-> " + Program.ObteJuego().pl.GetHealth() + "/" + Program.ObteJuego().pl.GetMHealth() + "+(" + modh + ") --> Capacidad de aguante");
            }

            if (moda == 0)
            {
                ConsoleBuffer.ObteBuffer().Print(2, 7, "ATAQUE (Att)-> " + Program.ObteJuego().pl.GetFlatAtt() + " --> Daño que inflinges");
            }
            else
            {
                ConsoleBuffer.ObteBuffer().Print(2, 7, "ATAQUE (Att)-> " + Program.ObteJuego().pl.GetFlatAtt() + "+(" + moda + ") --> Daño que inflinges");
            }

            if (modd == 0)
            {
                ConsoleBuffer.ObteBuffer().Print(2, 9, "DEFENSA (Def)-> " + Program.ObteJuego().pl.GetFlatDef() + " --> Daño que reduces");
            }
            else
            {
                ConsoleBuffer.ObteBuffer().Print(2, 9, "DEFENSA (Def)-> " + Program.ObteJuego().pl.GetFlatDef() + "+(" + modd + ") --> Daño que reduces");
            }

            ConsoleBuffer.ObteBuffer().Print(2, 13, "MANA (mana) -> " + Program.ObteJuego().pl.GetMana() + "/" + Program.ObteJuego().pl.GetManaM());

            ConsoleBuffer.ObteBuffer().Print(2, 15, "Velocidad (Vel.) -> " + Program.ObteJuego().pl.GetSpeed());

            ConsoleBuffer.ObteBuffer().SmallMap();
            ConsoleBuffer.ObteBuffer().PrintScreen();
            Console.ReadKey();
            return(true);
        }
Beispiel #42
0
 /// <summary>
 /// Initializes a new instance of the ConsoleGraphicsDevice.
 /// </summary>
 /// <param name="viewport">Viewport of the console used to draw graphics.</param>
 public ConsoleGraphicsDevice(Viewport viewport)
     : base(viewport, StartBufferSize)
 {
     consoleBuffer = new ConsoleBuffer(viewport);
 }
        public void ApplyColorMap ()
        {
            var buffer = new ConsoleBuffer(2);

            buffer.ApplyBackgroundColorMap(new Rect(0, 0, 1, 1), ColorMaps.Invert);
            buffer.ApplyForegroundColorMap(new Rect(1, 0, 1, 1), ColorMaps.Invert);

            buffer.GetLine(0).Should().Equal(
                new ConsoleChar { BackgroundColor = White },
                new ConsoleChar { ForegroundColor = White });
        }
Beispiel #44
0
 public static void DrawImage(this ConsoleBuffer @this, ImageSource imageSource, Rect rect)
 {
     @this.DrawImage(imageSource, rect.X, rect.Y, rect.Width, rect.Height);
 }
Beispiel #45
0
        public static bool VerEquipo()
        {
            ConsoleBuffer.ObteBuffer().PrintBackground();
            ConsoleBuffer.ObteBuffer().Print(1, 0, "EQUIPO");
            ConsoleBuffer.ObteBuffer().Print(1, 4, "ARMA");
            ItemWeapon weapon = Program.ObteJuego().pl.GetWeapon();

            if (weapon != null)
            {
                ConsoleBuffer.ObteBuffer().Print(7, 5, weapon.GetName());
                ConsoleBuffer.ObteBuffer().Print(7, 6, "HP-> " + weapon.ModifierHp());
                ConsoleBuffer.ObteBuffer().Print(7, 7, "ATT-> " + weapon.ModifierAtt());
                ConsoleBuffer.ObteBuffer().Print(7, 8, "DEF-> " + weapon.ModifierDef());
            }
            else
            {
                ConsoleBuffer.ObteBuffer().Print(7, 5, "Ninguna");
            }


            ConsoleBuffer.ObteBuffer().Print(1, 12, "ARMADURA");
            ItemArmor armor = Program.ObteJuego().pl.GetArmor();

            if (armor != null)
            {
                ConsoleBuffer.ObteBuffer().Print(7, 13, armor.GetName());
                ConsoleBuffer.ObteBuffer().Print(7, 14, "HP-> " + armor.ModifierHp());
                ConsoleBuffer.ObteBuffer().Print(7, 15, "ATT-> " + armor.ModifierAtt());
                ConsoleBuffer.ObteBuffer().Print(7, 16, "DEF-> " + armor.ModifierDef());
            }
            else
            {
                ConsoleBuffer.ObteBuffer().Print(7, 5, "Ninguna");
            }

            ConsoleBuffer.ObteBuffer().Print(101, 3, "Hp  -> " + Program.ObteJuego().pl.GetHealth() + "/" + Program.ObteJuego().pl.GetMHealth());
            ConsoleBuffer.ObteBuffer().Print(101, 5, "Att -> " + Program.ObteJuego().pl.GetAtt());
            ConsoleBuffer.ObteBuffer().Print(101, 7, "Def -> " + Program.ObteJuego().pl.GetDef());
            ConsoleBuffer.ObteBuffer().Print(101, 11, "Mana -> " + Program.ObteJuego().pl.GetMana() + "/" + Program.ObteJuego().pl.GetManaM());
            ConsoleBuffer.ObteBuffer().Print(101, 13, "Vel. -> " + Program.ObteJuego().pl.GetSpeed());

            ConsoleBuffer.ObteBuffer().Print(51, 4, "GEMAS");

            ItemGema[] gemas = Program.ObteJuego().pl.GetGemas();
            bool       check = true;

            for (int i = 0; i < gemas.Length; i++)
            {
                if (gemas[i] != null)
                {
                    check = false;
                    if (i < 2)
                    {
                        ConsoleBuffer.ObteBuffer().Print(55, 5 + i * 7, i.ToString() + ":");
                        ConsoleBuffer.ObteBuffer().Print(57, 6 + i * 7, gemas[i].GetName());
                        ConsoleBuffer.ObteBuffer().Print(57, 7 + i * 7, "HP-> " + gemas[i].ModifierHp());
                        ConsoleBuffer.ObteBuffer().Print(57, 8 + i * 7, "ATT-> " + gemas[i].ModifierAtt());
                        ConsoleBuffer.ObteBuffer().Print(57, 9 + i * 7, "DEF-> " + gemas[i].ModifierDef());
                    }
                    else
                    {
                        ConsoleBuffer.ObteBuffer().Print(78, 5, i.ToString() + ":");
                        ConsoleBuffer.ObteBuffer().Print(80, 6, gemas[i].GetName());
                        ConsoleBuffer.ObteBuffer().Print(80, 7, "HP-> " + gemas[i].ModifierHp());
                        ConsoleBuffer.ObteBuffer().Print(80, 8, "ATT-> " + gemas[i].ModifierAtt());
                        ConsoleBuffer.ObteBuffer().Print(80, 9, "DEF-> " + gemas[i].ModifierDef());
                    }
                }
            }

            if (check)
            {
                ConsoleBuffer.ObteBuffer().Print(57, 5, "No tienes gemas");
            }

            ConsoleBuffer.ObteBuffer().Print(1, ConsoleBuffer.ObteBuffer().height - 2, "Pulsa cualquier tecla para salir");
            ConsoleBuffer.ObteBuffer().PrintScreen();
            Console.ReadKey();
            return(true);
        }
Beispiel #46
0
 public static bool Desequipar()
 {
     if (Program.ObteJuego().pl.FilledBag())
     {
         ConsoleBuffer.ObteBuffer().InsertText("Tienes la mochila llena");
         return(false);
     }
     else
     {
         ConsoleBuffer.ObteBuffer().InsertText("¿Que quieres desequiparte?");
         ConsoleBuffer.ObteBuffer().InsertText("    >ARMA    >GEMA    >ARMADURA");
         ConsoleBuffer.ObteBuffer().Print(1, ConsoleBuffer.ObteBuffer().height - 2, ">");
         ConsoleBuffer.ObteBuffer().PrintBackground();
         ConsoleBuffer.ObteBuffer().PrintText(ConsoleBuffer.ObteBuffer().height - 3);
         ConsoleBuffer.ObteBuffer().SmallMap();
         ConsoleBuffer.ObteBuffer().PrintScreen();
         Console.SetCursorPosition(2, ConsoleBuffer.ObteBuffer().height - 2);
         string tipo = Console.ReadLine().ToLower();
         if (tipo.Equals("arma"))
         {
             if (Program.ObteJuego().pl.GetWeapon() != null)
             {
                 for (int i = 0; i < Program.ObteJuego().pl.GetBag().Length; i++)
                 {
                     if (Program.ObteJuego().pl.GetBag()[i] == null)
                     {
                         Item rr = Program.ObteJuego().pl.DropWeapon();
                         ConsoleBuffer.ObteBuffer().InsertText("Te has desequipado " + rr.GetName());
                         Program.ObteJuego().pl.GetBag()[i] = rr;
                         i = Program.ObteJuego().pl.GetBag().Length;
                     }
                 }
                 return(true);
             }
             else
             {
                 ConsoleBuffer.ObteBuffer().InsertText("No tienes arma equipada");
                 return(false);
             }
         }
         else if (tipo.Equals("gema"))
         {
             if (Program.ObteJuego().pl.EmptyGemas())
             {
                 ConsoleBuffer.ObteBuffer().InsertText("No tienes gemas equipadas");
                 return(false);
             }
             else
             {
                 ConsoleBuffer.ObteBuffer().InsertText("¿Que gema quieres desequiparte?");
                 Program.ObteJuego().pl.ListOfGems();
                 ConsoleBuffer.ObteBuffer().Print(1, ConsoleBuffer.ObteBuffer().height - 2, ">");
                 ConsoleBuffer.ObteBuffer().PrintBackground();
                 ConsoleBuffer.ObteBuffer().PrintText(ConsoleBuffer.ObteBuffer().height - 3);
                 ConsoleBuffer.ObteBuffer().PrintScreen();
                 Console.SetCursorPosition(2, ConsoleBuffer.ObteBuffer().height - 2);
                 bool obj = int.TryParse(Console.ReadLine().ToLower(), out int gema);
                 if (obj && gema >= 0 && gema < Program.ObteJuego().pl.GetGemas().Length&& Program.ObteJuego().pl.GetGemas()[gema] != null)
                 {
                     ItemGema r = Program.ObteJuego().pl.GetGemas()[gema];
                     Program.ObteJuego().pl.GetGemas()[gema] = null;
                     for (int i = 0; i < Program.ObteJuego().pl.GetBag().Length; i++)
                     {
                         if (Program.ObteJuego().pl.GetBag()[i] == null)
                         {
                             Program.ObteJuego().pl.GetBag()[i] = r;
                             ConsoleBuffer.ObteBuffer().InsertText("Te has desequipado '" + r.GetName() + "'");
                             i = Program.ObteJuego().pl.GetBag().Length;
                         }
                     }
                     return(true);
                 }
                 else if (obj)
                 {
                     ConsoleBuffer.ObteBuffer().InsertText("Tiene que ser un número");
                 }
                 else
                 {
                     ConsoleBuffer.ObteBuffer().InsertText("El número no es válido");
                 }
                 return(false);
             }
         }
         else if (tipo.Equals("armadura"))
         {
             if (Program.ObteJuego().pl.GetArmor() != null)
             {
                 for (int i = 0; i < Program.ObteJuego().pl.GetBag().Length; i++)
                 {
                     if (Program.ObteJuego().pl.GetBag()[i] == null)
                     {
                         Item rr = Program.ObteJuego().pl.DropArmor();
                         ConsoleBuffer.ObteBuffer().InsertText("Te has desequipado " + rr.GetName());
                         Program.ObteJuego().pl.GetBag()[i] = rr;
                         i = Program.ObteJuego().pl.GetBag().Length;
                     }
                 }
                 return(true);
             }
             else
             {
                 ConsoleBuffer.ObteBuffer().InsertText("No tienes armadura equipada");
                 return(false);
             }
         }
         else
         {
             ConsoleBuffer.ObteBuffer().InsertText("Comando no válido");
             return(false);
         }
     }
 }
Beispiel #47
0
        static void RunInterpreter(string romName)
        {
            ConsoleBuffer  console = new ConsoleBuffer();
            VmemVisualizer view    = new VmemVisualizer();

            Chip8VM inr = new Chip8Sharp.Chip8InterpreterDBG();
            var     ROM = File.ReadAllBytes(romName);

            inr.LoadBinary(ROM);

            DisassemblyProvider disasm = new DisassemblyProvider(ROM, inr.State);

            //inr.AddBreakPoint(0x268);

            byte[] OldRegisters = new byte[0x10];
            UInt16 OldI         = 0;

            while (true)
            {
                console.Clear();

                int startOffset = inr.State.PC - Console.WindowHeight;
                if (startOffset % 2 != 0)
                {
                    startOffset += 1;
                }

                for (int i = 0; i < Console.WindowHeight - 4; i++)
                {
                    UInt16 offset = (UInt16)(startOffset + i * 2);

                    if (inr.IsBreakpoint(offset))
                    {
                        console.Write(offset.ToString("X4") + " | ", ConsoleColor.Red);
                    }
                    else
                    {
                        console.Write(offset.ToString("X4") + " | ", ConsoleColor.Gray);
                    }

                    if (disasm.IsLabel(offset))
                    {
                        console.Write("off_" + offset.ToString("X4") + ":  ", ConsoleColor.Yellow);
                    }

                    var text = disasm.DisassembleLine(offset);

                    if (offset == inr.State.PC)
                    {
                        console.Write("  > ", ConsoleColor.Green);
                        console.WriteLine(text, ConsoleColor.Green);
                    }
                    else if (text.Contains("off_"))
                    {
                        var off = text.IndexOf("off_");
                        console.Write(text.Substring(0, off));
                        console.WriteLine(text.Substring(off), ConsoleColor.Yellow);
                    }
                    else
                    {
                        console.WriteLine(text);
                    }
                }

                for (int i = 0; i < 16; i++)
                {
                    console.Write($"V{i.ToString("X")}: {inr.State.Register((byte)i).ToString("X2")}   | ", inr.State.Registers.AsSpan()[i] != OldRegisters[i] ? ConsoleColor.Red : ConsoleColor.White);
                }
                console.Write($"I: {inr.State.I.ToString("X4")}   |", inr.State.I != OldI ? ConsoleColor.Red : ConsoleColor.White);
                console.Write($"PC: {inr.State.PC.ToString("X4")}   |");
                console.Write($"SP: {inr.State.SP.ToString("X4")}   |");
                console.Write($"DT: {inr.State.DT.ToString("X2")}   |");
                console.Write($"ST: {inr.State.ST.ToString("X2")}   |");

                console.WriteLine("");

                OldRegisters = inr.State.Registers.AsSpan().ToArray();
                OldI         = inr.State.I;

                console.Write("Space: ", ConsoleColor.Cyan);
                console.Write("step  ");
                console.Write("Q: ", ConsoleColor.Cyan);
                console.Write("run  ");
                console.Write("Z: ", ConsoleColor.Cyan);
                console.Write("run 5  ");
                console.Write("X: ", ConsoleColor.Cyan);
                console.Write("run 10  ");
                console.Write("C: ", ConsoleColor.Cyan);
                console.Write("run 15  ");
                console.Write("V: ", ConsoleColor.Cyan);
                console.Write("run 30  ");
                console.Write("N: ", ConsoleColor.Cyan);
                console.Write("run to jump  ");
                console.Write("B: ", ConsoleColor.Cyan);
                console.Write("toggle BP  ");
                console.Write("P: ", ConsoleColor.Cyan);
                console.Write("Break in VS ");
                console.Write("M: ", ConsoleColor.Cyan);
                console.Write("Disasm RAM ", disasm.DisassembleRam ? ConsoleColor.Green : ConsoleColor.White);

                console.Display();
                if (inr.CheckVMEMUpdate())
                {
                    view.Draw(inr);
                }

ReadAgain:
                switch (Console.ReadKey(true).Key)
                {
                case ConsoleKey.P:
                    Debugger.Break();
                    inr.StepInto();
                    break;

                case ConsoleKey.Spacebar:
                    inr.StepInto();
                    break;

                case ConsoleKey.Q:
                    inr.Run();
                    break;

                case ConsoleKey.Z:
                    inr.Run(5);
                    break;

                case ConsoleKey.X:
                    inr.Run(10);
                    break;

                case ConsoleKey.C:
                    inr.Run(15);
                    break;

                case ConsoleKey.V:
                    inr.Run(30);
                    break;

                case ConsoleKey.N:
                    inr.BreakOnJump = true;
                    inr.Run();
                    break;

                case ConsoleKey.M:
                    disasm.DisassembleRam = !disasm.DisassembleRam;
                    continue;

                case ConsoleKey.B:
                    var bp = ReadBreakPoint();
                    if (inr.IsBreakpoint(bp))
                    {
                        inr.RemovBreakPoint(bp);
                    }
                    else
                    {
                        inr.AddBreakPoint(bp);
                    }
                    console.UnbufferedClear();
                    continue;

                default:
                    goto ReadAgain;
                }
            }
        }
Beispiel #48
0
        public static bool DrawMap()
        {
            Player      pl        = Program.ObteJuego().pl;
            List <Room> lvlLayout = Program.ObteJuego().lvlLayout;
            int         miniMapx  = pl.currentRoom.GetPosX() * 2;
            int         miniMapy  = pl.currentRoom.GetPosY() * 2;
            int         width     = ConsoleBuffer.ObteBuffer().width;
            int         height    = ConsoleBuffer.ObteBuffer().height;
            int         level     = Program.ObteJuego().level;

            ConsoleKeyInfo keyInfo;

            do
            {
                for (int i = 0; i < lvlLayout.Count; i++)
                {
                    if (lvlLayout[i].IsVisible() != 0)
                    {
                        int xx = (lvlLayout[i].GetPosX()) * 2 - miniMapx + (width - 20) / 2;
                        int yy = (-lvlLayout[i].GetPosY()) * 2 + miniMapy + height / 2;
                        if (xx >= 1 && xx < width - 21 && yy >= 2 && yy < height - 1)
                        {
                            if (lvlLayout[i].IsVisible() == 2)
                            {
                                if (pl.currentRoom.GetPosX() == lvlLayout[i].GetPosX() && pl.currentRoom.GetPosY() == lvlLayout[i].GetPosY())
                                {
                                    ConsoleBuffer.ObteBuffer().Print(xx, yy, "O");
                                }
                                else if (lvlLayout[i].GetType() == typeof(RoomTreasure))
                                {
                                    ConsoleBuffer.ObteBuffer().Print(xx, yy, "Z");
                                }
                                else if (lvlLayout[i].GetType() == typeof(RoomExit))
                                {
                                    ConsoleBuffer.ObteBuffer().Print(xx, yy, "S");
                                }
                                else if (lvlLayout[i].GetType() == typeof(RoomClosed))
                                {
                                    ConsoleBuffer.ObteBuffer().Print(xx, yy, "T");
                                }
                                else if (lvlLayout[i].GetType() == typeof(RoomBless))
                                {
                                    ConsoleBuffer.ObteBuffer().Print(xx, yy, "B");
                                }
                                else
                                {
                                    ConsoleBuffer.ObteBuffer().Print(xx, yy, "X");
                                }

                                if (lvlLayout[i].GetNorthRoom() != null)
                                {
                                    if (yy >= 3)
                                    {
                                        ConsoleBuffer.ObteBuffer().Print(xx, yy - 1, "|");
                                    }
                                }
                                if (lvlLayout[i].GetSouthRoom() != null)
                                {
                                    if (yy < height - 2)
                                    {
                                        ConsoleBuffer.ObteBuffer().Print(xx, yy + 1, "|");
                                    }
                                }
                                if (lvlLayout[i].GetWestRoom() != null)
                                {
                                    if (xx > 0)
                                    {
                                        ConsoleBuffer.ObteBuffer().Print(xx - 1, yy, "-");
                                    }
                                }
                                if (lvlLayout[i].GetEastRoom() != null)
                                {
                                    if (xx < width - 22)
                                    {
                                        ConsoleBuffer.ObteBuffer().Print(xx + 1, yy, "-");
                                    }
                                }
                            }
                            else
                            {
                                if (pl.currentRoom.GetPosX() == lvlLayout[i].GetPosX() && pl.currentRoom.GetPosY() == lvlLayout[i].GetPosY())
                                {
                                    throw new Exception("Sala invisible en propia localización");
                                }
                                else
                                {
                                    ConsoleBuffer.ObteBuffer().Print(xx, yy, "?");
                                }
                                if (lvlLayout[i].IsVisible() == 3)
                                {
                                    if (lvlLayout[i].GetNorthRoom() != null)
                                    {
                                        if (yy >= 3)
                                        {
                                            ConsoleBuffer.ObteBuffer().Print(xx, yy - 1, "|");
                                        }
                                    }
                                    if (lvlLayout[i].GetSouthRoom() != null)
                                    {
                                        if (yy < height - 2)
                                        {
                                            ConsoleBuffer.ObteBuffer().Print(xx, yy + 1, "|");
                                        }
                                    }
                                    if (lvlLayout[i].GetWestRoom() != null)
                                    {
                                        if (xx > width - 19)
                                        {
                                            ConsoleBuffer.ObteBuffer().Print(xx - 1, yy, "-");
                                        }
                                    }
                                    if (lvlLayout[i].GetEastRoom() != null)
                                    {
                                        if (xx < width - 2)
                                        {
                                            ConsoleBuffer.ObteBuffer().Print(xx + 1, yy, "-");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                ConsoleBuffer.ObteBuffer().Print(1, 0, "MAP");
                ConsoleBuffer.ObteBuffer().Print(71, 0, "Usa flechas para mover mapa");
                ConsoleBuffer.ObteBuffer().Print(1, 2, "O -> Tu");
                ConsoleBuffer.ObteBuffer().Print(1, 3, "T, Z, B -> Especial");
                ConsoleBuffer.ObteBuffer().Print(1, 4, "S -> Salida");
                ConsoleBuffer.ObteBuffer().Print(101, 0, "Planta: " + -(level - 1));
                ConsoleBuffer.ObteBuffer().PrintBackground();

                ConsoleBuffer.ObteBuffer().PrintScreen();
                keyInfo = Console.ReadKey();
                switch (keyInfo.Key)
                {
                case ConsoleKey.DownArrow:
                    miniMapy -= 2;
                    break;

                case ConsoleKey.UpArrow:
                    miniMapy += 2;
                    break;

                case ConsoleKey.LeftArrow:
                    miniMapx -= 2;
                    break;

                case ConsoleKey.RightArrow:
                    miniMapx += 2;
                    break;
                }
            } while (keyInfo.Key == ConsoleKey.RightArrow || keyInfo.Key == ConsoleKey.LeftArrow || keyInfo.Key == ConsoleKey.UpArrow || keyInfo.Key == ConsoleKey.DownArrow);
            return(true);
        }
Beispiel #49
0
        private void Run ()
        {
            /*Size consoleSize = Size.Min(ConsoleRenderer.ConsoleLargestWindowSize, new Size((25 + 1) * 7 + 1, 60));
            try {
                ConsoleRenderer.ConsoleWindowRect = new Rect(consoleSize);
                Console.BufferWidth = consoleSize.Width;
            }
            catch (Exception e) {
                var consoleRect = new Rect(Console.WindowLeft, Console.WindowTop, Console.WindowWidth, Console.WindowHeight);
                Console.WriteLine(consoleRect);
                var bufferRect = new Size(Console.BufferWidth, Console.BufferHeight);
                Console.WriteLine(bufferRect);
                Console.WriteLine(e.Message);
            }*/
            Console.OutputEncoding = Encoding.UTF8;
            Console.Title = Path.GetFileNameWithoutExtension(Console.Title);

            var data = new Data {
                Title = "Header Title",
                SubTitle = "Header SubTitle",
                Formatted = "Aaaa\nBbbb\nCccc",
                LoremIpsum = "Lo|rem ip|sum do|lor sit amet, con|sec|te|tur adi|pis|cing elit, sed do eius|mod tem|por in|ci|di|dunt ut la|bo|re et do|lo|re mag|na ali|qua. Ut enim ad mi|nim ve|ni|am, qu|is nos|trud exer|ci|ta|tion ul|lam|co la|bo|ris ni|si ut ali|quip ex ea com|mo|do con|se|quat. Du|is au|te iru|re do|lor in rep|re|hen|de|rit in vo|lup|ta|te ve|lit es|se cil|lum do|lo|re eu fu|gi|at nul|la pa|ri|a|tur. Ex|cep|te|ur sint oc|ca|e|cat cu|pi|da|tat non pro|i|dent, sunt in cul|pa qui of|fi|cia de|se|runt mol|lit anim id est la|bo|rum.",
                LoremIpsumShort = "Lo|rem ip|sum do|lor sit amet, con|sec|te|tur adi|pis|cing elit, sed do eius|mod tem|por in|ci|di|dunt ut la|bo|re et do|lo|re mag|na ali|qua. Ut enim ad mi|nim ve|ni|am, qu|is nos|trud exer|ci|ta|tion ul|lam|co la|bo|ris ni|si ut ali|quip ex ea com|mo|do con|se|quat.",
                Guid = Guid.NewGuid(),
                Date = DateTime.Now,
                Items = new List<DataItem> {
                    new DataItem {
                        Id = 1, Name = "Name 1", Value = "Value 1",
                        SubItems = new List<DataItem> {
                            new DataItem { Id = 11, Name = "Name 1.1", Value = "Value 1.1" },
                            new DataItem { Id = 12, Name = "Name 1.2", Value = "Value 1.2" },
                        }
                    },
                    new DataItem { Id = 2, Name = "Name 2", Value = "Value 2" },
                }
            };

            /*if (MemoryProfiler.IsActive) {
                MemoryProfiler.EnableAllocations();
                MemoryProfiler.Dump();
            }
            new ConsoleRenderer().RenderDocument(ReadXaml<Document>(data));
            if (MemoryProfiler.IsActive)
                MemoryProfiler.Dump();*/
            /*for (int i = 0; i < 100; i++)
                new ConsoleRenderer().RenderDocument(ReadXaml<Document>(data));*/
            /*if (MemoryProfiler.IsActive)
                MemoryProfiler.Dump();*/

            Document xamlDoc = ConsoleRenderer.ReadDocumentFromResource(GetType(), "Markup.xaml", data);
            //Document xamlDoc = ConsoleRenderer.ReadDocumentFromResource(GetType().Assembly, "Alba.CsConsoleFormat.ConsoleTest.Markup.xaml", data);
            Console.WriteLine("XAML");
            ConsoleRenderer.RenderDocument(xamlDoc);
            ConsoleRenderer.RenderDocument(xamlDoc, new HtmlRenderTarget(File.Create(@"../../Tmp/0.html"), new UTF8Encoding(false)));

            Document builtDoc = new ViewBuilder().CreateDocument(data);
            Console.WriteLine("Builder");
            ConsoleRenderer.RenderDocument(builtDoc);
            ConsoleRenderer.RenderDocument(builtDoc, new HtmlRenderTarget(File.Create(@"../../Tmp/0a.html"), new UTF8Encoding(false)));

            var buffer = new ConsoleBuffer(80) {
                LineCharRenderer = LineCharRenderer.Box,
                //Clip = new Rect(1, 1, 78, 30),
            };
            var rainbow = new[] {
                Black,
                DarkRed, DarkYellow, DarkGreen, DarkCyan, DarkBlue, DarkMagenta, DarkRed,
                Black,
                Red, Yellow, Green, Cyan, Blue, Magenta, Red,
            };
            /*for (int i = 0; i < 16; i++)
                buffer.FillRectangle((ConsoleColor)i, i, i, 80 - i * 2, 31 - i * 2);*/
            for (int i = 0; i < rainbow.Length; i++)
                buffer.FillBackgroundRectangle(i, i, 80 - i * 2, (rainbow.Length - i) * 2, rainbow[i]);
            buffer.DrawHorizontalLine(1, 0, 78, White);
            buffer.DrawHorizontalLine(1, 1, 78, White, LineWidth.Wide);
            buffer.DrawHorizontalLine(3, 3, 7, White);
            buffer.DrawVerticalLine(1, 1, 9, White);
            buffer.DrawVerticalLine(2, 2, 4, White);
            buffer.DrawVerticalLine(5, 0, 6, White, LineWidth.Wide);
            buffer.DrawVerticalLine(5, 0, 6, White);
            buffer.DrawVerticalLine(6, 0, 6, White);
            buffer.DrawVerticalLine(3, 0, 12, White, LineWidth.Wide);
            buffer.DrawRectangle(0, 0, 80, 32, White, LineWidth.Wide);
            buffer.FillBackgroundVerticalLine(40, 0, 32, Yellow);
            buffer.FillForegroundVerticalLine(41, 0, 32, White, FullBlock);
            buffer.FillForegroundVerticalLine(42, 0, 32, White, DarkShade);
            buffer.FillForegroundVerticalLine(43, 0, 32, White, MediumShade);
            buffer.FillForegroundVerticalLine(44, 0, 32, White, LightShade);
            buffer.DrawString(15, 15, Black, "Hello world!");
            buffer.DrawString(15, 16, White, "Hello world! Hello world! Hello world! Hello world! Hello world! Hello world!");
            //buffer.ApplyBackgroundColorMap(0, 0, buffer.Width, buffer.Height, ColorMaps.Invert);
            //buffer.ApplyForegroundColorMap(0, 0, buffer.Width, buffer.Height, ColorMaps.Invert);

            //new ConsoleRenderTarget().Render(buffer);
            //new ConsoleRenderTarget { ColorOverride = ConsoleColor.White, BackgroundOverride = ConsoleColor.Black }.Render(buffer);
            using (var file = File.Create(@"../../Tmp/1.html"))
                new HtmlRenderTarget(file, new UTF8Encoding(false)).Render(buffer);
            using (var file = new StreamWriter(File.Create(@"../../Tmp/1.ans"), Encoding.GetEncoding("ibm437")) { NewLine = "" })
                new AnsiRenderTarget(file).Render(buffer);
            using (var file = File.Create(@"../../Tmp/1.txt"))
                new TextRenderTarget(file).Render(buffer);
            using (var file = File.Create(@"../../Tmp/1.asc"))
                new TextRenderTarget(file, Encoding.GetEncoding("ibm437")).Render(buffer);

            /*var text = new TextRenderTarget();
            text.Render(buffer);
            Console.Write(text.OutputText);*/

            /*Console.WriteLine(Console.OutputEncoding);
            Console.OutputEncoding = Encoding.UTF8;
            Console.WriteLine("■▬▲►▼◄");
            Console.WriteLine("▀▄█▌▐");
            Console.WriteLine("♠♣♥♦");
            Console.WriteLine("☺☻☼♀♂♫");
            Console.WriteLine("«»‘’‚‛“”„‟‹›");*/
            /*const string TestString1 = "«»‘’‚‛“”„‟‹›", TestString2 = "─═│║┼╪╫╬";
            foreach (EncodingInfo encodingInfo in Encoding.GetEncodings()) {
                try {
                    Encoding encoding = encodingInfo.GetEncoding();
                    bool matched1 = encoding.GetString(encoding.GetBytes(TestString1)) == TestString1;
                    bool matched2 = encoding.GetString(encoding.GetBytes(TestString2)) == TestString2;
                    Console.OutputEncoding = encoding;
                    Console.WriteLine("{0,-10}{1,-20}{2}{3} {4} {5}",
                        encodingInfo.CodePage, encodingInfo.Name, matched1 ? "+" : "-", matched2 ? "+" : "-", TestString1, TestString2);
                }
                catch {
                    Console.WriteLine("{0,-10}{1,-20}xx FAILED",
                        encodingInfo.CodePage, encodingInfo.Name);
                }
            }*/
            /*for (int i = 1; i < 10000; i += 10) {
                var sb = new StringBuilder();
                for (int j = 0; j < 10; j++)
                    sb.AppendFormat("{0,-6}{1} ", (i + j), (char)(i + j));
                Console.Write(sb);
            }*/
        }
        private static async void StartDemo()
        {
            const string NAME = "#BUFFER_SELECTION123#";

            ConsoleBuffer.MemoriseBufferPosition(NAME);

            Console.WriteLine("Select 1 option");
            var selection = InputSelection.From <TestClass>()
                            .AddOption(new TestClass {
                Name = "option1"
            })
                            .AddOption(new TestClass {
                Name = "option2"
            })
                            .AddOption(new TestClass {
                Name = "option3"
            })
                            .AddOption(new TestClass {
                Name = "option4"
            });

            var result1 = await selection.RequestInput();

            Console.WriteLine($"Selected => {result1.First()}");
            ConsoleI.AwaitContinue();
            ConsoleBuffer.ClearBufferFrom(NAME);

            Console.WriteLine("Select 1 to 5 options");
            var selection2 = InputSelection.From <TestClass>()
                             .SetMaxSelected(5)
                             .AddOption(new TestClass {
                Name = "option1"
            })
                             .AddOption(new TestClass {
                Name = "option2"
            })
                             .AddOption(new TestClass {
                Name = "option3"
            })
                             .AddOption(new TestClass {
                Name = "option4"
            })
                             .AddOption(new TestClass {
                Name = "option5"
            })
                             .AddOption(new TestClass {
                Name = "option6"
            })
                             .AddOption(new TestClass {
                Name = "option7"
            })
                             .AddOption(new TestClass {
                Name = "option8"
            })
                             .AddOption(new TestClass {
                Name = "option9"
            })
                             .AddOption(new TestClass {
                Name = "option10"
            })
                             .AddOption(new TestClass {
                Name = "option11"
            });

            var result2 = await selection2.RequestInput();

            foreach (var r in result2)
            {
                Console.WriteLine($"Selected => {r}");
            }
            ConsoleI.AwaitContinue();
            ConsoleBuffer.ClearBufferFrom(NAME);

            Console.WriteLine("Also works with ENUM");
            var result3 = await InputSelection
                          .FromEnum <EnumTest>()
                          .RequestInput();

            foreach (var r in result3)
            {
                Console.WriteLine($"Selected => {(int)r}");
            }
            ConsoleI.AwaitContinue();
            ConsoleBuffer.ClearBufferFrom(NAME);
        }