예제 #1
0
        private TetrisPiece(TetrisBoard board)
        {
            var maxPieceKind = Enum.GetValues(typeof(TetrisPieceKind)).Cast <int>().Max();
            var maxColor     = Enum.GetValues(typeof(TetrisFillState)).Cast <int>().Max();

            Kind   = (TetrisPieceKind)Number.Next(0, maxPieceKind + 1);
            Color  = (TetrisFillState)Number.Next(1, maxColor + 1);
            Board  = board;
            Sprite = Sprites.GetSprite(Kind, Rotation);
        }
예제 #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);
        }