Ejemplo n.º 1
0
        public void TestRecordVideoBasic()
        {
            ConsoleBitmap bitmap = new ConsoleBitmap(4, 2), redBitmap = null, greenBitmap = null, magentaPixelBitmap = null;

            using (var sharedStream = new MemoryStream())
            {
                using (var bitmapVideoWriter = new ConsoleBitmapStreamWriter(sharedStream)
                {
                    CloseInnerStream = false
                })
                {
                    bitmap             = new ConsoleBitmap(4, 2);
                    redBitmap          = bitmapVideoWriter.WriteFrame(bitmap.FillRect(ConsoleCharacter.RedBG())).Clone();
                    greenBitmap        = bitmapVideoWriter.WriteFrame(bitmap.FillRect(ConsoleCharacter.GreenBG())).Clone();
                    magentaPixelBitmap = bitmapVideoWriter.WriteFrame(bitmap.DrawPoint(ConsoleCharacter.MagentaBG(), 0, 0)).Clone();
                }

                sharedStream.Position = 0; // rewind the stream to the beginning to read it back

                // create a reader and make sure we can read each frame back exactly as they were written
                var bitmapVideoReader = new ConsoleBitmapStreamReader(sharedStream);
                Assert.AreEqual(redBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap);
                Assert.AreEqual(greenBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap);
                Assert.AreEqual(magentaPixelBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap);
                Assert.IsNull(bitmapVideoReader.ReadFrame().CurrentFrame);
            }
        }
Ejemplo n.º 2
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            var state = (Element as ProximityMine).State;

            if (state == ProximityMineState.NoNearbyThreats)
            {
                context.FillRect(new ConsoleCharacter('#', ConsoleColor.DarkGray), 0, 0, Width, Height);
            }
            else if (state == ProximityMineState.ThreatApproaching)
            {
                context.FillRect(new ConsoleCharacter('#', ConsoleColor.Black, ConsoleColor.DarkYellow), 0, 0, Width, Height);
            }
            else if (state == ProximityMineState.ThreatNearby)
            {
                context.FillRect(new ConsoleCharacter('#', ConsoleColor.Black, ConsoleColor.Red), 0, 0, Width, Height);
            }
        }
Ejemplo n.º 3
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            var state = (Element as Door).State;
            var pen   = state == DoorState.Locked ? new ConsoleCharacter('X', ConsoleColor.Black, ConsoleColor.Cyan) :
                        new ConsoleCharacter(' ', backgroundColor: ConsoleColor.Cyan);

            context.FillRect(pen, 0, 0, Width, Height);
        }
Ejemplo n.º 4
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            if (Character.IsVisible == false)
            {
                context.Pen = new ConsoleCharacter(' ', RGB.Black);
                context.FillRect(0, 0, Width, Height);
                return;
            }
            char c;

            var angle = Character.Velocity.Angle;

            c = Geometry.GetArrowPointedAt(angle);

            context.Pen = Character.Pen.HasValue ? Character.Pen.Value : new ConsoleCharacter(c, Character.Color);
            context.FillRect(0, 0, Width, Height);
        }
Ejemplo n.º 5
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     if ((Element as Waypoint).IsHighlighted)
     {
         context.Pen = new PowerArgs.ConsoleCharacter('W', backgroundColor: ConsoleColor.Cyan);
         context.FillRect(0, 0, Width, Height);
     }
 }
Ejemplo n.º 6
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            context.Pen = new ConsoleCharacter('F', ConsoleColor.Green);
            if ((Element as Character).Symbol.HasValue)
            {
                context.Pen = new ConsoleCharacter((Element as Character).Symbol.Value, context.Pen.ForegroundColor, context.Pen.BackgroundColor);
            }

            context.FillRect(0, 0, Width, Height);
        }
Ejemplo n.º 7
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     if (Element.Pen.HasValue)
     {
         context.FillRect(Element.Pen.Value, 0, 0, Width, Height);
     }
     else
     {
         base.OnPaint(context);
     }
 }
Ejemplo n.º 8
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     if ((Thing as Zombie).IsBeingTargeted)
     {
         context.Pen = new PowerArgs.ConsoleCharacter('Z', (Thing as Zombie).HealthPoints < 2 ? ConsoleColor.Gray : ConsoleColor.DarkRed, ConsoleColor.Cyan);
     }
     else
     {
         context.Pen = new PowerArgs.ConsoleCharacter('Z', (Thing as Zombie).HealthPoints < 2 ? ConsoleColor.Gray : ConsoleColor.DarkRed);
     }
     context.FillRect(0, 0, Width, Height);
 }
Ejemplo n.º 9
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            var primarySymbol = (Element as Fire).SymbolOverride.HasValue ? (Element as Fire).SymbolOverride.Value : BurnSymbol1;

            if (r.NextDouble() < .9)
            {
                var color  = r.NextDouble() < .8 ? PrimaryBurnColor : SecondaryBurnColor;
                var symbol = r.NextDouble() < .65 ? primarySymbol : BurnSymbol2;

                context.Pen = new ConsoleCharacter(symbol, color);
                context.FillRect(0, 0, Width, Height);
            }
        }
Ejemplo n.º 10
0
        public void TestPlaybackEndToEnd()
        {
            int w = 10, h = 1;
            var temp = Path.GetTempFileName();

            using (var stream = File.OpenWrite(temp))
            {
                var writer = new ConsoleBitmapStreamWriter(stream)
                {
                    CloseInnerStream = false
                };
                var bitmap = new ConsoleBitmap(w, h);

                for (var i = 0; i < bitmap.Width; i++)
                {
                    bitmap.Pen = new ConsoleCharacter(' ');
                    bitmap.FillRect(0, 0, bitmap.Width, bitmap.Height);
                    bitmap.Pen = new ConsoleCharacter(' ', backgroundColor: ConsoleColor.Red);
                    bitmap.DrawPoint(i, 0);
                    writer.WriteFrame(bitmap, true, TimeSpan.FromSeconds(.5 * i));
                }
                writer.Dispose();
            }

            var app = new CliTestHarness(this.TestContext, 80, 30);

            app.QueueAction(() =>
            {
                var player = app.LayoutRoot.Add(new ConsoleBitmapPlayer()).Fill();
                player.Load(File.OpenRead(temp));
                app.SetTimeout(() => app.SendKey(new ConsoleKeyInfo('p', ConsoleKey.P, false, false, false)), TimeSpan.FromMilliseconds(100));
                var playStarted = false;
                player.SubscribeForLifetime(nameof(player.State), () =>
                {
                    if (player.State == PlayerState.Playing)
                    {
                        playStarted = true;
                    }
                    else if (player.State == PlayerState.Stopped && playStarted)
                    {
                        app.Stop();
                    }
                }, app);
            });

            app.Start().Wait();
            Thread.Sleep(100);
            app.AssertThisTestMatchesLKGFirstAndLastFrame();
        }
Ejemplo n.º 11
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            var w = Element as Wall;

            if (w.Pen.HasValue)
            {
                context.Pen = w.Pen.Value;
            }
            else
            {
                context.Pen = Style;
            }

            context.FillRect(0, 0, Width, Height);
        }
Ejemplo n.º 12
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            if (Character.IsVisible == false)
            {
                return;
            }
            char c;

            var angle = Character.Speed.Angle;

            c = Geometry.GetArrowPointedAt(angle);

            context.Pen = new ConsoleCharacter(c, Character.Color);
            context.FillRect(0, 0, Width, Height);
        }
Ejemplo n.º 13
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            if ((Element as Enemy).IsBeingTargeted)
            {
                context.Pen = TargetedStyle;
            }
            else
            {
                context.Pen = (Element as Enemy).HealthPoints >= 3 ? NormalStyle : HurtStyle;
            }

            if ((Element as Character).Symbol.HasValue)
            {
                context.Pen = new ConsoleCharacter((Element as Character).Symbol.Value, context.Pen.ForegroundColor, context.Pen.BackgroundColor);
            }

            context.FillRect(0, 0, Width, Height);
        }
Ejemplo n.º 14
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            var w = Element as Wall;

            if (w.Pen.HasValue && w.Pen.Value.Value != ' ')
            {
                context.Pen = w.Pen.Value;
            }
            else
            {
                context.Pen = Style;
            }

            if (context.Pen.Value == ' ' && context.Pen.BackgroundColor == ConsoleString.DefaultBackgroundColor)
            {
                context.Pen = new ConsoleCharacter('W');
            }

            if ((Element as Wall).ForcePen)
            {
                context.Pen = (Element as Wall).Pen.Value;
            }
            context.FillRect(0, 0, Width, Height);
        }
Ejemplo n.º 15
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     context.Pen = (Thing as Wall).Texture;
     context.FillRect(0, 0, Width, Height);
 }
Ejemplo n.º 16
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     context.Pen = (Element as FlammableLetter).Symbol;
     context.FillRect(0, 0, Width, Height);
 }
Ejemplo n.º 17
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     context.Pen = new ConsoleCharacter(Math.Ceiling((Element as TimedMine).SecondsRemaining).ToString()[0], EffectiveStyle.ForegroundColor, EffectiveStyle.BackgroundColor);
     context.FillRect(0, 0, Width, Height);
 }
Ejemplo n.º 18
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     context.Pen = new PowerArgs.ConsoleCharacter('T', Foreground, Background);
     context.FillRect(0, 0, Width, Height);
 }
Ejemplo n.º 19
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     context.Pen = new ConsoleCharacter((Element as Satellite).Symbol, (Element as Satellite).IsShadow ? ConsoleColor.DarkGray : ConsoleColor.Green);
     context.FillRect(0, 0, Width, Height);
 }
Ejemplo n.º 20
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     context.Pen = EffectiveStyle;
     context.FillRect(0, 0, Width, Height);
 }
Ejemplo n.º 21
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     base.OnPaint(context);
     context.Pen = new PowerArgs.ConsoleCharacter('X', ConsoleColor.Green);
     context.FillRect(0, 0, Width, Height);
 }
Ejemplo n.º 22
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     context.Pen = new ConsoleCharacter(symbol, color);
     context.FillRect(0, 0, Width, Height);
 }
Ejemplo n.º 23
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     context.Pen = new ConsoleCharacter(Math.Ceiling((Element as TimedMine).SecondsRemaining).ToString()[0], ConsoleColor.Black, ConsoleColor.DarkYellow);
     context.FillRect(0, 0, Width, Height);
 }
Ejemplo n.º 24
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     context.Pen = new PowerArgs.ConsoleCharacter('O', ConsoleColor.White, ConsoleColor.Magenta);
     context.FillRect(0, 0, Width, Height);
 }
Ejemplo n.º 25
0
 public void FillRect()
 {
     bitmap.FillRect(pen, 0, 0, bitmap.Width, bitmap.Height);
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Paints the divider
        /// </summary>
        /// <param name="context">the bitmap target</param>
        protected override void OnPaint(ConsoleBitmap context)
        {
            var c = Orientation == Orientation.Vertical ? '|' : '-';

            context.FillRect(new ConsoleCharacter(c, Foreground, Background), 0, 0, Width, Height);
        }
Ejemplo n.º 27
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     context.Pen = (Thing as Ammo).Symbol;
     context.FillRect(0, 0, Width, Height);
 }