Beispiel #1
0
        private void InitTetriminoArray()
        {
            if (RotateableArray.GetLength(0) != RotateableArray.GetLength(1))
            {
                throw new System.Exception("Rotateable array should be square");
            }

            var temp = RotateableArray;


            while (MultiArrayHelper.AllInColumnFalse(temp, 0))
            {
                temp = MultiArrayHelper.TrimColumn(0, temp);
                DeductedLeftRows++;
            }

            while (MultiArrayHelper.AllInRowFalse(temp, 0))
            {
                temp = MultiArrayHelper.TrimRow(0, temp);
            }

            while (MultiArrayHelper.AllInColumnFalse(temp, temp.GetLength(1) - 1))
            {
                temp = MultiArrayHelper.TrimColumn(temp.GetLength(1) - 1, temp);
            }

            while (MultiArrayHelper.AllInRowFalse(temp, temp.GetLength(0) - 1))
            {
                temp = MultiArrayHelper.TrimRow(temp.GetLength(0) - 1, temp);
            }

            TetriminoArray = temp;
        }
Beispiel #2
0
        public Tetrimino RotateCW()
        {
            //bool[,] newB = new bool[Width, Height];

            //for (int newY = 0; newY < Width; newY++)
            //{
            //    for (int newX = 0; newX < Height; newX++)
            //    {
            //        newB[newY, newX] = TetriminoArray[Height - newX - 1, newY];
            //    }
            //}
            //return new Tetrimino(newB);

            int heightHere = RotateableArray.GetLength(0);
            int widthHere  = RotateableArray.GetLength(1);

            bool[,] newB = new bool[widthHere, heightHere];

            for (int newY = 0; newY < widthHere; newY++)
            {
                for (int newX = 0; newX < heightHere; newX++)
                {
                    newB[newY, newX] = RotateableArray[heightHere - newX - 1, newY];
                }
            }
            return(new Tetrimino(newB));
        }
Beispiel #3
0
        public string ToStringRotateable()
        {
            var sb = new StringBuilder();

            for (int y = 0; y < RotateableArray.GetLength(0); y++)
            {
                for (int x = 0; x < RotateableArray.GetLength(1); x++)
                {
                    if (RotateableArray[y, x])
                    {
                        sb.Append('x');
                    }
                    else
                    {
                        sb.Append('.');
                    }
                }
                sb.AppendLine();
            }
            return(sb.ToString());
        }