Beispiel #1
0
        public Block(Point location,  BlockTypes newBlockType)
        {
            if (newBlockType==BlockTypes.Undefined) {
                BlockType = (BlockTypes)(random.Next(7)) + 1;
            }
            else {
                BlockType = newBlockType;
            }
            square1 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);
            square2 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);
            square3 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);
            square4 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);

            switch(BlockType) {
                case BlockTypes.Square:
                    square1.Location = new Point(location.X, location.Y);
                    square2.Location = new Point(location.X+squareSize, location.Y);
                    square3.Location = new Point(location.X, location.Y+squareSize);
                    square4.Location = new Point(location.X+squareSize, location.Y+squareSize);
                    break;
                case BlockTypes.Line:
                    square1.Location = new Point(location.X, location.Y);
                    square2.Location = new Point(location.X, location.Y+squareSize);
                    square3.Location = new Point(location.X, location.Y+2*squareSize);
                    square4.Location = new Point(location.X, location.Y+3*squareSize);
                    break;
                case BlockTypes.J:
                    square1.Location = new Point(location.X+squareSize, location.Y);
                    square2.Location = new Point(location.X+squareSize, location.Y+squareSize);
                    square3.Location = new Point(location.X+squareSize, location.Y+2*squareSize);
                    square4.Location = new Point(location.X, location.Y+2*squareSize);
                    break;
                case BlockTypes.L:
                    square1.Location = new Point(location.X, location.Y);
                    square2.Location = new Point(location.X, location.Y+squareSize);
                    square3.Location = new Point(location.X, location.Y+2*squareSize);
                    square4.Location = new Point(location.X+squareSize, location.Y+2*squareSize);
                    break;
                case BlockTypes.T:
                    square1.Location = new Point(location.X, location.Y);
                    square2.Location = new Point(location.X+squareSize, location.Y);
                    square3.Location = new Point(location.X+2*squareSize, location.Y);
                    square4.Location = new Point(location.X+squareSize, location.Y+squareSize);
                    break;
                case BlockTypes.Z:
                    square1.Location = new Point(location.X, location.Y);
                    square2.Location = new Point(location.X+squareSize, location.Y);
                    square3.Location = new Point(location.X+squareSize, location.Y+squareSize);
                    square4.Location = new Point(location.X+2*squareSize, location.Y+squareSize);
                    break;
                case BlockTypes.S:
                    square1.Location = new Point(location.X, location.Y+squareSize);
                    square2.Location = new Point(location.X+squareSize, location.Y+squareSize);
                    square3.Location = new Point(location.X+squareSize, location.Y);
                    square4.Location = new Point(location.X+2*squareSize, location.Y);
                    break;
            }
        }
 public static void StopSquare(Square square, int x, int y)
 {
     arrBitGameField[y] = arrBitGameField[y] | (1<<x);
     arrGameField[x, y] = square;
 }
        public Block(Point location,  BlockTypes newBlockType)
        {
            // Create the new block
            if (newBlockType==BlockTypes.Undefined) {
                BlockType = (BlockTypes)(random.Next(7)) + 1;
                //BlockType = BlockTypes.Line; //force line block for testing
            }
            else {
                BlockType = newBlockType;
            }
            // Create each of the squares of the block
            // Set the square colors, based on the block type
            square1 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);
            square2 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);
            square3 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);
            square4 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);

            // Set the squares positions based on the block type
            switch(BlockType) {
                case BlockTypes.Square:
                    square1.Location = new Point(location.X, location.Y);
                    square2.Location = new Point(location.X+squareSize, location.Y);
                    square3.Location = new Point(location.X, location.Y+squareSize);
                    square4.Location = new Point(location.X+squareSize, location.Y+squareSize);
                    break;
                case BlockTypes.Line:
                    square1.Location = new Point(location.X, location.Y);
                    square2.Location = new Point(location.X, location.Y+squareSize);
                    square3.Location = new Point(location.X, location.Y+2*squareSize);
                    square4.Location = new Point(location.X, location.Y+3*squareSize);
                    break;
                case BlockTypes.J:
                    square1.Location = new Point(location.X+squareSize, location.Y);
                    square2.Location = new Point(location.X+squareSize, location.Y+squareSize);
                    square3.Location = new Point(location.X+squareSize, location.Y+2*squareSize);
                    square4.Location = new Point(location.X, location.Y+2*squareSize);
                    break;
                case BlockTypes.L:
                    square1.Location = new Point(location.X, location.Y);
                    square2.Location = new Point(location.X, location.Y+squareSize);
                    square3.Location = new Point(location.X, location.Y+2*squareSize);
                    square4.Location = new Point(location.X+squareSize, location.Y+2*squareSize);
                    break;
                case BlockTypes.T:
                    square1.Location = new Point(location.X, location.Y);
                    square2.Location = new Point(location.X+squareSize, location.Y);
                    square3.Location = new Point(location.X+2*squareSize, location.Y);
                    square4.Location = new Point(location.X+squareSize, location.Y+squareSize);
                    break;
                case BlockTypes.Z:
                    square1.Location = new Point(location.X, location.Y);
                    square2.Location = new Point(location.X+squareSize, location.Y);
                    square3.Location = new Point(location.X+squareSize, location.Y+squareSize);
                    square4.Location = new Point(location.X+2*squareSize, location.Y+squareSize);
                    break;
                case BlockTypes.S:
                    square1.Location = new Point(location.X, location.Y+squareSize);
                    square2.Location = new Point(location.X+squareSize, location.Y+squareSize);
                    square3.Location = new Point(location.X+squareSize, location.Y);
                    square4.Location = new Point(location.X+2*squareSize, location.Y);
                    break;
            }
        }
Beispiel #4
0
        public Block(Point location, BlockTypes newBlockType)
        {
            // Create the new block
            if (newBlockType == BlockTypes.Undefined)
            {
                BlockType = (BlockTypes)(random.Next(7)) + 1;
                //Alternately, comment the above line and use the line below
                // to force a line block for testing
                //BlockType = BlockTypes.Line;
            }
            else
            {
                BlockType = newBlockType;
            }
            // Create each of the squares of the block
            // Set the square colors, based on the block type
            square1 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);
            square2 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);
            square3 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);
            square4 = new Square(new Size(squareSize, squareSize), backColors[(int)BlockType], foreColors[(int)BlockType]);

            // Set the squares positions based on the block type
            switch (BlockType)
            {
            case BlockTypes.Square:
                square1.Location = new Point(location.X, location.Y);
                square2.Location = new Point(location.X + squareSize, location.Y);
                square3.Location = new Point(location.X, location.Y + squareSize);
                square4.Location = new Point(location.X + squareSize, location.Y + squareSize);
                break;

            case BlockTypes.Line:
                square1.Location = new Point(location.X, location.Y);
                square2.Location = new Point(location.X, location.Y + squareSize);
                square3.Location = new Point(location.X, location.Y + 2 * squareSize);
                square4.Location = new Point(location.X, location.Y + 3 * squareSize);
                break;

            case BlockTypes.J:
                square1.Location = new Point(location.X + squareSize, location.Y);
                square2.Location = new Point(location.X + squareSize, location.Y + squareSize);
                square3.Location = new Point(location.X + squareSize, location.Y + 2 * squareSize);
                square4.Location = new Point(location.X, location.Y + 2 * squareSize);
                break;

            case BlockTypes.L:
                square1.Location = new Point(location.X, location.Y);
                square2.Location = new Point(location.X, location.Y + squareSize);
                square3.Location = new Point(location.X, location.Y + 2 * squareSize);
                square4.Location = new Point(location.X + squareSize, location.Y + 2 * squareSize);
                break;

            case BlockTypes.T:
                square1.Location = new Point(location.X, location.Y);
                square2.Location = new Point(location.X + squareSize, location.Y);
                square3.Location = new Point(location.X + 2 * squareSize, location.Y);
                square4.Location = new Point(location.X + squareSize, location.Y + squareSize);
                break;

            case BlockTypes.Z:
                square1.Location = new Point(location.X, location.Y);
                square2.Location = new Point(location.X + squareSize, location.Y);
                square3.Location = new Point(location.X + squareSize, location.Y + squareSize);
                square4.Location = new Point(location.X + 2 * squareSize, location.Y + squareSize);
                break;

            case BlockTypes.S:
                square1.Location = new Point(location.X, location.Y + squareSize);
                square2.Location = new Point(location.X + squareSize, location.Y + squareSize);
                square3.Location = new Point(location.X + squareSize, location.Y);
                square4.Location = new Point(location.X + 2 * squareSize, location.Y);
                break;
            }
        }