Пример #1
0
        /// <summary>
        /// Adds the current piece to the board.
        /// </summary>
        private void addToPile()
        {
            for (int i = 0; i < shape.Length; i++)
            {
                if (board[shape[i].Position.Y, shape[i].Position.X] != Color.Transparent)
                {
                    OnGameOver();
                    return;
                }
            }


            Color shapeColor = shape[0].Colour;

            for (int i = 0; i < shape.Length; i++)
            {
                board[shape[i].Position.Y, shape[i].Position.X] = shapeColor;
            }

            int[] fullLinesCoord = checkFullLines();

            if (fullLinesCoord.Length > 0)
            {
                clearLines(fullLinesCoord);

                OnLinesCleared(fullLinesCoord.Length);
            }

            shape = shapeFactory.DeployNewShape();
        }
Пример #2
0
 public FakeBoard(int length, int width)
 {
     board        = new Color[length, width];
     shapeFactory = new ShapeProxy(this);
     shape        = shapeFactory.DeployNewShape();
     (shapeFactory as ShapeProxy).JoinPile += addToPile;
 }
Пример #3
0
        public Board(int length, int width)
        {
            if (length < 20 || width < 10)
            {
                throw new ArgumentException("Board Size is too small");
            }

            board        = new Color[length, width];
            shapeFactory = new ShapeProxy(this);
            shape        = shapeFactory.DeployNewShape();
            (shapeFactory as ShapeProxy).JoinPile += addToPile;
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Board"/> class.
        /// </summary>
        /// <param name="shapeFactory">The <see cref="ShapeFactory"/>.</param>
        public Board()
        {
            board = new Color[10, 20];
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    board[i, j] = Color.Black;
                }
            }

            ShapeProxy proxy = new ShapeProxy(this);
            shapeFactory = proxy;
            shape = proxy;

            // Event handler
            shape.JoinPile += new JoinPileHandler(addToPile);

            shapeFactory.DeployNewShape();
        }
Пример #5
0
 /// <summary>
 /// Event handler for a fired JoinPile event. Adds a shape to the board
 /// and deploys a new shape.
 /// </summary>
 private void joinPileHandler()
 {
     addToPile(shape);
     shapeFactory.DeployNewShape();
 }