Solitaire(3)

```C#:UseInput.cs
void GetMouseClick ()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 mousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -10));
            RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
            if (hit)
            {
                //what has been hit? Deck/Card/EmptySlot...
                if (hit.collider.CompareTag("Deck"))
                {
                    //clicked deck
                    Deck();
                }
                else if (hit.collider.CompareTag("Card"))
                {
                    //clicked card
                    Card();
                }
                else if (hit.collider.CompareTag("Top"))
                {
                    //clicked top
                    Top();        
                }
                else if (hit.collider.CompareTag("Bottom"))
                {
                    //clicked Bottom
                    Bottom();
                }
            }
        }
    }

    void Deck()
    {
        // Deck click actions
        print("Clicked on deck");
    }
    void Card()
    {
        // Card click actions
    }
    void Top()
    {
        // Top click actions
    }
    void Bottom()
    {
        // Bottom click actions
    }
}
```

```C#:UserInput.cs
void Update()
    {
        GetMouseClick();
    }
```

```C#:Solitaire.cs
private int trips;
private int tripsRemainder;
```

```C#:Solitaire.cs
public void SortDeckIntoTrips()
    {
        trips = deck.Count / 3;
        tripsRemainder = deck.Count % 3;
    }
```

```C#:Solitaire
public List<string> tripsOnDisplay = new List<string>();
public List<List<string>> deckTrips = new List<List<string>>();
```

```C#:Solitaire
public void SortDeckIntoTrips()
    {
        trips = deck.Count / 3;
        tripsRemainder = deck.Count % 3;
        deckTrips.Clear();

        int modifier = 0;
        for (int i = 0; i < trips; i++)
        {
            List<string> myTrips = new List<string>();
            for (int j = 0; j < 3; j++)
            {
                myTrips.Add(deck[j + modifier]);
            }
            deckTrips.Add(myTrips);
            modifier = modifier + 3;
        }
        if (tripsRemainder !=0)
        {
            List<string> myRemainders = new List<string>();
            modifier = 0;
            for (int k = 0; k < tripsRemainder; k++)
            {
                myRemainders.Add(deck[deck.Count - tripsRemainder + modifier]);
                modifier++;
            }
            deckTrips.Add(myRemainders);
            trips++;
        }
        deckLocation = 0;
    }
```

```C#:Solitaire.cs
private GameObject deckButton;

private int deckLocation;
```

```C#:Solitaire.cs
public void DealFromDeck()
    {
        if (deckLocation < trips)
        {
            //draw 3 new cards
            tripsOnDisplay.Clear();
            float xoffset = 2.5f; 

            foreach (string card in deckTrips[deckLocation])
            {
                GameObject newTopCard = Instantiate(cardPrefab, new Vector3(deckButton.transform.position.y, deckButton.transform.position.z), Quaternion.identity, deckButton.transform);
                xoffset = xoffset + 0.5f;
                newTopCard.name = card;
                tripsOnDisplay.Add(card);
                newTopCard.GetComponent<Selectable>().faceUp = true;
            }
            deckLocation++;

        }
        else
        {
            //Restack the top deck
            RestackTopDeck();        
        }
    }

    void RestackTopDeck()
    {

    }
```

public void DealFromDeck()内に

```C#:Solitaire.cs
 // add remaining cards to discard pile

            foreach (Transform child in deckButton.transform)
            {
                if (child.CompareTag("Card"))
                {
                    deck.Remove(child.name);
                    discardPile.Add(child.name);
                    Destroy(child.gameObject);
                }
            }
```

```C#:UserInput
private Solitaire solitaire;
```

void Deck()内に

```C#:UserInput
solitaire.DealFromDeck();
```

public void DealFromDeck()内の
foreach (string card in deckTrips[deckLocation])内の

xoffset = xoffset + 0.5f;の下に

```C#:Solitaire
zoffset = zoffset -0.2f;
```

public void PlayCards()内の
StartCoroutine(SolitaireDeal());の下に

```C#:Solitaire
SortDeckIntoTrips();
```