/// <summary> /// Draws a card from the one list and adds it to the other /// </summary> /// <param name="dst">Destination deck</param> /// <param name="src">Source deck</param> /// <return><c>if (src.Count <= 0)</c></return> public void DrawCard(Player dst, List <Card> src) { if (src.Count <= 0) { Debug.Log(src + " out of cards."); return; } var card = src[src.Count - 1]; DrawCard(dst.hand, src, card); //Instantiate new go_Card GameObject go_card = Instantiate(prefab_card, go_hand.transform); go_Card anana = go_card.GetComponent <go_Card>(); anana.go_owner_player = dst.gameObject; anana.sr.sprite = card._art; anana.card = card; //anana.gameObject.AddComponent<go_Card>(); setOwner(anana, go_hand); //Offset based on number of cards in hand //anana.transform.position += (.5f * transform.right + new Vector3(0, 0, .1f) ) * go_hand.transform.childCount; //anana.FaceUp();//flip up }
public void setOwner(go_Card anana, GameObject pile) { anana.go_owner_player = gameObject; //set owner anana.gameObject.transform.SetParent(pile.transform); //set parent //anana.transform.parent = pile.transform; anana.transform.position = this.transform.position; anana.transform.rotation = transform.rotation; //Offset based on number of cards in hand anana.transform.position += (.5f * transform.right + new Vector3(0, 0, .1f)) * go_hand.transform.childCount; anana.FaceUp();//flip up }
public void Discard(go_Card card) { //Physical transfer card.transform.parent = go_discard.transform; card.transform.position = go_discard.transform.position; //card.transform.position -= (.5f * transform.forward + new Vector3(0, 0, .1f)) * go_discard.transform.childCount; if (card.back.activeSelf) { card.back.SetActive(false); } //Debug.Log( card.transform.GetSiblingIndex()); //logical card transfer DrawCard(discard, hand, card.card); //Reorder this player's hand for (int i = 0; i < go_hand.transform.childCount; i++) { var anana = go_hand.transform.GetChild(i); anana.position = this.transform.position; anana.rotation = transform.rotation; //Offset based on number of cards in hand //print(go_hand.transform.childCount); anana.position += (.5f * transform.right + new Vector3(0, 0, .1f)) * i; } //foreach (Transform anana in go_hand.transform) //{ // anana.position = this.transform.position; // anana.rotation = transform.rotation; // //Offset based on number of cards in hand // print(go_hand.transform.childCount); // anana.position += (.5f * transform.right + new Vector3(0, 0, .1f)) * go_hand.transform.childCount; //} //End this player's turn state = PlayerState.None; GameManager.Instance.SetPlayerNext(); //destroy go_Card below if (go_discard.transform.childCount > 1) { var destroyedCard = go_discard.transform.GetChild(0).gameObject; //EditorGUIUtility.PingObject(destroyedCard); GameObject.Destroy(destroyedCard); } }
private void OnMouseOver() { Player owner_player = go_owner_player.GetComponent <Player>(); Player nextPlayer = GameManager.Instance.getNextPlayer(owner_player); GameObject currentPile = transform.parent.gameObject; //owner_player.Discard(this.GetComponent<Card>()); if (GameManager.Instance.GameState != GameState.Action) { StartCoroutine(WarningPanel.Instance.ShowMessage("Game has not started yet", 2f)); return; } if (Input.GetMouseButtonDown(0)) { if (owner_player.state == PlayerState.Discard) { if (currentPile == owner_player.go_hand) {//if card is in hand owner_player.Discard(this); } } else if (nextPlayer == GameManager.Instance.currentPlayer && GameManager.Instance.currentPlayer.state == PlayerState.Draw) { if (currentPile == owner_player.go_discard) {//if card is in discard pile //if (owner_player.discard.Count ) if (owner_player.discard.Count > 1) { //spawn cards below GameObject go_card = Instantiate(owner_player.prefab_card, currentPile.transform); go_Card anana = go_card.GetComponent <go_Card>(); anana.sr.sprite = owner_player.discard[owner_player.discard.Count - 2]._art; anana.card = owner_player.discard[owner_player.discard.Count - 2]; owner_player.setOwner(anana, currentPile); anana.transform.parent = owner_player.go_discard.transform; anana.transform.position = owner_player.go_discard.transform.position; } nextPlayer.setOwner(gameObject.GetComponent <go_Card>(), nextPlayer.go_hand);//set this card's parent to next player's hand nextPlayer.state = PlayerState.Discard; GameManager.Instance.t_currentPlayer.text = "Current player: \n" + nextPlayer.name + "\n" + nextPlayer.state + "\nPhase"; //owner_player.DiscardToHand(nextPlayer, GameManager.Instance.currentPlayer); //GameObject.Destroy(this); return; } } else { StartCoroutine(WarningPanel.Instance.ShowMessage(GameManager.Instance.currentPlayer.name + " already drew a card", 2f)); print(GameManager.Instance.currentPlayer + " already drew a card"); } //else if (transform.parent.gameObject == owner_player.go_discard) //{//if card is in discard pile // Debug.Log("Index: " + this.transform.GetSiblingIndex()); //} } if (Input.GetMouseButtonDown(1)) { if (currentPile != owner_player.go_hand) { StartCoroutine(WarningPanel.Instance.ShowMessage("End the game with a card from your hand", 2f)); print("End the game with a card from your hand"); return; } if (owner_player.state != PlayerState.Discard) { StartCoroutine(WarningPanel.Instance.ShowMessage("You have to be in your discard phase to end the game.", 2f)); print("You have to be in your discard phase to end the game."); return; } //check then trigger show if (!GameManager.Instance.CheckForShow()) { StartCoroutine(WarningPanel.Instance.ShowMessage("Not everyone has 5 discarded cards, you cannot show", 2f)); print("Not everyone has 5 discarded cards, you cannot show"); return; } else { //discard current card to the middle //trigger show event GameManager.Instance.EndGame(); } } }