private bool IsGoodRotation(Shape_With_Place shape, bool positionAndRectangle, DraggableShape shapeOnCard) { var figureRotation = 0; var rotLeft = new Quaternion(0, 0, (float)0.7, (float)0.7).eulerAngles.magnitude; var rotDown = new Quaternion(0, 0, 1, 0).eulerAngles.magnitude; var rotRight = new Quaternion(0, 0, (float)0.7, (float)-0.7).eulerAngles.magnitude; if (shapeOnCard.transform.rotation.eulerAngles.magnitude.Equals(rotLeft)) { figureRotation = 1; } if (shapeOnCard.transform.rotation.eulerAngles.magnitude.Equals(rotDown)) { figureRotation = 2; } if (shapeOnCard.transform.rotation.eulerAngles.magnitude.Equals(rotRight)) { figureRotation = 3; } if (!shape.shape.Get_Is_Rotative()) { return(true); } if (figureRotation == 0 && shape.shape.Get_Rotation() == Shape.Rotation.Up) { return(true); } if (figureRotation == 1 && shape.shape.Get_Rotation() == Shape.Rotation.Left) { return(true); } if (figureRotation == 2 && shape.shape.Get_Rotation() == Shape.Rotation.Down) { return(true); } if (figureRotation == 3 && shape.shape.Get_Rotation() == Shape.Rotation.Right) { return(true); } if (positionAndRectangle) { if (figureRotation == 2 && shape.shape.Get_Rotation() == Shape.Rotation.Up) { return(true); } if (figureRotation == 3 && shape.shape.Get_Rotation() == Shape.Rotation.Left) { return(true); } if (figureRotation == 0 && shape.shape.Get_Rotation() == Shape.Rotation.Down) { return(true); } if (figureRotation == 1 && shape.shape.Get_Rotation() == Shape.Rotation.Right) { return(true); } } return(false); }
private bool IsGoodColor(Shape_With_Place shape, Component shapeOncard) { var shapeOnCardColor = shapeOncard.gameObject.GetComponent <Image>().color; return(shapeOnCardColor == Helpers.ShapeColorToUnityColor(shape.shape.Get_Colour())); }
public bool IsOnCard(Shape_With_Place shape) { for (int i = 0; i < Card.childCount; i++) { bool rectangle = false; bool position = false; bool rotation = false; bool color = false; int shapePositionRotated = 0; var child = Card.GetChild(i); var shapeOnCard = child.gameObject.GetComponent <DraggableShape>(); if (shapeOnCard == null) { continue; } if (!Static.DifficultyModifiers.Colours_only_mechanic) { if (Static.DifficultyModifiers.cardType == Difficulty_Modifiers.CardType.Cart_Type70) { int computedPosition = shapeOnCard.NumberOfPosition + 10 + ((shapeOnCard.NumberOfPosition / 7) * 2); if (shape.shape is Rectangle) { rectangle = true; var rotationOfShape = shape.shape.Get_Rotation(); switch (rotationOfShape) { case Shape.Rotation.Up: shapePositionRotated = shape.id_place >= 21 ? shape.id_place - 21 : -1; break; case Shape.Rotation.Left: shapePositionRotated = shape.id_place % 7 >= 3 ? shape.id_place - 3 : -1; break; case Shape.Rotation.Down: shapePositionRotated = shape.id_place <= 48 ? shape.id_place + 27 : -1; break; case Shape.Rotation.Right: shapePositionRotated = shape.id_place % 7 >= 3 ? shape.id_place + 3 : -1; break; } if (computedPosition == shapePositionRotated) { position = true; } } if (shape.id_place == computedPosition) { position = true; } } else { if (shape.shape is Rectangle) { rectangle = true; var rotationOfShape = shape.shape.Get_Rotation(); switch (rotationOfShape) { case Shape.Rotation.Up: shapePositionRotated = shape.id_place - 3; break; case Shape.Rotation.Left: shapePositionRotated = shape.id_place - 1; break; case Shape.Rotation.Down: shapePositionRotated = shape.id_place + 3; break; case Shape.Rotation.Right: shapePositionRotated = shape.id_place + 1; break; } if (shapeOnCard.NumberOfPosition == shapePositionRotated) { position = true; } } if (shape.id_place == shapeOnCard.NumberOfPosition) { position = true; } } } else { position = true; } if (shape.shape.Get_Is_Rotative()) { rotation = IsGoodRotation(shape, position && rectangle, shapeOnCard); } else { rotation = true; } color = IsGoodColor(shape, child); if (position && rotation && color) { return(true); } } return(false); }
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; }