using System.Collections; using UnityEngine; using CodeJay.Enum; using System.Collections.Generic; // GamePanel Ŭ������ �̱������� ����Ǿ� �ֽ��ϴ�. // �ܺο����� GamePane.Instance�� ���ؼ� ������ �� �ֽ��ϴ�. public partial class GamePanel : MonoBehaviour { #region Enum public enum EGameWorkFlowType { DistributeCard, DiscardNEffectBeforeDiscard, CheckMatchedCardAfterDiscard, FlipCenterCard, BringTheGetableCards, CheckCombination, CheckEndOrGoStop, Max } public enum EGameStateType { None, InProgress, Complete, Error, Max } #endregion #region Fields private WaitForEndOfFrame _endofFrame = new WaitForEndOfFrame(); private WaitForSeconds _waitforSecondsZeroDotZeroOne = new WaitForSeconds(0.05f); private WaitForSeconds _waitforSecondsZeroDotOne = new WaitForSeconds(0.1f); private WaitForSeconds _waitforSecondsZeroDotTwoFive = new WaitForSeconds(0.25f); private WaitForSeconds _waitforSecondsAIBehaviour = new WaitForSeconds(1f); private CardSlot _discardSlot = null; private Dictionary _dicCoroutineStates; private EGameWorkFlowType _currentCoroutineType = EGameWorkFlowType.Max; #endregion #region Properties private EGameWorkFlowType CurrentCoroutineType { get => _currentCoroutineType; set => _currentCoroutineType = value; } #endregion #region Coroutines // ���� Ȯ���ϴ� �ڷ�ƾ private IEnumerator coroCheckCombination() { // �÷��̾����̶�� if (PlayerTurn) { // ���� �÷��̾� ���ھ�� ī���� ������ ã�´�. var combinations = CodeJay.CodeJayUtility.Utility.GetCombinationTypes(ref _lstPlayerScoreCards); // ������ �ϳ��� �ִٸ� for (int i = 0; i < combinations.Count; i++) { // ������ ���� �����̶�� if (_hashPlayerCombinations.Contains(combinations[i]) == false) { // ���� '��' ������ �������� �ʵ��� �����ش�. switch (combinations[i]) { case ECombinationType.Three_Ghwang: if (_hashPlayerCombinations.Contains(ECombinationType.Be_Three_Ghwang)) _hashPlayerCombinations.Remove(ECombinationType.Be_Three_Ghwang); break; case ECombinationType.Four_Ghwang: if (_hashPlayerCombinations.Contains(ECombinationType.Be_Three_Ghwang)) _hashPlayerCombinations.Remove(ECombinationType.Be_Three_Ghwang); if (_hashPlayerCombinations.Contains(ECombinationType.Three_Ghwang)) _hashPlayerCombinations.Remove(ECombinationType.Three_Ghwang); break; case ECombinationType.Five_Ghwang: if (_hashPlayerCombinations.Contains(ECombinationType.Be_Three_Ghwang)) _hashPlayerCombinations.Remove(ECombinationType.Be_Three_Ghwang); if (_hashPlayerCombinations.Contains(ECombinationType.Three_Ghwang)) _hashPlayerCombinations.Remove(ECombinationType.Three_Ghwang); if (_hashPlayerCombinations.Contains(ECombinationType.Four_Ghwang)) _hashPlayerCombinations.Remove(ECombinationType.Four_Ghwang); break; } // ������ �߰� �� ���� ��ٸ� _hashPlayerCombinations.Add(combinations[i]); yield return EffectPanel.Direct(combinations[i], true); } } // ���� �߰� �� ���ھ� �������� int score = GetTotalScore(true, false); // '��' ����� �������� int peeNumber = GetScoreBoardTypeNumber(true, ECardScoreType.Pee); bool hasSepYulgget = false; for (int i = 0; i < _lstPlayerScoreCards.Count; i++) { if (_lstPlayerScoreCards[i] == ECardType.Sep_Yulkkeut) { hasSepYulgget = true; break; } } // ������ 5�� �̻��̰� 9�� ������ ���ھ� ���忡 ������ �ְ�, ������ ���Ƿ� ������� ������ �ʾҴٸ�. if (score >= 5 && hasSepYulgget && _isSelctedSepYulggetState == false) { _isSelctedSepYulggetState = true; CardSlot slot = GetCardSlot(ECardType.Sep_Yulkkeut); if (slot.LocationType == ECardLocationType.Player_Score) { bool result = false; System.Action action = (bool b) => result = b; GameManager.UI.ShowNStackPopup(EPopupType.DoublePeeSelectPopup).SetData(action); yield return _waitforSecondsZeroDotOne; yield return new WaitUntil(() => GameManager.UI.IsOpendPopup(EPopupType.DoublePeeSelectPopup) == false); if (result) { slot.Move(ECardLocationType.Player_Score, ECardLocationType.Player_Score, Player_Pee.AddCard(ECardType.Sep_Yulkkeut)); } } } } else { // �÷��̾� ���� 9�� ���� ���ø� �ڵ��̰� ��� ���� SortAICards(); var combinations = CodeJay.CodeJayUtility.Utility.GetCombinationTypes(ref _lstAIScoreCards); for (int i = 0; i < combinations.Count; i++) { if (_hashAICombinations.Contains(combinations[i]) == false) { // ���� '��' ������ �������� �ʵ��� �����ش�. switch (combinations[i]) { case ECombinationType.Three_Ghwang: if (_hashAICombinations.Contains(ECombinationType.Be_Three_Ghwang)) _hashAICombinations.Remove(ECombinationType.Be_Three_Ghwang); break; case ECombinationType.Four_Ghwang: if (_hashAICombinations.Contains(ECombinationType.Be_Three_Ghwang)) _hashAICombinations.Remove(ECombinationType.Be_Three_Ghwang); if (_hashAICombinations.Contains(ECombinationType.Three_Ghwang)) _hashAICombinations.Remove(ECombinationType.Three_Ghwang); break; case ECombinationType.Five_Ghwang: if (_hashAICombinations.Contains(ECombinationType.Be_Three_Ghwang)) _hashAICombinations.Remove(ECombinationType.Be_Three_Ghwang); if (_hashAICombinations.Contains(ECombinationType.Three_Ghwang)) _hashAICombinations.Remove(ECombinationType.Three_Ghwang); if (_hashAICombinations.Contains(ECombinationType.Four_Ghwang)) _hashAICombinations.Remove(ECombinationType.Four_Ghwang); break; } _hashAICombinations.Add(combinations[i]); yield return EffectPanel.Direct(combinations[i], false); } } int score = GetTotalScore(false, false); int peeNumber = GetScoreBoardTypeNumber(false, ECardScoreType.Pee); bool hasSepYulgget = false; for (int i = 0; i < _lstAIScoreCards.Count; i++) { if (_lstAIScoreCards[i] == ECardType.Sep_Yulkkeut) { hasSepYulgget = true; break; } } if (score >= 5 && hasSepYulgget && _isSelctedSepYulggetState == false) { _isSelctedSepYulggetState = true; CardSlot slot = GetCardSlot(ECardType.Sep_Yulkkeut); if (slot.LocationType == ECardLocationType.AI_Score) { bool result = Random.Range(0, 2) > 0; GameManager.UI.ShowNStackPopup(EPopupType.WaitForAIBehaviourPopup).SetData(1f); yield return _waitforSecondsAIBehaviour; if (result) { UseSepYulgget_To_Pee = result; slot.Move(ECardLocationType.Player_Score, ECardLocationType.Player_Score, Player_Pee.AddCard(ECardType.Sep_Yulkkeut)); } } } } GameManager.Event.InvokeEvent(EEventType.OnSynchronizeScore); CurrentCoroutineType = EGameWorkFlowType.CheckEndOrGoStop; } private IEnumerator coroCheckEndOrGoStop() { if (GetMatchedCardSlotNumber(ECardLocationType.Center) <= 0) { if (PlayerTurn) { if (GetTotalScore(true, false) >= 7) { GameOver = true; GameManager.UI.ShowNStackPopup(EPopupType.ResultPopup).SetData(true); } else { int handNumber = GetMatchedCardSlotNumber(ECardLocationType.Player_Hand); int centerNumber = GetMatchedCardSlotNumber(ECardLocationType.Center); if (handNumber <= 0 && centerNumber <= 0) { yield return StartCoroutine(EffectPanel.NagariEffect()); GameManager.UI.ShowNStackPopup(EPopupType.NagariPopup); GameOver = true; } GameOver = true; } } else { if (GetTotalScore(false, false) >= 7) { GameOver = true; GameManager.UI.ShowNStackPopup(EPopupType.ResultPopup).SetData(false); } else { int handNumber = GetMatchedCardSlotNumber(ECardLocationType.AI_Hand); int centerNumber = GetMatchedCardSlotNumber(ECardLocationType.Center); if (handNumber <= 0 && centerNumber <= 0) { yield return StartCoroutine(EffectPanel.NagariEffect()); GameManager.UI.ShowNStackPopup(EPopupType.NagariPopup); } GameOver = true; } } } else if (PlayerTurn) { int score = GetTotalScore(true, false); if (score >= 7) { int handNumber = GetMatchedCardSlotNumber(ECardLocationType.Player_Hand); if (Player_Go <= 0) { if (handNumber <= 0) { yield return EffectPanel.Direct(EEffectDirectType.Stop, true); GameManager.UI.ShowNStackPopup(EPopupType.ResultPopup).SetData(true); GameOver = true; } else { // ������ ���� ó�� ���� ����. GameManager.UI.ShowNStackPopup(EPopupType.GoStopPopup); yield return _waitforSecondsZeroDotOne; yield return new WaitUntil(() => GameManager.UI.IsOpendPopup(EPopupType.GoStopPopup) == false); if (GameOver) yield break; } } // �̹� 1�� �̻��� go�� �߱� ������, �ٽ� Go�� Stop�� �����Ϸ��� ���� ������ �������� ���ƾ��Ѵ�. else if (score > _prevScore_Player) { if (handNumber > 0) { GameManager.UI.ShowNStackPopup(EPopupType.GoStopPopup); yield return _waitforSecondsZeroDotOne; yield return new WaitUntil(() => GameManager.UI.IsOpendPopup(EPopupType.GoStopPopup) == false); if (GameOver) yield break; } else { yield return EffectPanel.Direct(EEffectDirectType.Stop, true); GameManager.UI.ShowNStackPopup(EPopupType.ResultPopup).SetData(true); GameOver = true; } } // ���� �������� ���� �ʾƼ� GO�� Stop�� ������ �� ����. else { int centerNumber = GetMatchedCardSlotNumber(ECardLocationType.Center); if (handNumber <= 0) { yield return StartCoroutine(EffectPanel.NagariEffect()); GameManager.UI.ShowNStackPopup(EPopupType.NagariPopup); GameOver = true; } } _prevScore_Player = score; } } else { int score = GetTotalScore(false, false); int handNumber = GetMatchedCardSlotNumber(ECardLocationType.AI_Hand); if (score >= 7) { if (AI_Go <= 0) { if (handNumber <= 0) { GameOver = true; yield return EffectPanel.Direct(EEffectDirectType.Stop, PlayerTurn); GameManager.UI.ShowNStackPopup(EPopupType.ResultPopup).SetData(false); } else { GameManager.UI.ShowNStackPopup(EPopupType.WaitForAIBehaviourPopup).SetData(1f); yield return _waitforSecondsZeroDotOne; yield return new WaitUntil(() => GameManager.UI.IsOpendPopup(EPopupType.WaitForAIBehaviourPopup) == false); // �������� GO�� Stop�� ����. // 난이도 상승을 위해서는 고 판단을 할 수 있어야 한다. // 플레이어가 고가 1이상인가 // 플레이어의 점수가 5점 이상인가 bool go = false; int playerScore = GetTotalScore(true, false); if (Player_Go >= 1 || playerScore >= 5) { go = false; } else { go = Random.Range(0, 2) == 1; } if (go) { AI_Go++; yield return EffectPanel.GoDirect(AI_Go, false); } else { GameOver = true; yield return new WaitForSeconds(EffectPanel.Direct(EEffectDirectType.Stop, PlayerTurn)); GameManager.UI.ShowNStackPopup(EPopupType.ResultPopup).SetData(false); } if (GameOver) yield break; } } else if (score > _prevScore_AI) { if (handNumber > 0) { GameManager.UI.ShowNStackPopup(EPopupType.WaitForAIBehaviourPopup).SetData(1f); yield return _waitforSecondsZeroDotOne; yield return new WaitUntil(() => GameManager.UI.IsOpendPopup(EPopupType.WaitForAIBehaviourPopup) == false); // �������� GO�� Stop�� ����. bool go = false; int playerScore = GetTotalScore(true, false); if (Player_Go >= 1 || playerScore >= 5) { go = false; } else { go = Random.Range(0, 2) == 1; } if (go) { AI_Go++; yield return EffectPanel.GoDirect(AI_Go, false); } else { GameOver = true; yield return EffectPanel.Direct(EEffectDirectType.Stop, PlayerTurn); GameManager.UI.ShowNStackPopup(EPopupType.ResultPopup).SetData(false); } if (GameOver) yield break; } else { yield return EffectPanel.Direct(EEffectDirectType.Stop, true); GameManager.UI.ShowNStackPopup(EPopupType.ResultPopup).SetData(false); GameOver = true; } } else { int centerNumber = GetMatchedCardSlotNumber(ECardLocationType.Center); if (handNumber <= 0) { yield return StartCoroutine(EffectPanel.NagariEffect()); GameManager.UI.ShowNStackPopup(EPopupType.NagariPopup); GameOver = true; } } _prevScore_AI = score; } } if (!GameOver) { ChangeTurn(); CurrentCoroutineType = EGameWorkFlowType.DiscardNEffectBeforeDiscard; } } #endregion #region Methods private void ChangeTurn() { if (PlayerTurn) _isFirstTurn_Player = false; else _isFirstTurn_AI = false; PlayerTurn = !PlayerTurn; } #endregion } /* GPT ��ũ�÷ο� ���� private IEnumerator coroMain() { // ���� ����: ī�� �й� yield return StartCoroutine(coroDistributeCard()); // ī�� �й� �� �ʿ��� �ð���ŭ ��� yield return new WaitForSeconds(1.0f); // �÷��̾� ī�� ���� this.SortPlayerCards(); // ���� ���� �ݺ� while (!GameOver) { // ���� �÷��̾��� �� ���� (���� �Ǵ� AI) yield return StartCoroutine(coroPlayerTurn()); // �÷��̾ ī�带 �����Ͽ� ���� ECardType selectedCard = this.SelectCard(); yield return StartCoroutine(coroDiscard(selectedCard)); // �ٴ��п� ��Ī�� ī�� ó�� yield return StartCoroutine(coroMatchAndCollectCards(selectedCard)); // �߾� ī�嵦���� ī�� ������ yield return StartCoroutine(coroFlipCenterCard()); // ���ھ�� ������Ʈ: ���� ��� �� ���� �˻� this.UpdateScoreboard(); // ������ 7�� �̻��� ��� '��' �Ǵ� '��ž' ���� if (currentScore >= 7) { yield return StartCoroutine(coroChooseGoOrStop()); } // ���� ���� ���� Ȯ�� if (IsGameOver()) { GameOver = true; break; } // ���� �ѱ�� this.ChangeTurn(); } // ���� ����: ��� ǥ�� this.ShowGameOver(); yield return null; } // ���õ� ī�忡 ���� �ٴ��п� ��Ī�Ǵ� ī�带 �����ϴ� �ڷ�ƾ private IEnumerator coroMatchAndCollectCards(ECardType selectedCard) { // ��Ī ���� ����... // ��Ī�� ī�� ���� �� ó�� ���� ����... yield return null; } // �÷��̾ '��' �Ǵ� '��ž'�� �����ϴ� �ڷ�ƾ private IEnumerator coroChooseGoOrStop() { // '��' �Ǵ� '��ž' ���� ���� ����... yield return null; } // ��Ÿ �ʿ��� �ڷ�ƾ�� �޼ҵ� ����... */ /* ���� 2 // ... ���� �ڵ� ... // �߾� ī�嵦���� ī�� ������ yield return StartCoroutine(coroFlipCenterCard()); // ������ ī��� �ٴ��� ��Ī �˻� yield return StartCoroutine(coroCheckMatchAfterFlip()); // ��Ī�� ��� �ش��ϴ� ���� ���� if (IsMatched) { yield return StartCoroutine(coroPerformMatchedAction()); } // ���ھ�� ������Ʈ: ���� ��� �� ���� �˻� this.UpdateScoreboard(); // ... �ļ� �ڵ� ... // ������ ī��� �ٴ��� ��Ī �˻� �ڷ�ƾ private IEnumerator coroCheckMatchAfterFlip() { // ������ ī��� �ٴ����� ��Ī ���� ����... yield return null; } // ��Ī�� ��� ������ �����ϴ� �ڷ�ƾ private IEnumerator coroPerformMatchedAction() { // ��, �ڻ�, ���Ա�, �ڻ��Ա�, �� ���� ���� ����... yield return null; } */