Exemple #1
0
        //随机创建方块方法
        //
        public void ProduceBrick()
        {
            //随机决定形状、方向
            Random r = new Random();

            brickShape = (E_BrickShape)r.Next(0, 7);
            dir        = r.Next(1, 5);

            //重置位置信息
            instantPos = new Position(Game.w / 2, 2);

            //创建方块信息对象
            brickInfo = new BrickInfo(brickShape, dir, instantPos);

            //获取方块信息,创建方块并打印
            for (int i = 0; i < bricks.Length; i++)
            {
                bricks[i] = new GameObject(brickInfo.positions[i]);
            }
            Print();
        }
Exemple #2
0
        //改变方块位置、方向
        //
        public void Move(E_BrickShape brickShape, int dir, Position oriPos)
        {
            positions[0] = oriPos;
            switch (brickShape)
            {
            case E_BrickShape.a:
                Console.ForegroundColor = ConsoleColor.Blue;
                positions[1]            = new Position(oriPos.posX, oriPos.posY + 1);
                positions[2]            = new Position(oriPos.posX + 2, oriPos.posY + 1);
                positions[3]            = new Position(oriPos.posX + 2, oriPos.posY);
                break;

            case E_BrickShape.b:
                Console.ForegroundColor = ConsoleColor.Magenta;
                switch (dir)
                {
                case 1:
                    positions[1] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[2] = new Position(oriPos.posX, oriPos.posY + 2);
                    positions[3] = new Position(oriPos.posX, oriPos.posY - 1);
                    break;

                case 2:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX - 4, oriPos.posY);
                    positions[3] = new Position(oriPos.posX + 2, oriPos.posY);
                    break;

                case 3:
                    positions[1] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[2] = new Position(oriPos.posX, oriPos.posY - 2);
                    positions[3] = new Position(oriPos.posX, oriPos.posY - 1);
                    break;

                case 4:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX + 2, oriPos.posY);
                    positions[3] = new Position(oriPos.posX + 4, oriPos.posY);
                    break;

                default:
                    break;
                }
                break;

            case E_BrickShape.c:
                Console.ForegroundColor = ConsoleColor.Green;
                switch (dir)
                {
                case 1:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[3] = new Position(oriPos.posX + 2, oriPos.posY);
                    break;

                case 2:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[3] = new Position(oriPos.posX, oriPos.posY - 1);
                    break;

                case 3:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX + 2, oriPos.posY);
                    positions[3] = new Position(oriPos.posX, oriPos.posY - 1);
                    break;

                case 4:
                    positions[1] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[2] = new Position(oriPos.posX + 2, oriPos.posY);
                    positions[3] = new Position(oriPos.posX, oriPos.posY - 1);
                    break;

                default:
                    break;
                }
                break;

            case E_BrickShape.d:
                Console.ForegroundColor = ConsoleColor.Cyan;
                switch (dir)
                {
                case 1:
                    positions[1] = new Position(oriPos.posX + 2, oriPos.posY + 1);
                    positions[2] = new Position(oriPos.posX + 2, oriPos.posY);
                    positions[3] = new Position(oriPos.posX, oriPos.posY - 1);
                    break;

                case 2:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY + 1);
                    positions[2] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[3] = new Position(oriPos.posX + 2, oriPos.posY);
                    break;

                case 3:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[3] = new Position(oriPos.posX - 2, oriPos.posY - 1);
                    break;

                case 4:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX + 2, oriPos.posY - 1);
                    positions[3] = new Position(oriPos.posX, oriPos.posY - 1);
                    break;

                default:
                    break;
                }
                break;

            case E_BrickShape.e:
                Console.ForegroundColor = ConsoleColor.Cyan;
                switch (dir)
                {
                case 1:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX - 2, oriPos.posY + 1);
                    positions[3] = new Position(oriPos.posX, oriPos.posY - 1);
                    break;

                case 2:
                    positions[1] = new Position(oriPos.posX + 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX, oriPos.posY - 1);
                    positions[3] = new Position(oriPos.posX - 2, oriPos.posY - 1);
                    break;

                case 3:
                    positions[1] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[2] = new Position(oriPos.posX + 2, oriPos.posY);
                    positions[3] = new Position(oriPos.posX + 2, oriPos.posY - 1);
                    break;

                case 4:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[3] = new Position(oriPos.posX + 2, oriPos.posY + 1);
                    break;

                default:
                    break;
                }
                break;

            case E_BrickShape.f:
                Console.ForegroundColor = ConsoleColor.Yellow;
                switch (dir)
                {
                case 1:
                    positions[1] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[2] = new Position(oriPos.posX, oriPos.posY - 1);
                    positions[3] = new Position(oriPos.posX - 2, oriPos.posY - 1);
                    break;

                case 2:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX + 2, oriPos.posY);
                    positions[3] = new Position(oriPos.posX + 2, oriPos.posY - 1);
                    break;

                case 3:
                    positions[1] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[2] = new Position(oriPos.posX + 2, oriPos.posY + 1);
                    positions[3] = new Position(oriPos.posX, oriPos.posY - 1);
                    break;

                case 4:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX - 2, oriPos.posY + 1);
                    positions[3] = new Position(oriPos.posX + 2, oriPos.posY);
                    break;

                default:
                    break;
                }
                break;

            case E_BrickShape.g:
                Console.ForegroundColor = ConsoleColor.Yellow;
                switch (dir)
                {
                case 1:
                    positions[1] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[2] = new Position(oriPos.posX + 2, oriPos.posY - 1);
                    positions[3] = new Position(oriPos.posX, oriPos.posY - 1);
                    break;

                case 2:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX + 2, oriPos.posY + 1);
                    positions[3] = new Position(oriPos.posX + 2, oriPos.posY);
                    break;

                case 3:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY + 1);
                    positions[2] = new Position(oriPos.posX, oriPos.posY + 1);
                    positions[3] = new Position(oriPos.posX, oriPos.posY - 1);
                    break;

                case 4:
                    positions[1] = new Position(oriPos.posX - 2, oriPos.posY);
                    positions[2] = new Position(oriPos.posX + 2, oriPos.posY);
                    positions[3] = new Position(oriPos.posX - 2, oriPos.posY - 1);
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }

            //更新方块的下位置极值
            for (int i = 0; i < positions.Length; i++)
            {
                if (i == 0)
                {
                    bottomposY = positions[i].posY;
                }
                else
                {
                    if (positions[i].posY > bottomposY)
                    {
                        bottomposY = positions[i].posY;
                    }
                }
            }
        }
Exemple #3
0
 public BrickInfo(E_BrickShape brickShape, int dir, Position oriPos)
 {
     Move(brickShape, dir, oriPos);
 }