Пример #1
0
        private void SpawnPiece()
        {
            CurrentPiece = TetrisPiece.Spawn(this);

            if (CurrentPiece == null)
            {
                State = TetrisBoardState.Stopped;
                GameLost?.Invoke(this, EventArgs.Empty);
                return;
            }

            CurrentPiece.Draw();
        }
Пример #2
0
        public static TetrisPiece Spawn(TetrisBoard board)
        {
            var piece     = new TetrisPiece(board);
            var possibleX = new List <int>(board.Width);

            for (var x = 0; x < board.Width; x++)
            {
                if (TestBounds(board, piece.Sprite, x, 0))
                {
                    possibleX.Add(x);
                }
            }

            // No more space to place items!
            if (possibleX.Count <= 0)
            {
                return(null);
            }

            var selectedX = Number.Next(0, possibleX.Count);

            piece.Move(possibleX[selectedX], 0);
            return(piece);
        }