Exemplo n.º 1
0
        //Delete Row by preserving the rows below the one being deleted, shifting the rows, and then combining those two
        public void DeleteRow(int row)
        {
            row = Math.Abs (row);

                        BitArray preShiftedGrid = (BitArray)this.mBitArray.Clone ();
                        BitArray bottomRowsMask = new BitArray (mColumnCount * mRowCount);
                        for (int i = ((row + 1) * mColumnCount); i < (mRowCount * mColumnCount); ++i) { //bottomRowsMask = everything below full row
                                bottomRowsMask [i] = true; //-192 > -192
                        }

                        //UnityEngine.Debug.Log ("Before shift" + ++mDebugId);
                        //this.PrintBitArray ();

                        //shift - CAN'T do via mask because I don't have one consecutive array of bits in C#.
                        //They are split up across ints, which makes shifting a bitch - I still have to copy between ints
                        //(last part of int to first part of next int...), so it is easier just to use byte array.
                        for (int i = mRowCount -1; i > 0; --i) {
                                this.mRowBytes [i] = this.mRowBytes [i - 1];
                        }
                        this.mRowBytes [0] = 0; //explicitly set top row to 0s now that we shifted down
                        this.UpdateBitArrayBasedOnRowBytes ();

                        //UnityEngine.Debug.Log ("After shift" + ++mDebugId);
                        //this.PrintBitArray ();

                        BitArray topRowsMask = new BitArray (mColumnCount * mRowCount);
                        for (int i = (((row +1) * mColumnCount)-1); i >= 0; --i) { //includes the full row, and all rows above it
                                topRowsMask [i] = true;
                        }

                        TetrisGrid ans = new TetrisGrid (mRowCount, mColumnCount);
                        ans.mBitArray = (preShiftedGrid.And (bottomRowsMask)).Or (this.mBitArray.And (topRowsMask)); //
                        this.mBitArray = ans.mBitArray;

                        //UnityEngine.Debug.Log ("Answer" + ++mDebugId);
                        //ans.PrintBitArray ();
        }
Exemplo n.º 2
0
 public void Initialize(int rowCount, int columnCount)
 {
     mRowCount = rowCount;
                 mColumnCount = columnCount;
                 mPlacedShapeCount = 0;
                 mListOfShapes = new System.Collections.ArrayList ();
                 mSceneGrid = new TetrisGrid (mRowCount, mColumnCount);
 }
Exemplo n.º 3
0
        public List<int> GetFullRows()
        {
            List<int> fullRows = new List<int> ();

                        //Check for full rows using bit masks
                        for (int i = 0; i < mRowCount; ++i) {
                                TetrisGrid fullRowMask = new TetrisGrid (mRowCount, mColumnCount);
                                fullRowMask.mRowBytes [i] = Byte.MaxValue;
                                fullRowMask.UpdateBitArrayBasedOnRowBytes ();
                                BitArray clone = (BitArray)this.mBitArray.Clone (); //need to clone because AND will modify left-hand arg

                                if (fullRowMask.Equals (clone.And (fullRowMask.mBitArray)))
                                        fullRows.Add (i);
                        }

                        return fullRows;
        }