Пример #1
0
 private void UpdateTheTimer(bool enabled)
 {
     timerPieceDrop.Enabled = enabled;
     if (!enabled)
     {
         btnPause.Text        = "Stopped";
         btnPause.Text        = "Game Over";
         btnPause.Enabled     = false;
         this.btnNewGame.Text = "New Game";
         stopwatch.Stop();
         this.previewPiece = null;
         this.pbPreview.Invalidate();
     }
     else
     {
         throw new Exception("UpdateTheTimer no longer being called with true");
         //btnPause.Text = "Pause";
         //btnPause.ForeColor = Color.Gray;
     }
 }
Пример #2
0
        public FallingBlocksPiece GetNextPiece()
        {
            FallingBlocksPiece piece = null;

#if TEST
            if (testPiecesNdx < testPieces.Length)
            {
                piece = testPieces[testPiecesNdx++];
            }
            else
            {
                MessageBox.Show("Test Over", "Info", MessageBoxButtons.OK);
                Environment.Exit(0);
            }
            return(piece);
#else
            int pieceType;

            pieceType = randomPiece.Next(0, NumPieces);
            while (pieceType == lastPieceType)
            {
                pieceType = randomPiece.Next(0, NumPieces); // inclusive, exclusive
            }

            switch (pieceType) // I, J, L, O, S, T, Z
            {
            case 0:
                piece = new IPiece(pieceSize, colors[pieceType]);
                break;

            case 1:
                piece = new JPiece(pieceSize, colors[pieceType]);
                break;

            case 2:
                piece = new LPiece(pieceSize, colors[pieceType]);
                break;

            case 3:
                piece = new OPiece(pieceSize, colors[pieceType]);
                break;

            case 4:
                piece = new SPiece(pieceSize, colors[pieceType]);
                break;

            case 5:
                piece = new TPiece(pieceSize, colors[pieceType]);
                break;

            case 6:
                piece = new ZPiece(pieceSize, colors[pieceType]);
                break;

            default:
                throw new Exception("pieceType out of range");
            }
            lastPieceType = pieceType;


            int column = randomColumn.Next(0, NumCols);
            piece.Translate(FallingBlocksPiece.Direction.Right, column);

            return(piece);
#endif
        }