예제 #1
0
파일: Game.cs 프로젝트: dahopkin/Tetris
        } // end method GenerateBackgroundBlockGrid

        #endregion

        #region Movement Processing Methods
        /// <summary>
        /// This method moves the shape falling down on the screen left, right, or down,
        /// after checking to see if the move is possible.
        /// </summary>
        /// <param name="directionToMove">The direction to move</param>
        public void MoveCurrentShape(Direction directionToMove)
        {
            if (currentShape != null)
            {
                // copy the shape to test it.
                //Shape currentShapeCopy = currentShape.CopyShape();
                Shape currentShapeCopy = currentShape.CopyShape();
                // move the copied shape.
                switch (directionToMove)
                {
                case Direction.Right:
                    currentShapeCopy.Move(directionToMove, ShortestDistanceFromRight(currentShapeCopy));
                    break;

                case Direction.Left:
                    currentShapeCopy.Move(directionToMove, ShortestDistanceFromLeft(currentShapeCopy));
                    break;

                case Direction.Down:
                    currentShapeCopy.Move(directionToMove, ShortestDistanceFromBottom(currentShapeCopy));
                    break;
                }

                /*If the copied, moved shape is not past the boundary/overlapping a
                 * pile block, move the actual shape.*/
                if (!WouldOverlapGridBlock(currentShapeCopy) &&
                    !WouldPassLeftOrRightBorder(currentShapeCopy))
                {
                    currentShape = currentShapeCopy;
                }
            }
        } // end method MoveCurrentShape
예제 #2
0
파일: Game.cs 프로젝트: dahopkin/Tetris
        } // end method DrawNextShape

        /// <summary>
        /// This method draws the shape being held on the form.
        /// </summary>
        /// <param name="g">The graphics object to draw onto.</param>
        private void DrawHeldShape(Graphics g)
        {
            Point startPoint = new Point(
                Boundaries.Right + BlocksOver(2), Boundaries.Top + BlocksOver(6));
            string nextShapeString = "Held Shape:";
            Font   nextShapeFont   = new Font("Arial", 12, FontStyle.Bold);

            g.DrawString(nextShapeString, nextShapeFont, Brushes.Black, startPoint);
            startPoint.Y += 20;
            Size      displaySize = new Size(BlocksOver(6), BlocksOver(4));
            Rectangle background  = new Rectangle(startPoint, displaySize);

            g.FillRectangle(Brushes.Black, background);

            if (heldShape != null)
            {
                Point shapeDisplayPoint = GetShapeDisplayPoint(heldShape, background);
                Shape displayShape      = heldShape.CopyShape(shapeDisplayPoint);
                displayShape.Draw(g);
            }
        } // end method DrawHeldShape