示例#1
0
        public Tuple <int, int> canRotate(TetrisGrid grid, bool clockwise)
        {
            byte v;
            bool passing = true;
            int  target;

            if (clockwise)
            {
                target = (Rotation + 1) % 4;
            }
            else
            {
                if (Rotation - 1 < 0)
                {
                    target = 3;
                }
                else
                {
                    target = Rotation - 1;
                }
            }
            BlockTester tester = new BlockTester(0, 0, (float)Tetrimino.Size.Width, (float)Tetrimino.Size.Height);

            foreach (Tuple <int, int> kick in TetriminoKicks[Util.rotation_id(target, clockwise)])
            {
                passing = true;
                for (int i = 0; i < TetriminoLayout.GetLength(1); i++)
                {
                    for (int j = 0; j < TetriminoLayout.GetLength(2); j++)
                    {
                        v = TetriminoLayout[target, i, j];
                        if (v == 0)
                        {
                            continue;
                        }

                        tester.X = i * ((float)Tetrimino.Size.Width) + (kick.Item1 * (float)Tetrimino.Size.Width) + this.x();
                        tester.Y = j * ((float)Tetrimino.Size.Height) + (kick.Item2 * (float)Tetrimino.Size.Height) + this.y();
                        if (grid.isCollision(tester))
                        {
                            passing = false;
                            break;
                        }
                    }
                    if (passing == false)
                    {
                        break;
                    }
                }
                if (passing == true)
                {
                    return(kick);
                }
            }
            return(null);
        }
示例#2
0
        public bool isCollision(TetrisBlock block, float offX, float offY)
        {
            BlockTester tester;

            foreach (var tetrimino in block.Tetriminos)
            {
                tester = new BlockTester(tetrimino.x() + offX, tetrimino.y() + offY, (float)Tetrimino.Size.Width, (float)Tetrimino.Size.Height);
                if (isCollision(tester))
                {
                    return(true);
                }
            }

            return(false);
        }