Ejemplo n.º 1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            board.insertionPoint = new PointF(this.Attributes.Pivot.X - (float)((board.columns / 2.0) * board.cellSize), this.Attributes.Pivot.Y + 20);


            Grasshopper.Instances.ActiveCanvas.CanvasPaintBackground -= canvasPaintHandler;
            Grasshopper.Instances.ActiveCanvas.CanvasPaintBackground += canvasPaintHandler;

            if (board.gameActive)
            {
                if (Keyboard.IsKeyDown(Key.Right))
                {
                    Thread.Sleep(50);
                    board.activepiece.MoveRight();
                }

                if (Keyboard.IsKeyDown(Key.Left))
                {
                    Thread.Sleep(50);
                    board.activepiece.MoveLeft();
                }

                if (Keyboard.IsKeyDown(Key.Down))
                {
                    Thread.Sleep(50);
                    board.activepiece.MoveDown();
                }

                if (Keyboard.IsKeyDown(Key.Up))
                {
                    Thread.Sleep(50);
                    board.activepiece.Rotate();
                }

                board.CheckForFullRows();
            }

            else
            {
                if (Keyboard.IsKeyDown(Key.Enter))
                {
                    this.board             = new TetrisBoard(Grasshopper.Instances.ActiveCanvas, 20, 10, 35);
                    this.board.activepiece = board.NewRandomPiece();
                    board.insertionPoint   = new PointF(this.Attributes.Pivot.X - (float)((board.columns / 2.0) * board.cellSize), this.Attributes.Pivot.Y + 20);
                }
            }


            ExpireSolution(true);
        }
Ejemplo n.º 2
0
        public RussianInterlocking()
            : base("Russian Interlocking", "Tetris",
                   "Move with arrows, rotate with arrow up, reset with enter",
                   "Interlocking System", "Components")
        {
            board             = new TetrisBoard(Grasshopper.Instances.ActiveCanvas, 20, 10, 35);
            board.activepiece = board.NewRandomPiece();

            //Change the panning function froms the arrows to WASD keys so arrows can be use to play

            Grasshopper.GUI.Canvas.GH_Canvas.NavigationPanRight = System.Windows.Forms.Keys.A;
            Grasshopper.GUI.Canvas.GH_Canvas.NavigationPanLeft  = System.Windows.Forms.Keys.D;
            Grasshopper.GUI.Canvas.GH_Canvas.NavigationPanDown  = System.Windows.Forms.Keys.W;
            Grasshopper.GUI.Canvas.GH_Canvas.NavigationPanUp    = System.Windows.Forms.Keys.S;
        }