using System.Collections;
using System.Collections.Generic;
using UnityEngine.EventSystems;
public class SudokuTile : MonoBehaviour, IPrintable, IClickable
public int Weight { get; private set; }
public int CorrectWeight { get; private set; }
public int Row { get; private set; }
public int Column { get; private set; }
private Image backgroundImage;
private Image borderImage;
private TextMeshProUGUI textMesh;
protected GameScreen parentScreen;
private Vector3 cachedScale;
public bool IsEmpty { get; private set; }
public Sequence AnimationSequence { get; private set; }
public void Initialize(GameScreen initParent, int initWeight, int initRow, int initColumn)
parentScreen = initParent;
PrintWeight(Weight, Color.black);
CorrectWeight = -initWeight;
cachedScale = transform.localScale;
public void Reinitialize()
public void PrintWeight(int num, Color col)
textMesh.text = num.ToString();
if (parentScreen.IsClickable)
parentScreen.OnTileGotClicked(this);
public bool? CheckInput(int weight)
if (IsEmpty && CorrectWeight == weight)
PrintWeight(weight, Color.black);
else if (IsEmpty && CorrectWeight != weight)
PrintWeight(weight, GameManager.Instance.FailColor);
private void FailAnimation()
Color inputColor = GameManager.Instance.FailColor;
float scallingValue = 0.2f;
Vector3 bigScale = cachedScale + new Vector3(scallingValue, scallingValue, scallingValue);
Vector3 rotationValue = new Vector3(0f, 0f, 45f);
if (AnimationSequence != null)
AnimationSequence.Complete();
transform.SetAsLastSibling();
transform.localScale = cachedScale;
AnimationSequence = DOTween.Sequence();
AnimationSequence.Append(transform.DOScale(bigScale, timer / 2));
AnimationSequence.Join(transform.DORotate(-rotationValue, timer / 2));
AnimationSequence.Join(backgroundImage.DOColor(new Color(inputColor.r, inputColor.g + 0.6f, inputColor.b + 0.6f, inputColor.a), timer / 2));
AnimationSequence.Join(borderImage.DOColor(inputColor, timer / 2));
AnimationSequence.Append(transform.DORotate(rotationValue, timer / 2));
AnimationSequence.Append(transform.DOScale(cachedScale, timer));
AnimationSequence.Join(transform.DORotate(new Vector3(0f, 0f, 0f), timer / 2));
AnimationSequence.AppendCallback(() => Reinitialize());
private void SuccessAnimation()
Color inputColor = GameManager.Instance.SuccessColor;
float scallingValue = 0.2f;
Vector3 bigScale = cachedScale + new Vector3(scallingValue, scallingValue, scallingValue);
if (AnimationSequence != null)
AnimationSequence.Complete();
transform.SetAsLastSibling();
transform.localScale = cachedScale;
AnimationSequence = DOTween.Sequence();
AnimationSequence.Append(backgroundImage.DOColor(inputColor, timer));
AnimationSequence.Join(borderImage.DOColor(inputColor, timer));
AnimationSequence.Append(backgroundImage.DOColor(Color.white, timer / 4));
AnimationSequence.Join(transform.DOScale(bigScale, timer));
AnimationSequence.Append(transform.DOScale(cachedScale, timer));
AnimationSequence.Append(borderImage.DOColor(Color.white, timer));
AnimationSequence.Join(backgroundImage.DOColor(Color.white, timer));
public void SelectAnimation()
if (AnimationSequence != null)
AnimationSequence.Complete();
Color inputColor = GameManager.Instance.MainColor;
inputColor = new Color(inputColor.r * 1.5f, inputColor.g * 1.15f, inputColor.b, inputColor.a);
backgroundImage.color = inputColor;
borderImage.color = GameManager.Instance.MainColor;
public void HighlightAnimation()
if (AnimationSequence != null)
AnimationSequence.Complete();
Color inputColor = backgroundImage.color;
inputColor = new Color(inputColor.r, inputColor.g, inputColor.b, inputColor.a * 0.5f);
backgroundImage.color = inputColor;
borderImage.color = inputColor;
public Sequence ResetAnimation()
if (AnimationSequence != null)
AnimationSequence.Complete();
AnimationSequence = DOTween.Sequence();
AnimationSequence.Append(borderImage.DOColor(Color.white, timer));
AnimationSequence.Join(backgroundImage.DOColor(Color.white, timer));
return AnimationSequence;
public void HardResetAnimation()
if (AnimationSequence != null)
AnimationSequence.Complete();
borderImage.color = Color.white;
backgroundImage.color = Color.white;
public void FlashAnimation(float sec)
AnimationSequence = DOTween.Sequence();
AnimationSequence.Append(backgroundImage.DOColor(GameManager.Instance.MainColor, sec));
AnimationSequence.Join(borderImage.DOColor(GameManager.Instance.MainColor, sec));
AnimationSequence.Append(backgroundImage.DOColor(Color.white, sec));
AnimationSequence.Join(borderImage.DOColor(Color.white, sec));
AnimationSequence.Complete();