Beispiel #1
0
    private void GenerateNextType()
    {
        // Get Next Shape
        if (GameplayManager.GetInstance().SingleTypeMode)
        {
            // Custom pieces mode
            _NextType = _CustomMoveSequence[_MoveSequence_Index];

            // Increase index for next shape
            _MoveSequence_Index++;
            // If reached end of line, shuffle and reset
            if (_MoveSequence_Index == _CustomMoveSequence.Length)
            {
                ShuffleMoveSequence(ref _CustomMoveSequence);
                _MoveSequence_Index = 0;
            }
        }
        else
        {
            // Normal pieces mode
            _NextType = _MoveSequence[_MoveSequence_Index];

            // Increase index for next shape
            _MoveSequence_Index++;
            // If reached end of line, shuffle and reset
            if (_MoveSequence_Index == (int)Tetrominoes.TOTAL)
            {
                ShuffleMoveSequence(ref _MoveSequence);
                _MoveSequence_Index = 0;
            }
        }
    }
Beispiel #2
0
 //設定方塊的形狀
 public void setShape(Tetrominoes shape, Color color)
 {
     pieceShape = shape;
     pieceColor = color;
     width      = lenTable[(int)shape][0];
     height     = lenTable[(int)shape][1];
     shapeNow   = shapeTable[(int)shape][angle];
 }
Beispiel #3
0
 private void ShuffleMoveSequence(ref Tetrominoes[] Sequence)
 {
     for (int i = 0; i < Sequence.Length; i++)
     {
         int         random_index = UnityEngine.Random.Range(0, Sequence.Length);
         Tetrominoes Temp         = Sequence[i];
         Sequence[i]            = Sequence[random_index];
         Sequence[random_index] = Temp;
     }
 }
Beispiel #4
0
 //用Brick來初始化一個Brick
 //主要用在方塊向左、右、下移動時,先創一個新方塊偵測有沒有重疊
 public Brick(Brick b)
 {
     pieceShape = b.getShapeType();
     pieceColor = b.pieceColor;
     this.setX(b.getX()); this.setY(b.getY());
     angle    = b.getAngle();
     width    = b.getWidth();
     height   = b.getHeight();
     shapeNow = b.getShape();
 }
        public override void Direct(Tetrominoes mino)
        {
            switch (mino)
            {
            case Tetrominoes.I:
                builder.Textures[0, 0] = Texture;
                builder.Textures[0, 1] = Texture;
                builder.Textures[0, 2] = Texture;
                builder.Textures[0, 3] = Texture;
                break;

            case Tetrominoes.O:
                builder.Textures[0, 0] = Texture;
                builder.Textures[0, 1] = Texture;
                builder.Textures[1, 0] = Texture;
                builder.Textures[1, 1] = Texture;
                break;

            case Tetrominoes.T:
                builder.Textures[0, 1] = Texture;
                builder.Textures[1, 0] = Texture;
                builder.Textures[1, 1] = Texture;
                builder.Textures[1, 2] = Texture;
                break;

            case Tetrominoes.S:
                builder.Textures[0, 1] = Texture;
                builder.Textures[0, 2] = Texture;
                builder.Textures[1, 0] = Texture;
                builder.Textures[1, 1] = Texture;
                break;

            case Tetrominoes.Z:
                builder.Textures[0, 0] = Texture;
                builder.Textures[0, 1] = Texture;
                builder.Textures[1, 1] = Texture;
                builder.Textures[1, 2] = Texture;
                break;

            case Tetrominoes.J:
                builder.Textures[0, 0] = Texture;
                builder.Textures[1, 0] = Texture;
                builder.Textures[1, 1] = Texture;
                builder.Textures[1, 2] = Texture;
                break;

            case Tetrominoes.L:
                builder.Textures[0, 2] = Texture;
                builder.Textures[1, 0] = Texture;
                builder.Textures[1, 1] = Texture;
                builder.Textures[1, 2] = Texture;
                break;
            }
        }
Beispiel #6
0
    public void BecomeNewPiece()
    {
        // First Value workaround
        if (_NextType == Tetrominoes.NONE)
        {
            GenerateNextType();
        }

        _Type = _NextType;
        GenerateNextType();
        //_Type = Tetrominoes.I;
        UpdateColor();

        // Set Orientation
        if (GameplayManager.GetInstance().SpawnRotationIsRandom)
        {
            _Orientation = (Orientation)UnityEngine.Random.Range(0, 4);
        }
        else
        {
            _Orientation = Orientation.UP;
        }

        _x = TetrisBoard._Width / 2;
        _y = TetrisBoard._Height - 1;

        // Set position randomly instead
        if (GameplayManager.GetInstance().SpawnXPositionIsRandom)
        {
            _x = UnityEngine.Random.Range(0, TetrisBoard._Width - 1);

            // Update Actual Piece Position (ignore min/max)
            UpdatePiece();

            // Min Fix
            if (_WorldMin.x < 0)
            {
                _x -= (int)_WorldMin.x;
            }
            // Max Fix
            if (_WorldMax.x > (TetrisBoard._Width - 1))
            {
                _x -= ((int)_WorldMax.x - (TetrisBoard._Width - 1));
            }
        }

        // Update Actual Piece Position
        UpdatePiece();
    }
    // Spawn a new tetromino at the top of the screen
    void SpawnTetromino(int tetrominoIndex)
    {
        if (!dead)
        {
            buttonInfo.softDropCounter = 0;
            nextTetrominoIndex         = UnityEngine.Random.Range(1, 8);

            tetrominoPool          = Tetrominoes.GetTetrominoFromIndex(tetrominoIndex);
            currentTetrominoState  = Slicer3D(tetrominoPool, 0);
            rotationState          = 0;
            currentTetrominoPos[0] = 3;
            currentTetrominoPos[1] = 18;

            tetrominoSpawned?.Invoke();
        }
    }
Beispiel #8
0
    void UpdateTetrominoHolder()
    {
        foreach (Transform child in obj.nextTetrominoHolder)
        {
            Destroy(child.gameObject);
        }

        int[,,] tetrominoPool = Tetrominoes.GetTetrominoFromIndex(engine.nextTetrominoIndex);

        for (int x = 0; x < 4; x++)
        {
            for (int y = 0; y < 4; y++)
            {
                if (engine.Slicer3D(tetrominoPool, 0)[x, y] != 0)
                {
                    Vector2    spawnPos = new Vector2(obj.nextTetrominoHolder.position.x - 2 + x, obj.nextTetrominoHolder.position.y - 1 + y);
                    GameObject newTile  = Instantiate(obj.tileObj, spawnPos, Quaternion.identity);
                    newTile.GetComponent <TileRenderer>().isNext = true;
                    newTile.transform.parent = obj.nextTetrominoHolder;
                    newTile.GetComponent <TileRenderer>().engine = engine;
                }
            }
        }
    }
Beispiel #9
0
        private void drawSquare(Graphics g, int x, int y, Tetrominoes shape)
        {
            //    Color colors[] = { new Color(0, 0, 0), new Color(204, 102, 102),
            //    new Color(102, 204, 102), new Color(102, 102, 204),
            //    new Color(204, 204, 102), new Color(204, 102, 204),
            //    new Color(102, 204, 204), new Color(218, 170, 0)
            //};


            //Color color = colors[shape.ordinal()];

            //g.setColor(color);
            //g.fillRect(x + 1, y + 1, squareWidth() - 2, squareHeight() - 2);

            //g.setColor(color.brighter());
            //g.drawLine(x, y + squareHeight() - 1, x, y);
            //g.drawLine(x, y, x + squareWidth() - 1, y);

            //g.setColor(color.darker());
            //g.drawLine(x + 1, y + squareHeight() - 1,
            //                 x + squareWidth() - 1, y + squareHeight() - 1);
            //g.drawLine(x + squareWidth() - 1, y + squareHeight() - 1,
            //                 x + squareWidth() - 1, y + 1);
        }
Beispiel #10
0
 public virtual void Direct(Tetrominoes mino)
 {
     throw new NotImplementedException($"{nameof(TetrominoBuildDirectorBase)}::{nameof(Direct)}: Not-Implemented Exception");
 }
 public override Tetromino Get(Tetrominoes mino)
 {
     return(Minoes[(int)mino]);
 }
Beispiel #12
0
 public virtual Tetromino Get(Tetrominoes mino)
 {
     throw new NotImplementedException($"{nameof(TetrominoCollectionBase)}::{nameof(Get)}: Not-Implemented Exception");
 }
Beispiel #13
0
 public Brick()
 {
     width      = 0; height = 0; angle = 0;
     x          = 5; y = 0;
     pieceShape = Tetrominoes.NoShape;
 }
 public void RowClearScore(List <int> rows)
 {
     score += Tetrominoes.ComboMultiplier(rows.Count) * (level + 1);
     lines += rows.Count;
     CheckLevel();
 }
Beispiel #15
0
 public override void Direct(Tetrominoes mino)
 {
     base.Direct(mino);
 }