예제 #1
0
        public Figure(Panel workspace, FIGURE_TYPE figureType)
        {
            this.workspace  = workspace;
            this.figureType = figureType;

            isStay        = false;
            rotatingState = FIGURE_ROTATING_STATE.NORMAL;

            cubes = CreateFigure(figureType);
        }
예제 #2
0
        public bool Rotate(List <KeyValuePair <Point, Brush> > ocсupiedCubes)
        {
            switch (figureType)
            {
            case FIGURE_TYPE.I: {
                switch (rotatingState)
                {
                case FIGURE_ROTATING_STATE.NORMAL: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[0].X - 2 * CUBE_SIZE, cubes[0].Y + 3 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[1].X - 1 * CUBE_SIZE, cubes[1].Y + 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X, cubes[2].Y + 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X + 1 * CUBE_SIZE, cubes[3].Y));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[0] = newPoints[0];
                    cubes[1] = newPoints[1];
                    cubes[2] = newPoints[2];
                    cubes[3] = newPoints[3];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_90;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_90: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[0].X + 2 * CUBE_SIZE, cubes[0].Y - 3 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[1].X + 1 * CUBE_SIZE, cubes[1].Y - 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X, cubes[2].Y - 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X - 1 * CUBE_SIZE, cubes[3].Y));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[0] = newPoints[0];
                    cubes[1] = newPoints[1];
                    cubes[2] = newPoints[2];
                    cubes[3] = newPoints[3];

                    rotatingState = FIGURE_ROTATING_STATE.NORMAL;

                    break;
                }

                default:
                    throw new Exception("Wrong rotate type of Figure");
                }
                break;
            }

            case FIGURE_TYPE.J: {
                switch (rotatingState)
                {
                case FIGURE_ROTATING_STATE.NORMAL: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X + 1 * CUBE_SIZE, cubes[1].Y - 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X + 2 * CUBE_SIZE, cubes[2].Y - 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X + 3 * CUBE_SIZE, cubes[1].Y - 2 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_90;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_90: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X + 1 * CUBE_SIZE, cubes[1].Y + 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X + 2 * CUBE_SIZE, cubes[2].Y + 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X + 1 * CUBE_SIZE, cubes[3].Y + 3 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_180;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_180: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X - 1 * CUBE_SIZE, cubes[1].Y + 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X - 2 * CUBE_SIZE, cubes[2].Y + 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X - 3 * CUBE_SIZE, cubes[3].Y + 1 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_270;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_270: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X - 1 * CUBE_SIZE, cubes[1].Y - 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X - 2 * CUBE_SIZE, cubes[2].Y - 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X - 1 * CUBE_SIZE, cubes[3].Y - 3 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.NORMAL;

                    break;
                }

                default:
                    throw new Exception("Wrong rotate type of Figure");
                }
                break;
            }

            case FIGURE_TYPE.L: {
                switch (rotatingState)
                {
                case FIGURE_ROTATING_STATE.NORMAL: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[0].X + 1 * CUBE_SIZE, cubes[0].Y - 3 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[1].X, cubes[1].Y - 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X - 1 * CUBE_SIZE, cubes[2].Y - 1 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[0] = newPoints[0];
                    cubes[1] = newPoints[1];
                    cubes[2] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_90;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_90: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[0].X + 3 * CUBE_SIZE, cubes[0].Y + 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[1].X + 2 * CUBE_SIZE, cubes[1].Y));
                    newPoints.Add(new Point(cubes[2].X + 1 * CUBE_SIZE, cubes[2].Y - 1 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[0] = newPoints[0];
                    cubes[1] = newPoints[1];
                    cubes[2] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_180;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_180: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[0].X - 1 * CUBE_SIZE, cubes[0].Y + 3 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[1].X, cubes[1].Y + 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X + 1 * CUBE_SIZE, cubes[2].Y + 1 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[0] = newPoints[0];
                    cubes[1] = newPoints[1];
                    cubes[2] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_270;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_270: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[0].X - 3 * CUBE_SIZE, cubes[0].Y - 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[1].X - 2 * CUBE_SIZE, cubes[1].Y));
                    newPoints.Add(new Point(cubes[2].X - 1 * CUBE_SIZE, cubes[2].Y + 1 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[0] = newPoints[0];
                    cubes[1] = newPoints[1];
                    cubes[2] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.NORMAL;

                    break;
                }

                default:
                    throw new Exception("Wrong rotate type of Figure");
                }
                break;
            }

            case FIGURE_TYPE.O:
                break;

            case FIGURE_TYPE.S: {
                switch (rotatingState)
                {
                case FIGURE_ROTATING_STATE.NORMAL: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X + 1 * CUBE_SIZE, cubes[1].Y - 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X, cubes[2].Y - 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X + 1 * CUBE_SIZE, cubes[3].Y - 3 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_90;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_90: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X + 1 * CUBE_SIZE, cubes[1].Y + 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X + 2 * CUBE_SIZE, cubes[2].Y));
                    newPoints.Add(new Point(cubes[3].X + 3 * CUBE_SIZE, cubes[3].Y + 1 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_180;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_180: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X - 1 * CUBE_SIZE, cubes[1].Y + 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X, cubes[2].Y + 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X - 1 * CUBE_SIZE, cubes[3].Y + 3 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_270;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_270: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X - 1 * CUBE_SIZE, cubes[1].Y - 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X - 2 * CUBE_SIZE, cubes[2].Y));
                    newPoints.Add(new Point(cubes[3].X - 3 * CUBE_SIZE, cubes[3].Y - 1 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.NORMAL;

                    break;
                }

                default:
                    throw new Exception("Wrong rotate type of Figure");
                }
                break;
            }

            case FIGURE_TYPE.T: {
                switch (rotatingState)
                {
                case FIGURE_ROTATING_STATE.NORMAL: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X, cubes[1].Y - 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X - 1 * CUBE_SIZE, cubes[2].Y - 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X - 2 * CUBE_SIZE, cubes[3].Y));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_90;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_90: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X + 2 * CUBE_SIZE, cubes[1].Y));
                    newPoints.Add(new Point(cubes[2].X + 1 * CUBE_SIZE, cubes[2].Y - 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X, cubes[3].Y - 2 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_180;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_180: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X, cubes[1].Y + 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X + 1 * CUBE_SIZE, cubes[2].Y + 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X + 2 * CUBE_SIZE, cubes[3].Y));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_270;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_270: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X - 2 * CUBE_SIZE, cubes[1].Y));
                    newPoints.Add(new Point(cubes[2].X - 1 * CUBE_SIZE, cubes[2].Y + 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X, cubes[3].Y + 2 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.NORMAL;

                    break;
                }

                default:
                    throw new Exception("Wrong rotate type of Figure");
                }
                break;
            }

            case FIGURE_TYPE.Z: {
                switch (rotatingState)
                {
                case FIGURE_ROTATING_STATE.NORMAL: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X - 1 * CUBE_SIZE, cubes[1].Y + 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X - 2 * CUBE_SIZE, cubes[2].Y));
                    newPoints.Add(new Point(cubes[3].X - 3 * CUBE_SIZE, cubes[3].Y + 1 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_90;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_90: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X - 1 * CUBE_SIZE, cubes[1].Y - 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X, cubes[2].Y - 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X - 1 * CUBE_SIZE, cubes[3].Y - 3 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_180;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_180: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X + 1 * CUBE_SIZE, cubes[1].Y - 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X + 2 * CUBE_SIZE, cubes[2].Y));
                    newPoints.Add(new Point(cubes[3].X + 3 * CUBE_SIZE, cubes[3].Y - 1 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.ROTATE_270;

                    break;
                }

                case FIGURE_ROTATING_STATE.ROTATE_270: {
                    List <Point> newPoints = new List <Point>();
                    newPoints.Add(new Point(cubes[1].X + 1 * CUBE_SIZE, cubes[1].Y + 1 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[2].X, cubes[2].Y + 2 * CUBE_SIZE));
                    newPoints.Add(new Point(cubes[3].X + 1 * CUBE_SIZE, cubes[3].Y + 3 * CUBE_SIZE));

                    for (int i = 0; i < newPoints.Count; i++)
                    {
                        if (newPoints[i].X + CUBE_SIZE > workspace.Width || newPoints[i].X <0 ||
                                                                                            newPoints[i].Y + CUBE_SIZE> workspace.Height)
                        {
                            return(false);
                        }

                        for (int j = 0; j < ocсupiedCubes.Count; j++)
                        {
                            if ((newPoints[i].X == ocсupiedCubes[j].Key.X && newPoints[i].Y == ocсupiedCubes[j].Key.Y))
                            {
                                return(false);
                            }
                        }
                    }

                    cubes[1] = newPoints[0];
                    cubes[2] = newPoints[1];
                    cubes[3] = newPoints[2];

                    rotatingState = FIGURE_ROTATING_STATE.NORMAL;

                    break;
                }

                default:
                    throw new Exception("Wrong rotate type of Figure");
                }
                break;
            }

            default:
                throw new Exception("Wrong type of Figure");
            }
            return(true);
        }