////////////////////////////////////////////////////////////////////////// // RoundStartCO ( Coroutine ) private IEnumerator RoundStartCO() { UI.Instance.PrintStatus(""); // Give two random cards to players for (int i = 0; i < MAX_PLAYERS; i++) { VirtualPlayer player = VirtualPlayer.Players[i]; for (int j = 0; j < 2; j++) { Card randomCard = m_Deck[Random.Range(0, m_Deck.Count)].GetComponent <Card>(); player.GetCard(randomCard); } } // Give two random cards to dealer, first is hidden Card randomCard1 = m_Deck[Random.Range(0, m_Deck.Count)].GetComponent <Card>(); Dealer.Instance.GetCard(randomCard1); Card randomCard2 = m_Deck[Random.Range(0, m_Deck.Count)].GetComponent <Card>(); Dealer.Instance.GetCard(randomCard2); // hide mouse Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; m_RoundStartTime = m_HiddenCardShowTime; while (m_RoundStartTime > 0f) { m_RoundStartTime -= Time.deltaTime; yield return(null); } Cursor.visible = true; Cursor.lockState = CursorLockMode.None; randomCard1.Shown = false; // Game setup is completed, players make their own decision VirtualPlayer.Players.ForEach(( VirtualPlayer p ) => p.MakeDecision()); GameActive = true; UI.Instance.PrintStatus("Players Turn"); this.ChechGameStatus(); }
////////////////////////////////////////////////////////////////////////// // Update private void Update() { if (GameManager.GameActive == false || m_IsThrown == false) { return; } transform.position += m_DirectionVector * Time.deltaTime * m_CardSpeed; if (m_ValidThrow == true) { if (m_DestinationPlayer.NeedCard() && (transform.position - m_DestinationPlayer.transform.position).sqrMagnitude < VirtualPlayer.PLAYER_RADIUS * VirtualPlayer.PLAYER_RADIUS) { m_DestinationPlayer.GetCard(this); } } }
////////////////////////////////////////////////////////////////////////// // OnEndDrag ( Interface ) void IEndDragHandler.OnEndDrag(PointerEventData eventData) { // Allowed only on card in deck if (InDeck == false) { return; } // Interaction has benn locked if (GameManager.GameActive == false) { return; } // right button not alowed if (eventData.button == PointerEventData.InputButton.Right) { return; } // not valid during dealer phase if (GameManager.Instance.CurrentPhase == GameManager.GAMEPHASE.DEALER) { return; } float distance = Vector3.Distance(transform.position, m_StartDragPosition); if (distance < 20) { transform.position = m_StartDragPosition; return; } m_ImageBackground.raycastTarget = false; m_ImageForeground.raycastTarget = false; m_IsThrown = true; m_DirectionVector = (transform.position - m_StartDragPosition).normalized; m_CardSpeed = distance; for (int i = 0; i < GameManager.MAX_PLAYERS; i++) { VirtualPlayer player = VirtualPlayer.Players[i]; // Giving card directly to a player if (player.NeedCard() && (Input.mousePosition - player.transform.position).sqrMagnitude < VirtualPlayer.PLAYER_RADIUS * VirtualPlayer.PLAYER_RADIUS) { player.GetCard(this); InDeck = false; m_DestinationPlayer = player; GameManager.Instance.Deck.Remove(gameObject); return; } // Throwing card Vector3 directionDectToPlayer = (player.transform.position - UI.Instance.Deck.transform.position); Vector3 directionDeckToCard = (transform.position - UI.Instance.Deck.transform.position); if (Vector3.Angle(directionDectToPlayer, directionDeckToCard) < 10f) { m_ValidThrow = true; m_DestinationPlayer = player; break; } } InDeck = false; transform.SetParent(transform.parent.parent); }