LoginSignup
0
0

More than 3 years have passed since last update.

Solitaire(5)

Last updated at Posted at 2019-09-14

bool Stackableとは別に新たにStackメソッドを作る

UserInput
void Stack(GameObject selected)
        {
            // if on top of king or empty bottom stack the cards in place
            // else stack the cards with a negative y offset

            Selectable s1 = slot1.GetComponent<Selectable>();
            Selectable s2 = selected.GetComponent<Selectable>();
            float yOffset = 0.3f;

            if (s2.top || (!s2.top && s1.value == 13))
            {
                yOffset = 0;   
            }

            slot1.transform.position = new Vector3(selected.transform.position.x, selected.transform.position.y - yOffset, selected.transform.position.z - 0.01f);
            slot1.transform.parent = selected.transform; //this makes their children move with the parents


            if (s1.inDeckPile) // removes the cards from the top pile to prevent dupulicate cards
            {
                solitaire.tripsOnDisplay.Remove(slot1.name);
            }
            else if (s1.top && s2.top && s1.value == 1) // allows movement of cards between top spots
            {
                solitaire.topPos[s1.row].GetComponent<Selectable>().value = 0;
                solitaire.topPos[s1.row].GetComponent<Selectable>().suit = null;
            }
            else if (s1.top)
            {
                solitaire.topPos[s1.row].GetComponent<Selectable>().value = s1.value - 1;
            }
            else
            {
                solitaire.bottoms[s1.row].Remove(slot1.name);
            }


            s1.inDeckPile = false; // you cannot add cards to the trips pile so this is always fine
            s1.row = s2.row;

            if (s2.top)
            {
                solitaire.topPos[s1.row].GetComponent<Selectable>().value = s1.value;
                solitaire.topPos[s1.row].GetComponent<Selectable>().suit = s1.suit;
                s1.top = true;
            }
            else
            {
                s1.top = false;
            }

            // after completing move reset slot1 to be essentially null as being null will break the logic
            slot1 = this.gameObject;

        }

bool Stackable(GameObject selected)を

UserInput
bool Stackable(GameObject selected)
    {
        Selectable s1 = slot1.GetComponent<Selectable>();
        Selectable s2 = selected.GetComponent<Selectable>();
        // compare them to see if they stach


        if (!s2.inDeckPile) //デッキファイルじゃない時に
        {
            if (s2.top) // if in the top pile must stack suited Ace to King
            {
                if (s1.suit == s2.suit || (s1.value == 1 && s2.suit == null))
                {
                    if (s1.value == s2.value + 1)
                    {
                        return true;
                    }
                }
            }
            else // if in the bottom pile must stack alternate colours King to Ace
            {
                if (s1.value == s2.value - 1)
                {
                    bool card1Red = true;
                    bool card2Red = true;

                    if (s1.suit == "C" || s1.suit == "S")
                    {
                        card1Red = false;
                    }

                    if (s2.suit == "C" || s2.suit == "S")
                    {
                        card2Red = false;
                    }

                    if (card1Red == card2Red)
                    {
                        print("Not stackable");
                        return false;
                    }
                    else
                    {
                        print("Stackable");
                        return true;
                    }
                }
            }
        }
        return false;
    }

に書き換える

void Card(GameObject selected)内の
print("Clicked on Card");下に

UserInput
f (!selected.GetComponent<Selectable>().faceUp) // if the card clicked on is facedown
        {
            // if the card clicked on is not blocked
            // flip it over
            selected.GetComponent<Selectable>().faceUp = true;
            slot1 = this.gameObject;
        }

追加する

一番下に

UserInput
bool Blocked(GameObject selected)
    {
        Selectable s2 = selected.GetComponent<Selectable>();
        if (s2.inDeckPile == true)
        {
            if (s2.name == solitaire.tripsOnDisplay.Last()) // if it is the last trip it is not blocked
            {
                return false;
            }
            else
            {
                print(s2.name + " is blocked by " + solitaire.tripsOnDisplay.Last()); // check if it is the bottom card
                return true;
            }
        }
        else
        {
            if (s2.name == solitaire.bottoms[s2.row].Last())
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }

追加する

void Card(GameObject selected)内の
if (!selected.GetComponent().faceUp) // if the card clicked on is facedown下を

UserInput
if (!Blocked(selected))//if the card clicked on is not blocked
            {
                // flip it over
                selected.GetComponent<Selectable>().faceUp = true;
                slot1 = this.gameObject;
            }

変更する

void Card(GameObject selected)内の

// if the card clicked on is in the deck pile with the trips
// if it is not blocked
//select it

UserInput
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))
            {
                slot1 = selected;
            }
        }

に書き換える

void Top()の中身を

UserInput
void Top(GameObject selected) //Topを認識させる
    {
        // Top click actions
        print("Clicked on Top");
        if (slot1.CompareTag("Card"))
        {
            // if the card is an ace and the empty slot is top then stack
            if (slot1.GetComponent<Selectable>().value == 1)
            {
                Stack(selected);
            }
        }
    }

に書き換える

void GetMouseClick ()内の
Top()を

UserInput
Top(hit.collider.gameObject); //Topを触ったとき

に書き換える

27行目あたりのvoid GetMouseClick ()内の
Bottom();を

UserInput
Bottom(hit.collider.gameObject); //Bottomを触ったとき

に書き換える

137行目あたりのvoid Bottom()を

UserInput
void Bottom(GameObject selected) //BottomにKを置けるようにする
    {
        // Bottom click actions
        print("Clicked on Bottom");
        // if the card is a king and the empty slot is bottom then stack

        if (slot1.CompareTag("Card"))
        {
            if (slot1.GetComponent<Selectable>().value == 13)
            {
                Stack(selected);
            }
        }


    }

に書き換える

void RestackTopDeck()の中身を

Solitaire
void RestackTopDeck()
    {
        deck.Clear(); //一度使ったカードをデッキから削除する
        foreach (string card in discardPile)
        {
            deck.Add(card);
        }
        discardPile.Clear();
        SortDeckIntoTrips();
    }

に書き換える

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0