bool Stackableとは別に新たにStackメソッドを作る
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)を
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");下に
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;
}
追加する
一番下に
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下を
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
を
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()の中身を
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()を
Top(hit.collider.gameObject); //Topを触ったとき
に書き換える
27行目あたりのvoid GetMouseClick ()内の
Bottom();を
Bottom(hit.collider.gameObject); //Bottomを触ったとき
に書き換える
137行目あたりのvoid Bottom()を
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()の中身を
void RestackTopDeck()
{
deck.Clear(); //一度使ったカードをデッキから削除する
foreach (string card in discardPile)
{
deck.Add(card);
}
discardPile.Clear();
SortDeckIntoTrips();
}
に書き換える