Exemple #1
0
        public bool isCurrentPieceMovable(Vector2 coords)
        {
            bool[]    visited = new bool[16];
            bool      res     = true;
            Tetrimino tmp     = TetrisConsole.Model.Tetriminos.DeepCloner.Clone(t);

            tmp.coords = coords;
            SweapPiecePosition();
            FloodFill(tmp, tmp.pivot, tmp.colors, visited, ref res);
            PrintPiece();
            return(res);
        }
Exemple #2
0
        public void FloodFill(Tetrimino t, Vector2 pivot, int target, int color, bool[] visited)
        {
            if (pivot.X < 0 || pivot.X > t.Size - 1 || pivot.Y < 0 || pivot.Y > t.Size - 1 || visited[(int)(pivot.X + pivot.Y * t.Size)] || t.grid[(int)(pivot.X + pivot.Y * t.Size)] != target)
            {
                return;
            }

            visited[(int)(pivot.X + pivot.Y * t.Size)] = true;
            pField[(int)(t.coords.X + pivot.X + (t.coords.Y + pivot.Y) * (nFieldWidth + 2))] = color;
            FloodFill(t, new Vector2(pivot.X, pivot.Y + 1), target, color, visited);                          //NORTH
            FloodFill(t, new Vector2(pivot.X, pivot.Y - 1), target, color, visited);                          //SOUTH
            FloodFill(t, new Vector2(pivot.X + 1, pivot.Y), target, color, visited);                          //EAST
            FloodFill(t, new Vector2(pivot.X - 1, pivot.Y), target, color, visited);                          //WEST
        }
Exemple #3
0
        public bool isCurrentPieceRotable()
        {
            bool[] visited = new bool[t.Size * t.Size];
            bool   res     = true;
            int    rotate  = 1;

            SweapPiecePosition();
            bool      continu = true;
            Tetrimino tmp     = TetrisConsole.Model.Tetriminos.DeepCloner.Clone(t);

            while (continu && rotate < 4)
            {
                tmp.Rotate();
                FloodFill(tmp, tmp.pivot, tmp.colors, visited, ref res);
                rotate++;
                continu = !res;
            }
            PrintPiece();
            return(res);
        }
Exemple #4
0
        public void FloodFill(Tetrimino t, Vector2 pivot, int target, bool[] visited, ref bool collide)
        {
            if (pivot.X < 0 || pivot.X > t.Size - 1 || pivot.Y < 0 || pivot.Y > t.Size - 1 || visited[(int)(pivot.X + pivot.Y * t.Size)] || t.grid[(int)(pivot.X + pivot.Y * t.Size)] != target)
            {
                return;
            }

            visited[(int)(pivot.X + pivot.Y * t.Size)] = true;

            if (t.coords.X < -1 ||
                t.coords.Y < -1 ||
                t.coords.X > nFieldWidth + 2 - t.Size ||
                t.coords.Y > nFieldHeight + 2 - t.Size ||
                pField[(int)(t.coords.X + pivot.X + (t.coords.Y + pivot.Y) * (nFieldWidth + 2))] != 0)
            {
                collide = false;
                return;
            }

            FloodFill(t, new Vector2(pivot.X, pivot.Y + 1), target, visited, ref collide);                         //NORTH
            FloodFill(t, new Vector2(pivot.X, pivot.Y - 1), target, visited, ref collide);                         //SOUTH
            FloodFill(t, new Vector2(pivot.X + 1, pivot.Y), target, visited, ref collide);                         //EAST
            FloodFill(t, new Vector2(pivot.X - 1, pivot.Y), target, visited, ref collide);                         //WEST
        }