Skip to content

Commit

Permalink
231028
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynab committed Oct 27, 2023
1 parent 5217a30 commit f1e6c3b
Showing 1 changed file with 99 additions and 2 deletions.
101 changes: 99 additions & 2 deletions Assets/Script/MouseInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using static UnityEngine.Physics2D;
using static UnityEngine.Time;
using static UnityEngine.Vector2;
using static UnityEngine.GameObject;

public sealed class MouseInput : MonoBehaviour
{
Expand All @@ -17,8 +18,8 @@ public sealed class MouseInput : MonoBehaviour

private void Start()
{
_managerCard = FindObjectOfType<ManagerCard>();
Slot = gameObject;
_managerCard = FindObjectOfType<ManagerCard>();
_setTimes = _times;
}

Expand All @@ -44,6 +45,16 @@ private void Update()
GetMouseClick();
}

public bool StackAble(GameObject selected)
{
var s1 = Slot.GetComponent<Selectable>();
var s2 = selected.GetComponent<Selectable>();

return !s2.IsDeckPile && (s2.Top
? (s1.Suit == s2.Suit || s1.Values is 1 && s2.Suit is null) && s1.Values == s2.Values + 1
: s1.Values == s2.Values - 1 && s1.Suit is not "C" and not "S" == s2.Suit is not "C" and not "S");
}

private void GetMouseClick()
{
if (GetMouseButtonDown(0))
Expand Down Expand Up @@ -78,11 +89,97 @@ private void GetMouseClick()
}
}

private void StackBots(GameObject selected)
private bool DoubleClick() => _times < _doubleClickTime && _clickCount is 2;

private void AutoStack(GameObject selected)
{
for (var i = 0; i < _managerCard.PosTops.Length; i++)
{
var stack = _managerCard.PosTops[i].GetComponent<Selectable>();

if (selected.GetComponent<Selectable>().Values is 1 && stack.Values is 0)
{
Slot = selected;
StackCard(stack.gameObject);
break;
}
else if (stack.Suit == Slot.GetComponent<Selectable>().Suit && stack.Values == Slot.GetComponent<Selectable>().Values - 1 && HasNoChildren(Slot))
{
Slot = selected;

StackCard(Find(stack.Suit + stack.Values switch
{
1 => "A",
11 => "J",
12 => "Q",
13 => "K",
_ => stack.Values.ToString()
}));

break;
}
}
}

private bool HasNoChildren(GameObject card) => card.transform.childCount is 0;

private void StackCard(GameObject selected)
{
var s1 = Slot.GetComponent<Selectable>();
var s2 = selected.GetComponent<Selectable>();
var yPos = 0.3f;
var zPos = 0.01f;

if (s2.Top || s1.Values is 13)
{
yPos = 0;
}

Slot.transform.position = new Vector3(selected.transform.position.x, selected.transform.position.y - yPos, selected.transform.position.z - zPos);
Slot.transform.parent = selected.transform;

if (s1.IsDeckPile)
{
_managerCard.TripsOnDisplay.Remove(Slot.name);
}
else if (s1.Top)
{
if (s2.Top && s1.Values is 1)
{
_managerCard.PosTops[s1.Row].GetComponent<Selectable>().Values = default;
_managerCard.PosTops[s1.Row].GetComponent<Selectable>().Suit = default;
}
else
{
_managerCard.PosTops[s1.Row].GetComponent<Selectable>().Values = s1.Values - 1;
}
}
else
{
_managerCard.Bots[s1.Row].Remove(Slot.name);
}

s1.IsDeckPile = default;
s1.Row = s2.Row;

if (s2.Top)
{
_managerCard.PosTops[s1.Row].GetComponent<Selectable>().Values = s1.Values;
_managerCard.PosTops[s1.Row].GetComponent<Selectable>().Suit = s1.Suit;
s1.Top = true;
}
else
{
s1.Top = default;
}

Slot = gameObject;
}

private void StackBots(GameObject selected)
{
var s1 = Slot.GetComponent<Selectable>();
var s2 = selected.GetComponent<Selectable>();
var yPos = 0.3f;
var zPos = 0.01f;

Expand Down

0 comments on commit f1e6c3b

Please sign in to comment.