public bool allowedToPlay(SCCardInfo[] cards, bool updateIfAllowed) { if(cards[0] == null || cards.Length != 4){ Debug.Log("Invalid cards; not suitable for checking"); return false; } if(topCards == null || topCards[0] == null){ if(cards[0].suit == "club" && cards[0].number == 3 && cards[1] == null){ return true; }else{ Debug.Log("This card is not the 3 of clubs."); return false; } } if(!areCardNumbersSame(cards)){ Debug.Log("Cards must be the same."); return false; } if(topCards[0].isAnyCard()){ return true; } int numberOfTopCards = numberOfCards(topCards); int numberOfPlayedCards = numberOfCards(cards); if(cards[0].number == 2){ if(numberOfTopCards == 1 && numberOfPlayedCards != 1){ Debug.Log("You must play only one 2"); return false; }else if(numberOfTopCards > 1 && numberOfPlayedCards != numberOfTopCards - 1){ Debug.Log("You must play one less two"); return false; } }else{ if(numberOfTopCards != numberOfPlayedCards){ Debug.Log("You must play the same number of cards."); return false; } } if(cardValues[cards[0].number] > cardValues[topCards[0].number]){ return true; } Debug.Log("Other tests failed."); return false; }
public bool playExistingCard(GameObject[] cards, bool strict, ref string extra) { SCCardInfo[] cardsToCheck = new SCCardInfo[4]; int cardsAdded = 0; for(int i = 0; i < cardsToCheck.Length; ++i){ if(cards[i] == null){ continue; } SCCard prop = cards[i].GetComponent<SCCard>(); cardsToCheck[i] = new SCCardInfo(prop.suit, prop.number, prop.guiCard); ++cardsAdded; } if(!cardsToCheck[0].guiCard && strict && !rules.allowedToPlay(cardsToCheck, false)){ return false; } rules.updateTopCards(cardsToCheck, false); SCHand h = hand.GetComponent<SCHand>(); if(!h.guiHand){ h.updateHeldCards(); } SCAnimator anim; Vector3 targetPosition; Vector3 targetRotation; for(int i = 0; i < cards.Length; ++i){ if(cards[i] == null){ continue; } this.cards.Add(cards[i]); cards[i].transform.SetParent(transform); SCCard prop = cards[i].GetComponent<SCCard>(); anim = cards[i].GetComponent<SCAnimator>(); prop.setSelectable(false); prop.active = true; prop.higher = false; targetPosition = cloneVector3(tableCenter); targetPosition.x += Random.Range(-5.0f, 5.0f); targetPosition = fixZPosition(targetPosition, this.cards.Count - (cardsAdded - i)); targetRotation = new Vector3(0, 0, (Random.Range(0, 2) == 0) ? Random.Range(0.0f, 12.0f) : Random.Range(348.0f, 359.0f)); anim.moveTo(targetPosition, 0.5f, SCAnimator.EASE_OUT, 0.1f * i); anim.rotateToTarget(targetRotation, 0.5f, SCAnimator.EASE_OUT, 0.1f * i); if(i == cardsAdded - 1 && !rules.isAnyOtherCardPossible()){ anim.callBack = scrapPile; extra = "repeat_turn"; } } for(int i = 0; i < this.cards.Count - cardsAdded; ++i){ anim = this.cards[i].GetComponent<SCAnimator>(); targetPosition = cloneVector3(this.cards[i].transform.localPosition); //targetPosition.x += spacing; anim.moveTo(fixZPosition(targetPosition, i), 0.5f, SCAnimator.EASE_OUT); } return true; }
public void scrapPile() { for(int i = 0; i < pile.Count; ++i){ Vector3 targetPosition = cloneVector3(pile[i].transform.localPosition); targetPosition.z = 0.05f * (cards.Count + pile.Count - i); pile[i].transform.localPosition = targetPosition; } for(int i = 0; i < cards.Count; ++i){ SCCard prop = cards[i].GetComponent<SCCard>(); prop.setSelectable(false); prop.active = true; prop.higher = false; pile.Add(cards[i]); SCAnimator anim = cards[i].GetComponent<SCAnimator>(); Vector3 targetPosition = cloneVector3(pileLocation); targetPosition.z = 0.05f * (cards.Count - i); anim.moveTo(targetPosition, 0.5f, SCAnimator.EASE_OUT); } cards = new List<GameObject>(); SCCardInfo[] newTopCards = new SCCardInfo[4]; newTopCards[0] = new SCCardInfo(SCCardInfo.ANY_SUIT, SCCardInfo.ANY_NUMBER); rules.updateTopCards(newTopCards, true); SCHand h = hand.GetComponent<SCHand>(); if(!h.guiHand){ h.updateHeldCards(); } }
public void playNewCard(SCCardInfo[] cards, Vector3 origin) { GameObject[] cardsToPlay = new GameObject[cards.Length]; for(int i = 0; i < cardsToPlay.Length; ++i){ if(cards[i] == null){ continue; } GameObject card = Instantiate(cardObj); SCCard prop = card.GetComponent<SCCard>(); prop.suit = cards[i].suit; prop.number = cards[i].number; prop.createCard(); card.transform.SetParent(transform); card.transform.localPosition = origin; cardsToPlay[i] = card; } string extra = ""; playExistingCard(cardsToPlay, false, ref extra); }
private void printCards(SCCardInfo[] cards) { if(cards == null){ Debug.Log("There are no cards."); return; } string p = "Cards: "; for(int i = 0; i < cards.Length; ++i){ if(cards[i] == null){ continue; } p += "" + cards[i].number + cards[i].suit + " "; } Debug.Log(p); }
private bool areCardNumbersSame(SCCardInfo[] cards) { int number = cards[0].number; for(int i = 1; i < cards.Length && cards[i] != null; ++i){ if(cards[i].number != number){ return false; } } return true; }
private int numberOfCards(SCCardInfo[] cards) { for(int i = 0; i < cards.Length; ++i){ if(cards[i] == null){ return i; } } return 0; }
private int numberOfCards(SCCardInfo[] cards) { int val = 0; for(int i = 0; i < cards.Length; ++i){ if(cards[i] != null){ ++val; } } return val; }
public void updateTopCards(SCCardInfo[] cards, bool trashPrevious) { if(cards[0] == null || cards.Length != 4){ Debug.Log("Invalid cards; cannot set as top"); return; } if(trashPrevious){ previousTopCards = null; }else{ previousTopCards = topCards; } topCards = cards; }
public void userPlayed(SCCardInfo[] cards, SCPlayerInfo playedBy) { cards[0].playedBy = playedBy; playedCards.Add(cards); if(consecutiveCards == 0){ ++consecutiveCards; }else if(SCRules.cardValues[playedCards[playedCards.Count - 2][0].number] + 1 == SCRules.cardValues[playedCards[playedCards.Count - 1][0].number]){ ++consecutiveCards; }else{ resetConsecutiveCards(); } }
/********************************************************************************************/ /** User Input Functions ********************************************************************/ /********************************************************************************************/ public void userPlayed(SCCardInfo[] playedCards, string extra) { turnsSkipped = 0; string message = "spawn_card:"; for(int i = 1; i <= playedCards.Length && playedCards[i - 1] != null; ++i){ message += (i == 1 ? "" : ",") + "suit" + i + "=" + playedCards[i - 1].suit + ",number" + i + "=" + playedCards[i - 1].number; } sendMessageToAllAccept(turnIndex, message); logic.userPlayed(playedCards, connectedPlayers[turnIndex]); int[] discardsAllowed = logic.discardsAllowed(); for(int i = 0; i < discardsAllowed.Length; ++i){ if(discardsAllowed[i] > 0){ sendMessageTo(i, "discard:num=" + discardsAllowed[i]); } } if(extra == "repeat_turn"){ reallowTurn(); }else if(extra == "out"){ connectedPlayers[turnIndex].outOfGame = true; logic.resetConsecutiveCards(); sendMessageToAllAccept(turnIndex, "scrap_pile:safe=true"); if(getOutPlayers() == connectedPlayers.Count - 1){ newRound(); }else{ advanceTurn(); } }else{ advanceTurn(); } }
private void onUpdateTopCardsCommand(SCMessageInfo info) { SCTable table = communicator.gameObject.GetComponentInChildren<SCTable>(); SCCardInfo[] cards = new SCCardInfo[4]; for(int i = 0; i < 4; ++i){ string suit = info.getValue("suit" + i); string number = info.getValue("number" + i); if(suit == null || number == null){ break; } cards[i] = new SCCardInfo(suit, SCNetworkUtil.toInt(number)); } if(cards[0] == null){ return; }else{ table.getRules().updateTopCards(cards, false); } }
private void onSpawnCardCommand(SCMessageInfo info) { SCTable table = communicator.gameObject.GetComponentInChildren<SCTable>(); SCCardInfo[] cardsToSpawn = new SCCardInfo[4]; for(int i = 1; i <= cardsToSpawn.Length; ++i){ string suit = info.getValue("suit" + i); string number = info.getValue("number" + i); if(suit == null || number == null){ break; } cardsToSpawn[i - 1] = new SCCardInfo(suit, SCNetworkUtil.toInt(number)); } table.playNewCard(cardsToSpawn, new Vector3(0, 40, 0)); }
private void onPlayCardCommand(SCMessageInfo info) { SCCardInfo[] playedCards = new SCCardInfo[4]; for(int i = 0; i < playedCards.Length; ++i){ string suit = info.getValue("suit" + (i + 1)); string number = info.getValue("number" + (i + 1)); if(suit == null || number == null){ break; } playedCards[i] = new SCCardInfo(suit, SCNetworkUtil.toInt(number)); } localServer.userPlayed(playedCards, info.getValue("extra")); }