示例#1
0
        public FieldTest()
        {
            this.Width = DefaultWidth;
            this.Height = DefaultHeight;

            var f = new Field(6, 4)
                {
                    ShowSelection = true
                };

            #region round the corners
            f.Tiles[0, 0].Hide();
            f.Tiles[f.Tiles.SizeX - 1, 0].Hide();
            f.Tiles[f.Tiles.SizeX - 1, f.Tiles.SizeY - 1].Hide();
            f.Tiles[0, f.Tiles.SizeY - 1].Hide();
            #endregion

            f[2, 0] = new SimplePipe.PumpToLeft();

            f[1, 0] = new SimplePipe.RightToBottom();
            f[1, 1] = new SimplePipe.Vertical();
            f[1, 2] = new SimplePipe.TopToRight();
            f[2, 2] = new SimplePipe.Cross();
            f[3, 2] = new SimplePipe.Horizontal();
            f[4, 2] = new SimplePipe.LeftToDrain();

            f[2, 1] = new SimplePipe.RightToBottom();
            f[2, 3] = new SimplePipe.TopToLeft();
            f[3, 1] = new SimplePipe.Horizontal();
            f[4, 1] = new SimplePipe.TopToLeft();
            f[4, 0] = new SimplePipe.LeftToBottom();
            f[3, 0] = new SimplePipe.RightToDrain();
            f[1, 3] = new SimplePipe.PumpToRight();

            f[4, 2].Output.Drain = f[1, 3].Input.Pump;

            // show a hole in the floor
            f.Tiles[3, 0].Drain.Visibility = System.Windows.Visibility.Visible;
            f.Tiles[4, 2].Drain.Visibility = System.Windows.Visibility.Visible;

            // user must click on the pump to activate it
            f.Tiles[2, 0].Overlay.MouseLeftButtonUp +=
                delegate
                {
                    f[2, 0].Input.Pump();
                };

            // when a user adds a pipe on top of another
            // we need to call this to force a zorder sort
            f.RefreshPipes();

            var x = (DefaultWidth - f.Tiles.Width) / 2;
            var y = (DefaultHeight - f.Tiles.Height) / 2;

            f.Container.MoveTo(x, y).AttachTo(this);

            #region overlay
            var Overlay = new Canvas
            {
                Width = DefaultWidth,
                Height = DefaultHeight,
            }.AttachTo(this);

            new Rectangle
            {
                Fill = Brushes.White,
                Width = DefaultWidth,
                Height = DefaultHeight,
                Opacity = 0
            }.AttachTo(Overlay);

            f.Tiles.Overlay.MoveTo(x, y).AttachTo(Overlay);
            #endregion
        }
        public InteractiveFieldTest()
        {
            this.Width = DefaultWidth;
            this.Height = DefaultHeight;

            var f = new Field(8, 8)
            {
                DefaultPipeColor = Colors.Green
            };

            #region round the corners
            f.Tiles[0, 0].Hide();
            f.Tiles[f.Tiles.SizeX - 1, 0].Hide();
            f.Tiles[f.Tiles.SizeX - 1, f.Tiles.SizeY - 1].Hide();
            f.Tiles[0, f.Tiles.SizeY - 1].Hide();
            #endregion

            f[2, 0] = new SimplePipe.PumpToLeft();

            f[1, 0] = new SimplePipe.RightToBottom();
            f[1, 1] = new SimplePipe.Vertical();
            f[1, 2] = new SimplePipe.TopToRight();
            f[2, 2] = new SimplePipe.Cross();
            f[3, 2] = new SimplePipe.Horizontal();
            f[4, 2] = new SimplePipe.LeftToDrain();

            f[2, 1] = new SimplePipe.RightToBottom();
            f[2, 3] = new SimplePipe.TopToLeft();
            f[3, 1] = new SimplePipe.Horizontal();
            f[4, 1] = new SimplePipe.TopToLeft();
            f[4, 0] = new SimplePipe.LeftToBottom();
            f[3, 0] = new SimplePipe.RightToDrain();
            f[1, 3] = new SimplePipe.PumpToRight();
            f[2, 4] = new SimplePipe.PumpToRight();
            f[3, 5] = new SimplePipe.BonusPickup();

            f[4, 2].Output.Drain = f[1, 3].Input.Pump;

            // show a hole in the floor
            f.Tiles[3, 0].Drain.Visibility = System.Windows.Visibility.Visible;
            f.Tiles[4, 2].Drain.Visibility = System.Windows.Visibility.Visible;

            // user must click on the pump to activate it
            f.Tiles[2, 0].Overlay.MouseLeftButtonUp +=
                delegate
                {
                    if (f[2, 0].HasWater)
                        return;

                    f[2, 0].Input.Pump();
                };

            f.Tiles[2, 4].Overlay.MouseLeftButtonUp +=
                delegate
                {
                    if (f[2, 4].HasWater)
                        return;

                    f[2, 4].Input.Pump();
                };

            // when a user adds a pipe on top of another
            // we need to call this to force a zorder sort
            f.RefreshPipes();

            var x = (DefaultWidth - f.Tiles.Width) / 2;
            var y = (DefaultHeight - f.Tiles.Height) / 2;

            f.Container.MoveTo(x, y).AttachTo(this);

            var CurrentTile = default(SimplePipe);

            var CurrentTileCanvas = new Canvas
            {
                Width = DefaultWidth,
                Height = DefaultHeight
            }.AttachTo(this);

            var ExplosionCanvas = new Canvas
            {
                Width = DefaultWidth,
                Height = DefaultHeight
            }.AttachTo(this);

            double CurrentTileX = 0;
            double CurrentTileY = 0;

            Action CurrentTileNext =
                delegate
                {
                    CurrentTile = SimplePipe.BuildablePipes.Random()();

                    CurrentTile.Container.Opacity = 0.7;
                    CurrentTile.Container.MoveTo(CurrentTileX, CurrentTileY);
                    CurrentTile.Container.AttachTo(CurrentTileCanvas);
                    CurrentTile.OverlayBlackAnimationStart();
                };

            CurrentTileNext();

            #region overlay
            var Overlay = new Canvas
            {
                Width = DefaultWidth,
                Height = DefaultHeight,
            }.AttachTo(this);

            new Rectangle
            {
                Fill = Brushes.White,
                Width = DefaultWidth,
                Height = DefaultHeight,
                Opacity = 0
            }.AttachTo(Overlay);

            f.Tiles.Overlay.MoveTo(x, y).AttachTo(Overlay);
            #endregion

            #region IsBlockingPipe
            Func<bool> IsBlockingPipe =
                delegate
                {
                    var u = f.Tiles.FocusTile;

                    if (u != null)
                    {
                        var q = f[u];
                        if (q != null)
                        {
                            var qt = q.GetType();
                            if (!SimplePipe.BuildablePipeTypes.Any(t => t.Equals(qt)))
                            {
                                // we got a pipe on which we should not build upon
                                return true;
                            }

                        }

                        if (f.ByIndex(u.IndexX, u.IndexY).Any(k => k.Value.HasWater))
                            return true;
                    }

                    return false;
                };
            #endregion

            f.Tiles.Click +=
                Target =>
                {

                    var u = f.Tiles.FocusTile;

                    if (IsBlockingPipe())
                    {
                        // we got a pipe on which we should not build upon
                        u = null;
                    }

                    if (u != null)
                    {
                        CurrentTile.OverlayBlackAnimationStop();
                        CurrentTile.Container.Orphanize();
                        CurrentTile.Container.Opacity = 1;

                        if (f.ByIndex(Target.IndexX, Target.IndexY).Any())
                        {

                            var px = x + u.IndexX * Tile.Size + Tile.ShadowBorder;
                            var py = y + (u.IndexY + 1) * Tile.SurfaceHeight + Tile.ShadowBorder - Tile.Size;

                            new Explosion().PlayAndOrphanize().Container.MoveTo(px, py).AttachTo(ExplosionCanvas);
                        }

                        f[u] = CurrentTile;
                        f.RefreshPipes();

                        CurrentTileNext();

                    }

                };

            #region MouseMove
            this.MouseMove +=
                (Sender, Arguments) =>
                {
                    var p = Arguments.GetPosition(this);

                    var u = f.Tiles.FocusTile;

                    if (IsBlockingPipe())
                    {
                        // we got a pipe on which we should not build upon
                        u = null;
                    }

                    if (u != null)
                    {
                        p.X = x + u.IndexX * Tile.Size + Tile.ShadowBorder;
                        p.Y = y + (u.IndexY + 1) * Tile.SurfaceHeight + Tile.ShadowBorder - Tile.Size;

                        CurrentTile.Container.Opacity = 1;
                    }
                    else
                    {
                        p.X -= Tile.Size / 2;
                        p.Y -= Tile.SurfaceHeight / 2;

                        CurrentTile.Container.Opacity = 0.7;
                    }

                    CurrentTileX = p.X;
                    CurrentTileY = p.Y;
                    CurrentTile.Container.MoveTo(p.X, p.Y);
                };
            #endregion
        }
        public ColoredFieldTest()
        {
            this.Width = DefaultWidth;
            this.Height = DefaultHeight;

            var f = new ExtendedField(16, 6, DefaultWidth, DefaultHeight);

            f.Field.DefaultPipeColor = Colors.Green;

            f.Field.Tiles.Color = Colors.Pink;

            f.Container.AttachTo(this);

            #region feeder
            var feeder = new SimplePipeFeeder(6, Colors.Yellow);

            feeder.Container.AttachTo(this);

            var feeder_autohide = new SimplePipeFeeder.AutoHide(feeder, f.Overlay, DefaultWidth, DefaultHeight);

            f.Overlay.AttachTo(this);

            f.PipeToBeBuilt = feeder.Current;
            f.PipeToBeBuiltUsed +=
                delegate
                {
                    feeder.MoveNext();

                    f.PipeToBeBuilt = feeder.Current;
                };
            #endregion

            #region setting up some stuff on the field
            var Randomized = f.Field.Tiles.TileList.Randomize().GetEnumerator();

            Enumerable.Range(0, 4).ForEach(
                Index =>
                {
                    var Target = Randomized.Take();

                    Target.Drain.Show();

                    if (Index % 2 == 0)
                        f.Field[Target] = new SimplePipe.LeftToDrain();
                    else
                        f.Field[Target] = new SimplePipe.RightToDrain();
                }
            );

            var PumpTimeout = new Random();

            Enumerable.Range(0, 4).ForEach(
                Index =>
                {
                    var Target = Randomized.Take();

                    var pump = default(SimplePipe);

                    if (Index % 2 == 0)
                        pump = new SimplePipe.PumpToLeft();
                    else
                        pump = new SimplePipe.PumpToRight();

                    pump.AddTimer(PumpTimeout.Next(20, 150), pump.Input.Pump);

                    f.Field[Target] = pump;
                }
            );
            #endregion
        }
示例#4
0
        public ScrollTest()
        {
            this.Width = DefaultWidth;
            this.Height = DefaultHeight;

            this.ClipTo(0, 0, DefaultWidth, DefaultHeight);

            var f = new Field(16, 16);

            // f.Tiles.Color = Colors.Pink;
            f.Tiles.Color = Colors.Cyan;

            #region random pumps and drain holes
            var Randomized = f.Tiles.TileList.Randomize().ToArray();

            Enumerable.Range(0, f.Tiles.SizeX * f.Tiles.SizeY / 20).ForEach(
                Index =>
                {
                    var Target = Randomized[Index];
                    if (Index % 2 == 0)
                    {
                        Target.Drain.Show();

                        if (Index % 4 == 0)
                            f[Target] = new SimplePipe.LeftToDrain();
                        else
                            f[Target] = new SimplePipe.RightToDrain();

                    }
                    else
                    {
                        if (Index % 4 == 1)
                            f[Target] = new SimplePipe.PumpToLeft();
                        else
                            f[Target] = new SimplePipe.PumpToRight();
                        10000.AtDelay(f[Target].Input.Pump);
                    }
                }
            );
            #endregion

            f.Container.AttachTo(this);

            #region overlay
            var Overlay = new Canvas
            {
                Width = DefaultWidth,
                Height = DefaultHeight
            }.AttachTo(this);

            var OverlayRectangle = new Rectangle
            {
                Fill = Brushes.Black,
                Width = DefaultWidth,
                Height = DefaultHeight,
                Opacity = 0
            }.AttachTo(Overlay);

            f.Tiles.Overlay.AttachTo(Overlay);
            #endregion

            #region move the map with the mouse yet not too often anf smooth enough
            Action<int, int> MoveTo = NumericEmitter.Of(
                (x, y) =>
                {
                    f.Tiles.Overlay.MoveTo(x, y);
                    f.Container.MoveTo(x, y);
                }
            );

            Action<int, int> CalculateMoveTo =
                //Tween.NumericOmitter.Of(
                (int_x, int_y) =>
                {
                    double x = int_x;
                    double y = int_y;

                    //Console.WriteLine(new { x, y }.ToString());

                    const int PaddingX = Tile.Size / 2;
                    const int PaddingY = Tile.SurfaceHeight;

                    const int MarginLeft = Tile.ShadowBorder + Tile.Size + PaddingX;
                    const int MarginWidth = MarginLeft + Tile.ShadowBorder + Tile.Size + PaddingX;

                    const int MarginTop = Tile.ShadowBorder + Tile.SurfaceHeight + PaddingY;
                    const int MarginHeight = MarginTop + Tile.ShadowBorder + Tile.Size + PaddingY;

                    var _x = PaddingX + (DefaultWidth - (f.Tiles.Width + PaddingX * 2)) * ((x - MarginLeft).Max(0) / (DefaultWidth - MarginWidth)).Min(1);
                    var _y = PaddingY + (DefaultHeight - (f.Tiles.Height + PaddingY * 2)) * ((y - MarginTop).Max(0) / (DefaultHeight - MarginHeight)).Min(1);

                    MoveTo(Convert.ToInt32(_x), Convert.ToInt32(_y));
                }
                //)
            ;
            #endregion

            Overlay.MouseMove +=
                (Sender, Arguments) =>
                {
                    var p = Arguments.GetPosition(Overlay);

                    CalculateMoveTo(Convert.ToInt32(p.X), Convert.ToInt32(p.Y));
                };

            f.Tiles.Click +=
                Selected =>
                {
                    if (Selected == null)
                        return;

                    f[Selected] = null;

                    Selected.Hide();
                };
        }
        public SpaceInvaderTest()
        {
            this.Width = DefaultWidth;
            this.Height = DefaultHeight;

            // SpaceInvaderTest
            // http://www.glassgiant.com/ascii/
            // http://text-image.com/convert/
            // these maps could be inside a zip file

            var map = new ASCIIImage(@"
            MMMMMMM...MMMMMMMMMMMMMMMMMMM...MMMMMMMM
            MMMMMMM...MMMMMMMMMMMMMMMMMMM...MMMMMMMM
            MMMMMMMMMM    MMMMMMMMMMM    MMMMMMMMMMM
            MMMMMMMMMM    MMMMMMMMMMM    MMMMMMMMMMM
            MMMMMMM                         MMMMMMMM
            MMMMMMM                         MMMMMMMM
            MMM       MMMM           MMMM       MMMM
            MMM       MMMM           MMMM       MMMM
            MMM       MMMM           MMMM       MMMM
            ...
            ...
            ...
            ...
            ...MMMM   MMMMMMMMMMMMMMMMMMM   MMMM
            ...MMMM   MMMMMMMMMMMMMMMMMMM   MMMM
            MMMMMMMMMM        MMM.       MMMMMMMMMMM
            MMMMMMMMMM        MMM.       MMMMMMMMMMM
            MMMMMMMMMM        MMM.       MMMMMMMMMMM
            ".Trim());

            var f = new ExtendedField(map.Width, map.Height, DefaultWidth, DefaultHeight);

            f.Field.Tiles.TileList.ForEach(
                value =>
                {
                    if (map[value.IndexX, value.IndexY] == "M")
                        f.Field.Tiles[value.IndexX, value.IndexY].Hide();
                }
            );

            f.Field.DefaultPipeColor = Colors.Yellow;

            f.Field.Tiles.Color = Colors.Cyan;

            f.Container.AttachTo(this);

            #region feeder
            var feeder = new SimplePipeFeeder(6, Colors.Brown);

            feeder.Container.AttachTo(this);

            var feeder_autohide = new SimplePipeFeeder.AutoHide(feeder, f.Overlay, DefaultWidth, DefaultHeight);

            f.Overlay.AttachTo(this);

            f.PipeToBeBuilt = feeder.Current;
            f.PipeToBeBuiltUsed +=
                delegate
                {
                    feeder.MoveNext();

                    f.PipeToBeBuilt = feeder.Current;
                };
            #endregion

            #region setting up some stuff on the field
            var Randomized = f.Field.Tiles.TileList.Where(k => k.IsVisible).Randomize().GetEnumerator();

            Enumerable.Range(0, 4).ForEach(
                Index =>
                {
                    var Target = Randomized.Take();

                    Target.Drain.Show();

                    if (Index % 2 == 0)
                        f.Field[Target] = new SimplePipe.LeftToDrain();
                    else
                        f.Field[Target] = new SimplePipe.RightToDrain();
                }
            );

            var PumpTimeout = new Random();

            Enumerable.Range(0, 4).ForEach(
                Index =>
                {
                    var Target = Randomized.Take();

                    var pump = default(SimplePipe);

                    if (Index % 2 == 0)
                        pump = new SimplePipe.PumpToLeft();
                    else
                        pump = new SimplePipe.PumpToRight();

                    pump.AddTimer(PumpTimeout.Next(20, 150), pump.Input.Pump);

                    f.Field[Target] = pump;
                }
            );

            Enumerable.Range(0, 6).ForEach(
                Index =>
                {
                    var Target = Randomized.Take();

                    f.Field[Target] = new SimplePipe.BonusPickup();
                }
            );
            #endregion
        }