Solitaire(6)

```C#:UserInput
    private float timer;
    private float doubleClickTime = 0.3f;
    private int clickCount = 0;
```

void　Update()内に

```C#:UserInput
if (clickCount == 1)
        {
            timer += Time.deltaTime;
        }
        if (clickCount == 3)
        {
            timer = 0;
            clickCount = 1;
        }
        if (timer > doubleClickTime)
        {
            timer = 0;
            clickCount = 0;
        }
```

を加える

void GetMouseClick()内の
if (Input.GetMouseButtonDown(0))内に

```C#:UserInput
clickCount++;
```

を加える

一番下にdoubleClick()をbool型で作る

```C#:UserInput
bool DoubleClick()
    {
        if (timer < doubleClickTime && clickCount == 2)
        {
            print("Double Click");
            return true;
        }
        else
        {
            return false;
        }

    }
```

void Card(GameObject selected)を

```C#:UserInput
void Card(GameObject selected)
    {
        // Card click actions
        print("Clicked on Card");

        if (!selected.GetComponent<Selectable>().faceUp) // if the card clicked on is facedown
        {
            if (!Blocked(selected))//if the card clicked on is not blocked
            {
                // flip it over
                selected.GetComponent<Selectable>().faceUp = true;
                slot1 = this.gameObject;
            }
        }
        else if (selected.GetComponent<Selectable>().inDeckPile)
        // if the card clicked on is in the deck pile with the trips めくったデッキの一番上しか触れない
        {
            // if it is not blocked
            if (!Blocked(selected))
            {
                if (slot1 == selected) // if the same card is clicked twice
                {
                    if (DoubleClick())
                    {
                        // attempt auto stack
                    }
                }
                else
                {
                    slot1 = selected;
                }




                slot1 = selected;
            }
        }
        else
        {

            // if the card is face up
            // if therer is no card currently selected
            // select the card

            if (slot1 == this.gameObject) // not null because we pass in this gameObject instead
            {
                slot1 = selected;
            }

            // if there is already a card selected (and it is not the same card)


            else if (slot1 != selected)
            {
                // if the new card is eligable to stack on the old card
                if (Stackable(selected))
                {
                    Stack(selected);
                }
                else
                {
                    //select the new card
                    slot1 = selected;
                }
            }

        else if (slot1 == selected) // if the same card is clicked twice
            {
                if (DoubleClick())
                {
                    if (DoubleClick())
                    {
                        // attempt auto stack
                    }
                }
            }



        }
    }
```

に書き換える

一番下に加える

```C#:UserInput
void AutoStack(GameObject selected)
    {
        for (int i = 0; i < solitaire.topPos.Length; i++)
        {
            Selectable stack = solitaire.topPos[i].GetComponent<Selectable>();
            if (selected.GetComponent<Selectable>().value == 1) //if it is an Ace
            {
                if (solitaire.topPos[i].GetComponent<Selectable>().value == 0) // and the top position is empty
                {
                    slot1 = selected;
                    Stack(stack.gameObject); // stack the ace up top
                    break;                   // in the first empty position found
                }
            }
            else
            {
                if ((solitaire.topPos[i].GetComponent<Selectable>().suit == slot1.GetComponent<Selectable>().suit) && (solitaire.topPos[i].GetComponent<Selectable>().value == slot1.GetComponent<Selectable>().value - 1))
                {
                    // if it is the last card (if it has no children)
                    if (HasNoChildren(slot1))
                    {
                        slot1 = selected;
                        // find a top spot that matches the conditions for auto stacking if it exists
                        string lastCardname = stack.suit + stack.value.ToString();
                        if (stack.value == 1)
                        {
                            lastCardname = stack.suit + "A";
                        }
                        if (stack.value == 11)
                        {
                            lastCardname = stack.suit + "J";
                        }
                        if (stack.value == 12)
                        {
                            lastCardname = stack.suit + "Q";
                        }
                        if (stack.value == 13)
                        {
                            lastCardname = stack.suit + "K";
                        }
                        GameObject lastCard = GameObject.Find(lastCardname);
                        Stack(lastCard);
                        break;
                    }
                }
            }
        }
    }


    bool HasNoChildren(GameObject card)
    {
        int i = 0;
        foreach (Transform child in card.transform)
        {
            i++;
        }
        if (i == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
```

void Card(GameObject selected)内の
else if (selected.GetComponent<Selectable>().inDeckPile)の下を

```C#:UserInput
// if it is not blocked
            if (!Blocked(selected))
            {
                if (slot1 == selected) // if the same card is clicked twice
                {
                    if (DoubleClick())
                    {
                        // attempt auto stack
                        AutoStack(selected);
                    }
                }
                else
                {
                    slot1 = selected;
                }
            }
```

に書き換える

UIButtonsというスクリプトを追加して

```C#:UIButtons
public void ResetScene()
    {
        // find all the cards and remove them
        UpdateSprite[] cards = FindObjectsOfType<UpdateSprite>();
        foreach (UpdateSprite card in cards)
        {
            Destroy(card.gameObject);
        }
        ClearTopValues();
        // deal new cards
        FindObjectOfType<Solitaire>().PlayCards();
    }

    void ClearTopValues()
    {
        Selectable[] selectables = FindObjectsOfType<Selectable>();
        foreach (Selectable selectable in selectables)
        {
            if (selectable.CompareTag("Top"))
            {
                selectable.suit = null;
                selectable.value = 0;
            }
        }
    }
```
を下に加える