Пример #1
0
    private Roll_Struct2x1 Find_Empty_Space_70_2x1(int width, int height)
    {
        Roll_Struct2x1 rolled_data = new Roll_Struct2x1();

        current_removed_places_array = new ArrayList();

        while (true)
        {
            current_rotation_array = new ArrayList();

            int rnd     = Random.Range(0, empty_space.Count);
            int place   = (int)empty_space[rnd];
            int counter = place;

            //Debug.Log(place);

            int x = 0;
            int y = 0;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (counter == 0)
                    {
                        x = j;
                        y = i;
                    }

                    counter--;
                }
            }



            current_place_status_array = new ArrayList();

            current_place_status_array.Add(Check_Left(x, place, 1));

            current_place_status_array.Add(Check_Up(difficulty_modifires.cardType, y, place, 1));

            current_place_status_array.Add(Check_Right(x, width_70, place, 1));

            current_place_status_array.Add(Check_Down(difficulty_modifires.cardType, y, height_70, place, 1));

            current_place_status_array.Add(Check_Diagonal_Up_Left(difficulty_modifires.cardType, x, y, place, 1, 1));

            current_place_status_array.Add(Check_Diagonal_Up_Right(difficulty_modifires.cardType, x, y, width_70, place, 1, 1));

            current_place_status_array.Add(Check_Diagonal_Down_Left(difficulty_modifires.cardType, x, y, height_70, place, 1, 1));

            current_place_status_array.Add(Check_Diagonal_Down_Right(difficulty_modifires.cardType, x, y, width_70, height_70, place, 1, 1));

            if (!current_place_status_array.Contains(false))
            {
                current_place_status_array = new ArrayList();

                current_place_status_array.Add(Check_Diagonal_Up_Right(difficulty_modifires.cardType, x, y, width_70, place, 2, 1));

                current_place_status_array.Add(Check_Diagonal_Up_Right(difficulty_modifires.cardType, x, y, width_70, place, 3, 1));

                current_place_status_array.Add(Check_Diagonal_Up_Right(difficulty_modifires.cardType, x, y, width_70, place, 4, 1));

                current_place_status_array.Add(Check_Right(x, width_70, place, 2));

                current_place_status_array.Add(Check_Right(x, width_70, place, 3));

                current_place_status_array.Add(Check_Right(x, width_70, place, 4));

                current_place_status_array.Add(Check_Diagonal_Down_Right(difficulty_modifires.cardType, x, y, width_70, height_70, place, 2, 1));

                current_place_status_array.Add(Check_Diagonal_Down_Right(difficulty_modifires.cardType, x, y, width_70, height_70, place, 3, 1));

                current_place_status_array.Add(Check_Diagonal_Down_Right(difficulty_modifires.cardType, x, y, width_70, height_70, place, 4, 1));

                if (current_place_status_array.Contains(false))
                {
                    current_place_status_array = new ArrayList();
                }
                else
                {
                    current_place_status_array = new ArrayList();
                    current_rotation_array.Add(Shape.Rotation.Right);
                }

                current_place_status_array.Add(Check_Diagonal_Up_Left(difficulty_modifires.cardType, x, y, place, 2, 1));

                current_place_status_array.Add(Check_Diagonal_Up_Left(difficulty_modifires.cardType, x, y, place, 3, 1));

                current_place_status_array.Add(Check_Diagonal_Up_Left(difficulty_modifires.cardType, x, y, place, 4, 1));

                current_place_status_array.Add(Check_Left(x, place, 2));

                current_place_status_array.Add(Check_Left(x, place, 3));

                current_place_status_array.Add(Check_Left(x, place, 4));

                current_place_status_array.Add(Check_Diagonal_Down_Left(difficulty_modifires.cardType, x, y, height_70, place, 2, 1));

                current_place_status_array.Add(Check_Diagonal_Down_Left(difficulty_modifires.cardType, x, y, height_70, place, 3, 1));

                current_place_status_array.Add(Check_Diagonal_Down_Left(difficulty_modifires.cardType, x, y, height_70, place, 4, 1));

                if (current_place_status_array.Contains(false))
                {
                    current_place_status_array = new ArrayList();
                }
                else
                {
                    current_place_status_array = new ArrayList();
                    current_rotation_array.Add(Shape.Rotation.Left);
                }

                current_place_status_array.Add(Check_Diagonal_Down_Left(difficulty_modifires.cardType, x, y, height_70, place, 1, 2));

                current_place_status_array.Add(Check_Diagonal_Down_Left(difficulty_modifires.cardType, x, y, height_70, place, 1, 3));

                current_place_status_array.Add(Check_Diagonal_Down_Left(difficulty_modifires.cardType, x, y, height_70, place, 1, 4));

                current_place_status_array.Add(Check_Down(difficulty_modifires.cardType, y, height_70, place, 2));

                current_place_status_array.Add(Check_Down(difficulty_modifires.cardType, y, height_70, place, 3));

                current_place_status_array.Add(Check_Down(difficulty_modifires.cardType, y, height_70, place, 4));

                current_place_status_array.Add(Check_Diagonal_Down_Right(difficulty_modifires.cardType, x, y, width_70, height_70, place, 1, 2));

                current_place_status_array.Add(Check_Diagonal_Down_Right(difficulty_modifires.cardType, x, y, width_70, height_70, place, 1, 3));

                current_place_status_array.Add(Check_Diagonal_Down_Right(difficulty_modifires.cardType, x, y, width_70, height_70, place, 1, 4));

                if (current_place_status_array.Contains(false))
                {
                    current_place_status_array = new ArrayList();
                }
                else
                {
                    current_place_status_array = new ArrayList();
                    current_rotation_array.Add(Shape.Rotation.Down);
                }

                current_place_status_array.Add(Check_Diagonal_Up_Left(difficulty_modifires.cardType, x, y, place, 1, 2));

                current_place_status_array.Add(Check_Diagonal_Up_Left(difficulty_modifires.cardType, x, y, place, 1, 3));

                current_place_status_array.Add(Check_Diagonal_Up_Left(difficulty_modifires.cardType, x, y, place, 1, 4));

                current_place_status_array.Add(Check_Up(difficulty_modifires.cardType, y, place, 2));

                current_place_status_array.Add(Check_Up(difficulty_modifires.cardType, y, place, 3));

                current_place_status_array.Add(Check_Up(difficulty_modifires.cardType, y, place, 4));

                current_place_status_array.Add(Check_Diagonal_Up_Right(difficulty_modifires.cardType, x, y, width_70, place, 1, 2));

                current_place_status_array.Add(Check_Diagonal_Up_Right(difficulty_modifires.cardType, x, y, width_70, place, 1, 3));

                current_place_status_array.Add(Check_Diagonal_Up_Right(difficulty_modifires.cardType, x, y, width_70, place, 1, 4));

                if (current_place_status_array.Contains(false))
                {
                    current_place_status_array = new ArrayList();
                }
                else
                {
                    current_place_status_array = new ArrayList();
                    current_rotation_array.Add(Shape.Rotation.Up);
                }
            }

            if (current_rotation_array.Count == 0)
            {
                current_removed_places_array.Add(place);
                empty_space.RemoveAt(rnd);
            }
            else
            {
                rolled_data.rotation = (Shape.Rotation)current_rotation_array[Random.Range(0, current_rotation_array.Count)];
                rolled_data.place    = place;
                rolled_data.is_2x1   = true;

                empty_space.RemoveAt(rnd);

                foreach (int removed_place in current_removed_places_array)
                {
                    empty_space.Add(removed_place);
                }

                card_pattern[x, y - 1] = new Empty(); //up
                empty_space.Remove(place - 9);

                card_pattern[x, y + 1] = new Empty(); // down
                empty_space.Remove(place + 9);

                card_pattern[x + 1, y] = new Empty(); // r
                empty_space.Remove(place + 1);

                card_pattern[x - 1, y] = new Empty(); // l
                empty_space.Remove(place - 1);

                card_pattern[x - 1, y - 1] = new Empty(); /// ul
                empty_space.Remove(place - 10);

                card_pattern[x + 1, y - 1] = new Empty(); /// ur
                empty_space.Remove(place - 8);

                card_pattern[x - 1, y + 1] = new Empty(); /// dl
                empty_space.Remove(place + 8);

                card_pattern[x + 1, y + 1] = new Empty(); /// dr
                empty_space.Remove(place + 10);

                switch (rolled_data.rotation)
                {
                case Shape.Rotation.Up:

                    card_pattern[x, y - 2] = new Empty();     //up
                    empty_space.Remove(place - 18);
                    card_pattern[x, y - 3] = new Empty();     //up
                    empty_space.Remove(place - 27);
                    card_pattern[x, y - 4] = new Empty();     //up
                    empty_space.Remove(place - 36);

                    card_pattern[x - 1, y - 2] = new Empty();     /// ul
                    empty_space.Remove(place - 19);
                    card_pattern[x - 1, y - 3] = new Empty();     /// ul
                    empty_space.Remove(place - 28);
                    card_pattern[x - 1, y - 4] = new Empty();     /// ul
                    empty_space.Remove(place - 37);

                    card_pattern[x + 1, y - 2] = new Empty();     /// ur
                    empty_space.Remove(place - 17);
                    card_pattern[x + 1, y - 3] = new Empty();     /// ur
                    empty_space.Remove(place - 26);
                    card_pattern[x + 1, y - 4] = new Empty();     /// ur
                    empty_space.Remove(place - 35);

                    break;

                case Shape.Rotation.Down:

                    card_pattern[x, y + 2] = new Empty();     // down
                    empty_space.Remove(place + 18);
                    card_pattern[x, y + 3] = new Empty();     // down
                    empty_space.Remove(place + 27);
                    card_pattern[x, y + 4] = new Empty();     // down
                    empty_space.Remove(place + 36);

                    card_pattern[x - 1, y + 2] = new Empty();     /// dl
                    empty_space.Remove(place + 17);
                    card_pattern[x - 1, y + 3] = new Empty();     /// dl
                    empty_space.Remove(place + 26);
                    card_pattern[x - 1, y + 4] = new Empty();     /// dl
                    empty_space.Remove(place + 35);

                    card_pattern[x + 1, y + 2] = new Empty();     /// dr
                    empty_space.Remove(place + 19);
                    card_pattern[x + 1, y + 3] = new Empty();     /// dr
                    empty_space.Remove(place + 28);
                    card_pattern[x + 1, y + 4] = new Empty();     /// dr
                    empty_space.Remove(place + 37);

                    break;

                case Shape.Rotation.Right:

                    card_pattern[x + 2, y] = new Empty();     // r
                    empty_space.Remove(place + 2);
                    card_pattern[x + 3, y] = new Empty();     // r
                    empty_space.Remove(place + 3);
                    card_pattern[x + 4, y] = new Empty();     // r
                    empty_space.Remove(place + 4);

                    card_pattern[x + 2, y - 1] = new Empty();     /// ur
                    empty_space.Remove(place - 8);
                    card_pattern[x + 3, y - 1] = new Empty();     /// ur
                    empty_space.Remove(place - 7);
                    card_pattern[x + 4, y - 1] = new Empty();     /// ur
                    empty_space.Remove(place - 6);

                    card_pattern[x + 2, y + 1] = new Empty();     /// dr
                    empty_space.Remove(place + 11);
                    card_pattern[x + 3, y + 1] = new Empty();     /// dr
                    empty_space.Remove(place + 12);
                    card_pattern[x + 4, y + 1] = new Empty();     /// dr
                    empty_space.Remove(place + 13);

                    break;

                case Shape.Rotation.Left:

                    card_pattern[x - 2, y] = new Empty();     // l
                    empty_space.Remove(place - 2);
                    card_pattern[x - 3, y] = new Empty();     // l
                    empty_space.Remove(place - 3);
                    card_pattern[x - 4, y] = new Empty();     // l
                    empty_space.Remove(place - 4);

                    card_pattern[x - 2, y - 1] = new Empty();     /// ul
                    empty_space.Remove(place - 11);
                    card_pattern[x - 3, y - 1] = new Empty();     /// ul
                    empty_space.Remove(place - 12);
                    card_pattern[x - 4, y - 1] = new Empty();     /// ul
                    empty_space.Remove(place - 13);

                    card_pattern[x - 2, y + 1] = new Empty();     /// dl
                    empty_space.Remove(place + 7);
                    card_pattern[x - 3, y + 1] = new Empty();     /// dl
                    empty_space.Remove(place + 6);
                    card_pattern[x - 4, y + 1] = new Empty();     /// dl
                    empty_space.Remove(place + 5);

                    break;

                default:

                    Debug.Log("Error missing rolled rotation");
                    Debug.Log(rolled_data.rotation);
                    break;
                }

                return(rolled_data);
            }

            if (empty_space.Count == 0)
            {
                foreach (int removed_place in current_removed_places_array)
                {
                    empty_space.Add(removed_place);
                }

                current_can_roll_2x1 = false;
                rolled_data.is_2x1   = false;

                Debug.Log("k");
                return(rolled_data);
            }
        }
    }
Пример #2
0
    private void Generate_Card12()
    {
        card_pattern = new Shape[width_12, height_12];
        empty_space  = new ArrayList();
        Setup_Generation(width_12, height_12);

        for (int i = 0; i < difficulty_modifires.Number_of_figures; i++)
        {
            if (empty_space.Count == 0)
            {
                Debug.Log("Error not enought space on card");
                break;
            }

            if (current_can_roll_2x1)
            {
                current_shape_size = Roll_Shape_Sizes();
            }
            else
            {
                current_shape_size = Shape_Sizes.Size1x1;
            }

            switch (current_shape_size)
            {
            case Shape_Sizes.Size1x1:

                current_place = Find_Empty_Space_12_1x1();
                current_shape = Roll_Shape_1x1();
                current_shape.Set_Colour(Roll_Colour());
                Save_Shape(current_place, current_shape, width_12, height_12);
                Debug.Log("place:  " + current_place + " shape: " + current_shape + " colour: " + current_shape.Get_Colour() + " rotation: " + current_shape.Get_Rotation());
                Debug.Log("Id place: " + current_place);
                var shapeWithPlace = new Shape_With_Place
                {
                    shape    = current_shape,
                    id_place = current_place
                };
                list_of_shapes.Add(shapeWithPlace);
                break;

            case Shape_Sizes.Size2x1:

                Roll_Struct2x1 roled_struct = Find_Empty_Space_12_2x1(width_12, height_12);

                if (roled_struct.is_2x1)
                {
                    current_place = roled_struct.place;
                    current_shape = Roll_Shape_2x1(roled_struct.rotation);
                    current_shape.Set_Colour(Roll_Colour());
                    Save_Shape(current_place, current_shape, width_12, height_12);
                    Debug.Log("place:  " + current_place + " shape: " + current_shape + " colour: " + current_shape.Get_Colour() + " rotation: " + current_shape.Get_Rotation());
                    Debug.Log("Id place: " + current_place);
                    shapeWithPlace = new Shape_With_Place
                    {
                        shape    = current_shape,
                        id_place = current_place
                    };
                    list_of_shapes.Add(shapeWithPlace);
                }
                else
                {
                    current_place = Find_Empty_Space_12_1x1();
                    current_shape = Roll_Shape_1x1();
                    current_shape.Set_Colour(Roll_Colour());
                    Save_Shape(current_place, current_shape, width_12, height_12);
                    Debug.Log("place:  " + current_place + " shape: " + current_shape + " colour: " + current_shape.Get_Colour() + " rotation: " + current_shape.Get_Rotation());
                    Debug.Log("Id place: " + current_place);
                    shapeWithPlace = new Shape_With_Place
                    {
                        shape    = current_shape,
                        id_place = current_place
                    };
                    list_of_shapes.Add(shapeWithPlace);
                }

                break;

            default:

                Debug.Log("Error missing rolled shape size");
                Debug.Log(current_shape_size);
                break;
            }
        }

        current_can_roll_2x1 = true;
    }
Пример #3
0
    private Roll_Struct2x1 Find_Empty_Space_12_2x1(int width, int height)
    {
        Roll_Struct2x1 rolled_data = new Roll_Struct2x1();

        current_removed_places_array = new ArrayList();

        while (true)
        {
            current_rotation_array = new ArrayList();

            int rnd     = Random.Range(0, empty_space.Count);
            int place   = (int)empty_space[rnd];
            int counter = place;

            int x = 0;
            int y = 0;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (counter == 0)
                    {
                        x = j;
                        y = i;
                    }

                    counter--;
                }
            }

            if (Check_Left(x, place, 1))
            {
                current_rotation_array.Add(Shape.Rotation.Left);
            }
            if (Check_Up(difficulty_modifires.cardType, y, place, 1))
            {
                current_rotation_array.Add(Shape.Rotation.Up);
            }
            if (Check_Right(x, width_12, place, 1))
            {
                current_rotation_array.Add(Shape.Rotation.Right);
            }
            if (Check_Down(difficulty_modifires.cardType, y, height_12, place, 1))
            {
                current_rotation_array.Add(Shape.Rotation.Down);
            }

            if (current_rotation_array.Count == 0)
            {
                current_removed_places_array.Add(place);
                empty_space.RemoveAt(rnd);
            }
            else
            {
                rolled_data.rotation = (Shape.Rotation)current_rotation_array[Random.Range(0, current_rotation_array.Count)];
                rolled_data.place    = place;
                rolled_data.is_2x1   = true;

                empty_space.RemoveAt(rnd);

                foreach (int removed_place in current_removed_places_array)
                {
                    empty_space.Add(removed_place);
                }

                switch (rolled_data.rotation)
                {
                case Shape.Rotation.Up:

                    card_pattern[x, y - 1] = new Empty();
                    empty_space.Remove(place - 3);
                    break;

                case Shape.Rotation.Down:

                    card_pattern[x, y + 1] = new Empty();
                    empty_space.Remove(place + 3);
                    break;

                case Shape.Rotation.Right:

                    card_pattern[x + 1, y] = new Empty();
                    empty_space.Remove(place + 1);
                    break;

                case Shape.Rotation.Left:

                    card_pattern[x - 1, y] = new Empty();
                    empty_space.Remove(place - 1);
                    break;

                default:

                    Debug.Log("Error missing rolled rotation");
                    Debug.Log(rolled_data.rotation);
                    break;
                }

                return(rolled_data);
            }

            if (empty_space.Count == 0)
            {
                foreach (int removed_place in current_removed_places_array)
                {
                    empty_space.Add(removed_place);
                }

                current_can_roll_2x1 = false;
                rolled_data.is_2x1   = false;
                return(rolled_data);
            }
        }
    }