Beispiel #1
0
        public Block(Point thisLocation,BlockTypes bType)
        { //当blockType为undefined时,随机产生方块形状
            Random rand=new Random();
            if (bType == BlockTypes.undefined)
            {
                blockType = (BlockTypes)(rand.Next(7) + 1);
            }
            else
                blockType = bType;
            //设置四小方块的颜色
            int i=(int)blockType-1;
            foreColor = GameField.BlockForeColor[i];
            backColor = GameField.BlockBackColor[i];
            Size squareS=new Size(squareSize,squareSize);
            square1 = new Square(squareS, foreColor, backColor);
            square2 = new Square(squareS, foreColor, backColor);
            square3 = new Square(squareS, foreColor, backColor);
            square4 = new Square(squareS, foreColor, backColor);

            //设置小方块的位置,组合成指定形状的一个大方块
            switch (blockType)
            {
                case BlockTypes.square:
                    //组合成正方形
                    square1.location = new Point(thisLocation.X, thisLocation.Y);
                    square2.location = new Point(thisLocation.X + squareSize, thisLocation.Y);
                    square3.location = new Point(thisLocation.X,thisLocation.Y+squareSize);
                    square4.location = new Point(thisLocation.X+squareSize,thisLocation.Y+squareSize);
                    break;
                case BlockTypes.line:
                    //组合成线形
                    square1.location = new Point(thisLocation.X, thisLocation.Y);
                    square2.location = new Point(thisLocation.X + squareSize, thisLocation.Y);
                    square3.location = new Point(thisLocation.X + 2 * squareSize, thisLocation.Y);
                    square4.location = new Point(thisLocation.X + 3 * squareSize, thisLocation.Y);
                    break;
                case BlockTypes.J:
                    //组合成J形
                    square1.location = new Point(thisLocation.X + squareSize, thisLocation.Y);
                    square2.location = new Point(thisLocation.X + squareSize, thisLocation.Y + squareSize);
                    square3.location = new Point(thisLocation.X + squareSize, thisLocation.Y + 2 * squareSize);
                    square4.location = new Point(thisLocation.X, thisLocation.Y + 2 * squareSize);
                    break;
                case BlockTypes.L:
                    //组合成l形
                    square1.location = new Point(thisLocation.X, thisLocation.Y);
                    square2.location = new Point(thisLocation.X, thisLocation.Y + squareSize);
                    square3.location = new Point(thisLocation.X, thisLocation.Y + 2 * squareSize);
                    square4.location = new Point(thisLocation.X + squareSize, thisLocation.Y + 2 * squareSize);
                    break;
                case BlockTypes.T:
                    //组合成T形
                    square1.location = new Point(thisLocation.X, thisLocation.Y);
                    square2.location = new Point(thisLocation.X + squareSize, thisLocation.Y);
                    square3.location = new Point(thisLocation.X + 2*squareSize, thisLocation.Y);
                    square4.location = new Point(thisLocation.X + squareSize, thisLocation.Y +squareSize);
                    break;
                case BlockTypes.Z:
                    //组合成z形
                    square1.location = new Point(thisLocation.X, thisLocation.Y);
                    square2.location = new Point(thisLocation.X + squareSize, thisLocation.Y);
                    square3.location = new Point(thisLocation.X + squareSize, thisLocation.Y + squareSize);
                    square4.location = new Point(thisLocation.X + 2*squareSize, thisLocation.Y + squareSize);
                    break;
                case BlockTypes.S:
                    //组合成S形
                    square1.location = new Point(thisLocation.X, thisLocation.Y + squareSize);
                    square2.location = new Point(thisLocation.X + squareSize, thisLocation.Y + squareSize);
                    square3.location = new Point(thisLocation.X + squareSize, thisLocation.Y);
                    square4.location = new Point(thisLocation.X + 2 * squareSize, thisLocation.Y);
                    break;
            }
        }
Beispiel #2
0
 /*将方块停住*/
 public static void stopSquare(Square sq, int x, int y)
 {
     arriveBlock[x, y] = sq;
     arrBitBlock[y]=arrBitBlock[y]|(1<<x);
 }