コード例 #1
0
    // set ups rotation point and coordinates(relative to the center of tetramino) of cells that form a tetromino
    public Tetramino(TetraminoType type)
    {
        this.type = type;
        switch (type)
        {
        case TetraminoType.I:
            Poses = GetPoses(new int[4, 2] {
                { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 }
            });
            rotationPoint = new Vector2(3f / 2f, -1f / 2f);
            break;

        case TetraminoType.J:
            Poses = GetPoses(new int[4, 2] {
                { 0, 0 }, { 1, 0 }, { 1, 1 }, { 1, 2 }
            });
            rotationPoint = new Vector2(1f, 1f);
            break;

        case TetraminoType.L:
            Poses = GetPoses(new int[4, 2] {
                { 0, 0 }, { 1, 0 }, { 0, 1 }, { 0, 2 }
            });
            rotationPoint = new Vector2(0f, 1f);
            break;

        case TetraminoType.O:
            Poses = GetPoses(new int[4, 2] {
                { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 }
            });
            rotationPoint = new Vector2(1f / 2f, 1f / 2f);
            break;

        case TetraminoType.S:
            Poses = GetPoses(new int[4, 2] {
                { 0, 0 }, { 1, 0 }, { 1, 1 }, { 2, 1 }
            });
            rotationPoint = new Vector2(1f, 0f);
            break;

        case TetraminoType.T:
            Poses = GetPoses(new int[4, 2] {
                { 1, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }
            });
            rotationPoint = new Vector2(1f, 1f);
            break;

        case TetraminoType.Z:
            Poses = GetPoses(new int[4, 2] {
                { 0, 1 }, { 1, 1 }, { 1, 0 }, { 2, 0 }
            });
            rotationPoint = new Vector2(1f, 0f);
            break;

        default:
            Debug.LogError("Unsupported tetramino type: " + type);
            break;
        }
    }
コード例 #2
0
    public void SpawnNext()
    {
        TetraminoType type = (TetraminoType)Random.Range(0, 7);

        tetramino.GetComponent <Tetramino>().SetType(type);

        nextTetramino = Instantiate(tetramino, Vector3.zero, Quaternion.identity);
    }
コード例 #3
0
        private void TimerTick(object sender, EventArgs e)
        {
            if (Cells == null)
            {
                //GetNextTetramino();
                currentType = TetraminoTypeGenerator.GetTetraminoType(tetraminoCounter++);
                if (!GenerateTetramino())
                {
                    //game over
                    _tmr.Stop();
                    _notificate(GameEvent.GameOver);
                }
                else
                {
                    _notificate(GameEvent.CreateNewTetramino);
                }
            }
            else
            {
                //todo user input here
                switch (_input())
                {
                case Move.Left:
                    MoveLeft();
                    break;

                case Move.Right:
                    MoveRight();
                    break;

                case Move.Rotate:
                    Rotate(true);
                    break;
                }

                if (timerCounter > (500 - ((GameSpeed - 1) * 50)))
                {
                    timerCounter = 0;

                    if (!MoveDown())
                    {
                        Cells = null;

                        CheckCompleteRow();
                    }
                }
                else
                {
                    timerCounter += 33;
                }
            }
        }
コード例 #4
0
        private static void GenerateBag()
        {
            TetraminoType[] newBag = new TetraminoType[7];
            //shuffle bag
            for (int i = 0; i < bag.Length; i++)
            {
                int           index = rnd.Next(i, bag.Length);
                TetraminoType tmp   = bag[index];
                bag[index] = bag[i];
                bag[i]     = tmp;
            }

            for (int i = 0; i < bag.Length; i++)
            {
                newBag[i] = bag[i];
            }

            listOfBag.Add(newBag);
        }
コード例 #5
0
        private void GetNextTetramino()
        {
            if (bagIndex >= bag.Length)
            {
                bagIndex = 0;
            }

            if (bagIndex == 0)
            {
                //shuffle bag
                for (int i = 0; i < bag.Length; i++)
                {
                    int           index = rnd.Next(i, bag.Length);
                    TetraminoType tmp   = bag[index];
                    bag[index] = bag[i];
                    bag[i]     = tmp;
                }
            }

            currentType = bag[bagIndex++];
        }
コード例 #6
0
    public GameObject GetTileByType(TetraminoType tetramino)
    {
        GameObject tile = null;

        switch (tetramino)
        {
        case TetraminoType.I:
            tile = _cyanTile;
            break;

        case TetraminoType.J:
            tile = _blueTile;
            break;

        case TetraminoType.L:
            tile = _orangeTile;
            break;

        case TetraminoType.O:
            tile = _yellowTile;
            break;

        case TetraminoType.S:
            tile = _greenTile;
            break;

        case TetraminoType.T:
            tile = _purpleTile;
            break;

        case TetraminoType.Z:
            tile = _redTile;
            break;
        }

        return(tile);
    }
コード例 #7
0
 // sets up rotation point and tetramino's cells coordinates
 // also sets up tetramino's type
 public Tetramino(TetraminoType type)
 {
     Builder.SetUp(this, type);
 }
コード例 #8
0
ファイル: Tetramino.cs プロジェクト: indivisibleman/Tetris
 public void SetType(TetraminoType type)
 {
     this.type = type;
 }
コード例 #9
0
ファイル: TetrisManager.cs プロジェクト: sonic1003/Tetris
 public void SpawnBlock()
 {
     TetraminoType tetramino = GetRandomType();
 }
コード例 #10
0
 public Color GetColor(TetraminoType type)
 {
     return(typeToColor[type]);
 }
コード例 #11
0
 public Vector3 GetOffset(TetraminoType type)
 {
     return(typeToOffset[type]);
 }
コード例 #12
0
 public int[,,] GetShapes(TetraminoType type)
 {
     return(typeToShapes[type]);
 }
コード例 #13
0
ファイル: Tetramino.cs プロジェクト: sonic1003/Tetris
 public Tetramino(TetraminoType type, Vector2[] coord)
 {
     this.Type  = type;
     this.coord = coord;
 }