Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Visible = false;
            var game = new GameField(pictureBox1);

            game.Init();
            game.Start();
        }
Пример #2
0
 public GameTab(Game game, int difficultIndex)
     : base(game)
 {
     information = new Information(this);
     nextFigure = new NextFigure(this);
     gameField = new GameField(this);
     difficult = Difficulty.getDifficult(difficultIndex);
     information.difVariant = (Difficulty.Variants)difficultIndex;
 }
Пример #3
0
        /*旋转block*/
        public void Rotate()
        {
            //保存每个小块的位置
            Point oldPosition1 = square1.location;
            Point oldPosition2 = square2.location;
            Point oldPosition3 = square3.location;
            Point oldPosition4 = square4.location;
            //保存当前的方向
            RotateDirections oldRotation = myRotation;

            //开始试着旋转方块,旋转方向:顺时针方向 旋转中心点为形状拐点
            Erase(GameField.winHandle);
            switch (blockType)
            {
            case BlockTypes.square:
                break;

            case BlockTypes.line:
                //直线的旋转只有两种方向
                switch (myRotation)
                {
                case RotateDirections.North:
                    myRotation       = RotateDirections.East;
                    square1.location = new Point(square2.location.X - squareSize, square2.location.Y);
                    square3.location = new Point(square2.location.X + squareSize, square2.location.Y);
                    square4.location = new Point(square2.location.X + 2 * squareSize, square2.location.Y);
                    break;

                case RotateDirections.East:
                    myRotation       = RotateDirections.North;
                    square1.location = new Point(square2.location.X, square2.location.Y - squareSize);
                    square3.location = new Point(square2.location.X, square2.location.Y + squareSize);
                    square4.location = new Point(square2.location.X, square2.location.Y + 2 * squareSize);
                    break;
                }
                break;

            case BlockTypes.J:
                //J形方块有四种旋转方向
                switch (myRotation)
                {
                case RotateDirections.North:
                    myRotation       = RotateDirections.East;
                    square1.location = new Point(square3.location.X + 2 * squareSize, square3.location.Y);
                    square2.location = new Point(square3.location.X + squareSize, square3.location.Y);
                    square4.location = new Point(square3.location.X, square3.location.Y - squareSize);
                    break;

                case RotateDirections.East:
                    myRotation       = RotateDirections.South;
                    square1.location = new Point(square3.location.X, square3.location.Y + 2 * squareSize);
                    square2.location = new Point(square3.location.X, square3.location.Y + squareSize);
                    square4.location = new Point(square3.location.X + squareSize, square3.location.Y);
                    break;

                case RotateDirections.South:
                    myRotation       = RotateDirections.West;
                    square1.location = new Point(square3.location.X - 2 * squareSize, square3.location.Y);
                    square2.location = new Point(square3.location.X - squareSize, square3.location.Y);
                    square4.location = new Point(square3.location.X, square3.location.Y + squareSize);
                    break;

                case RotateDirections.West:
                    myRotation       = RotateDirections.North;
                    square1.location = new Point(square3.location.X, square3.location.Y - 2 * squareSize);
                    square2.location = new Point(square3.location.X, square3.location.Y - squareSize);
                    square4.location = new Point(square3.location.X - squareSize, square3.location.Y);
                    break;
                }
                break;

            case BlockTypes.L:
                //L形方块有四种旋转方向
                switch (myRotation)
                {
                case RotateDirections.North:
                    myRotation       = RotateDirections.East;
                    square1.location = new Point(square3.location.X + 2 * squareSize, square3.location.Y);
                    square2.location = new Point(square3.location.X + squareSize, square3.location.Y);
                    square4.location = new Point(square3.location.X, square3.location.Y + squareSize);
                    break;

                case RotateDirections.East:
                    myRotation       = RotateDirections.South;
                    square1.location = new Point(square3.location.X, square3.location.Y + 2 * squareSize);
                    square2.location = new Point(square3.location.X, square3.location.Y + squareSize);
                    square4.location = new Point(square3.location.X - squareSize, square3.location.Y);
                    break;

                case RotateDirections.South:
                    myRotation       = RotateDirections.West;
                    square1.location = new Point(square3.location.X - 2 * squareSize, square3.location.Y);
                    square2.location = new Point(square3.location.X - squareSize, square3.location.Y);
                    square4.location = new Point(square3.location.X, square3.location.Y - squareSize);
                    break;

                case RotateDirections.West:
                    myRotation       = RotateDirections.North;
                    square1.location = new Point(square3.location.X, square3.location.Y - 2 * squareSize);
                    square2.location = new Point(square3.location.X, square3.location.Y - squareSize);
                    square4.location = new Point(square3.location.X + squareSize, square3.location.Y);
                    break;
                }
                break;

            case BlockTypes.T:
                //T形方块也有四种旋转方向
                switch (myRotation)
                {
                case RotateDirections.North:
                    myRotation       = RotateDirections.East;
                    square1.location = new Point(square2.location.X, square2.location.Y - squareSize);
                    square3.location = new Point(square2.location.X, square2.location.Y + squareSize);
                    square4.location = new Point(square2.location.X - squareSize, square2.location.Y);
                    break;

                case RotateDirections.East:
                    myRotation       = RotateDirections.South;
                    square1.location = new Point(square2.location.X + squareSize, square2.location.Y);
                    square3.location = new Point(square2.location.X - squareSize, square2.location.Y);
                    square4.location = new Point(square2.location.X, square2.location.Y - squareSize);
                    break;

                case RotateDirections.South:
                    myRotation       = RotateDirections.West;
                    square1.location = new Point(square2.location.X, square2.location.Y + squareSize);
                    square3.location = new Point(square2.location.X, square2.location.Y - squareSize);
                    square4.location = new Point(square2.location.X + squareSize, square2.location.Y);
                    break;

                case RotateDirections.West:
                    myRotation       = RotateDirections.North;
                    square1.location = new Point(square2.location.X - squareSize, square2.location.Y);
                    square3.location = new Point(square2.location.X + squareSize, square2.location.Y);
                    square4.location = new Point(square2.location.X, square2.location.Y + squareSize);
                    break;
                }
                break;

            case BlockTypes.Z:
                //Z形方块有两种旋转方向
                switch (myRotation)
                {
                case RotateDirections.North:
                    myRotation       = RotateDirections.East;
                    square1.location = new Point(square2.location.X, square2.location.Y - squareSize);
                    square3.location = new Point(square2.location.X - squareSize, square2.location.Y);
                    square4.location = new Point(square2.location.X - squareSize, square2.location.Y + squareSize);
                    break;

                case RotateDirections.East:
                    myRotation       = RotateDirections.North;
                    square1.location = new Point(square2.location.X - squareSize, square2.location.Y);
                    square3.location = new Point(square2.location.X, square2.location.Y + squareSize);
                    square4.location = new Point(square2.location.X + squareSize, square2.location.Y + squareSize);
                    break;
                }
                break;

            case BlockTypes.S:
                //S形方块有两种旋转方向
                switch (myRotation)
                {
                case RotateDirections.North:
                    myRotation       = RotateDirections.East;
                    square1.location = new Point(square3.location.X + squareSize, square3.location.Y + squareSize);
                    square2.location = new Point(square3.location.X + squareSize, square3.location.Y);
                    square4.location = new Point(square3.location.X, square3.location.Y - squareSize);
                    break;

                case RotateDirections.East:
                    myRotation       = RotateDirections.North;
                    square1.location = new Point(square3.location.X - squareSize, square3.location.Y + squareSize);
                    square2.location = new Point(square3.location.X, square3.location.Y + squareSize);
                    square4.location = new Point(square3.location.X + squareSize, square3.location.Y);
                    break;
                }
                break;
            }
            //旋转之后检测位置是否冲突
            if (!(GameField.isEmpty(square1.location.X / squareSize, square1.location.Y / squareSize) &&
                  GameField.isEmpty(square2.location.X / squareSize, square2.location.Y / squareSize) &&
                  GameField.isEmpty(square3.location.X / squareSize, square3.location.Y / squareSize) &&
                  GameField.isEmpty(square4.location.X / squareSize, square4.location.Y / squareSize)))
            {//如果有冲突则回到原来的状态
                myRotation       = oldRotation;
                square1.location = oldPosition1;
                square2.location = oldPosition2;
                square3.location = oldPosition3;
                square4.location = oldPosition4;
            }
            Draw(GameField.winHandle);
        }
Пример #4
0
        private void ClearLine()
        {
            int combo = 0;

            for (int i = 0; i < GameField.GetHeight(); i++)
            {
                int j;
                for (j = 0; j < GameField.GetWidth(); j++)
                {
                    if (GameField.GetDroppedShapeLocationGrid()[i, j] == 0)
                    {
                        break;
                    }
                }

                if (j == GameField.GetWidth())
                {
                    linesPicked++;
                    combo++;
                    ShowLineBlock();

                    for (j = 0; j < GameField.GetWidth(); j++)
                    {
                        GameField.GetDroppedShapeLocationGrid()[i, j] = 0;
                    }

                    int[,] newDroppedShapeLocationGrid = new int[GameField.GetHeight(), GameField.GetWidth()];
                    for (int k = 1; k < i; k++)
                    {
                        for (int l = 0; l < GameField.GetWidth(); l++)
                        {
                            newDroppedShapeLocationGrid[k + 1, l] = GameField.GetDroppedShapeLocationGrid()[k, l];
                        }
                    }

                    for (int k = 1; k < i; k++)
                    {
                        for (int l = 0; l < GameField.GetWidth(); l++)
                        {
                            GameField.GetDroppedShapeLocationGrid()[k, l] = 0;
                        }
                    }

                    for (int k = 0; k < GameField.GetHeight(); k++)
                    {
                        for (int l = 0; l < GameField.GetWidth(); l++)
                        {
                            if (newDroppedShapeLocationGrid[k, l] == 1)
                            {
                                GameField.GetDroppedShapeLocationGrid()[k, l] = 1;
                            }
                        }
                    }
                    GameField.DrawShape(this.shape);

                    if (combo == 1)
                    {
                        this.player.SetScore(this.player.GetScore() + 100);
                    }
                    else if (combo == 2)
                    {
                        this.player.SetScore(this.player.GetScore() + 300);
                    }
                    else if (combo == 3)
                    {
                        this.player.SetScore(this.player.GetScore() + 700);
                    }
                    else if (combo > 3)
                    {
                        this.player.SetScore(this.player.GetScore() + 1500);
                    }
                    ShowScoreBlock();

                    if (linesPicked < 5)
                    {
                        level = 1;
                    }
                    else if (linesPicked < 10)
                    {
                        level = 2;
                    }
                    else if (linesPicked < 15)
                    {
                        level = 3;
                    }
                    else if (linesPicked < 25)
                    {
                        level = 4;
                    }
                    else if (linesPicked < 35)
                    {
                        level = 5;
                    }
                    else if (linesPicked < 50)
                    {
                        level = 6;
                    }
                    else if (linesPicked < 70)
                    {
                        level = 7;
                    }
                    else if (linesPicked < 90)
                    {
                        level = 8;
                    }
                    else if (linesPicked < 110)
                    {
                        level = 9;
                    }
                    else if (linesPicked < 150)
                    {
                        level = 10;
                    }
                    ShowPlayerStat();
                }
            }
            dropRate = 300 - 22 * level;
        }