diff --git a/Assets/Script/Game/GameLogic.cs b/Assets/Script/Game/GameLogic.cs index 8d21ec4..7b9f8f2 100644 --- a/Assets/Script/Game/GameLogic.cs +++ b/Assets/Script/Game/GameLogic.cs @@ -34,6 +34,7 @@ public partial class GameLogic : IDisposable public int SelectedRow { get; private set; } public int SelectedCol { get; private set; } public FioTimer FioTimer { get; private set; } + public bool GameInProgress { get; private set; } // 게임 진행 중인지 확인 #endregion @@ -120,10 +121,9 @@ public partial class GameLogic : IDisposable Debug.Log("## End Game"); ExecuteOnMainThread(() => { - GameManager.Instance.panelManager.OpenConfirmPanel("연결이 끊어졌습니다.", () => + GameManager.Instance.panelManager.OpenConfirmPanel("상대방이 방을 나갔습니다.", () => { - GameManager.Instance.panelManager.OpenEffectPanel(Enums.GameResult.Win); - EndGame(Enums.GameResult.Win); + // TODO: 무승부/항복 등 버튼 동작 안하도록 처리 }); }); break; @@ -199,6 +199,7 @@ public partial class GameLogic : IDisposable break; case Constants.MultiplayManagerState.ReceiveRevengeRequest: Debug.Log("상대방의 재대결 요청이 들어옴"); + ChangeGameInProgress(true); ExecuteOnMainThread(() => { GameManager.Instance.panelManager.OpenDrawConfirmPanel("상대방의 재대결 요청을\n승낙하시겠습니까?", () => @@ -276,7 +277,14 @@ public partial class GameLogic : IDisposable break; case Constants.MultiplayManagerState.OpponentDisconnected: Debug.Log("상대방 강제 종료"); - // 실제로 실행되지 않음. 상대방 강제 종료 시에는 EndGame으로 처리됨 + ExecuteOnMainThread(() => + { + GameManager.Instance.panelManager.OpenConfirmPanel("연결이 끊어졌습니다.", () => + { + GameManager.Instance.panelManager.OpenEffectPanel(Enums.GameResult.Win); + EndGame(Enums.GameResult.Win); + }); + }); break; } ReplayManager.Instance.InitReplayData(UserManager.Instance.Nickname,"nicknameB"); @@ -339,6 +347,9 @@ public partial class GameLogic : IDisposable // 메인스레드에서 게임 시작 private void StartGameOnMainThread() { + ChangeGameInProgress(true); + Debug.Log("GameInProgress 변경 true"); + ExecuteOnMainThread(() => { // 로딩 패널 열려있으면 닫기 @@ -551,10 +562,24 @@ public partial class GameLogic : IDisposable private void TimerUnpause() => FioTimer.StartTimer(); #endregion + + public void ChangeGameInProgress(bool inProgress) + { + if (GameInProgress == inProgress) + return; + + GameInProgress = inProgress; + } public void Dispose() { MultiPlayManager?.LeaveRoom(_roomId); MultiPlayManager?.Dispose(); } + + public void ForceQuit() + { + MultiPlayManager?.ForceQuit(_roomId); + MultiPlayManager?.Dispose(); + } } diff --git a/Assets/Script/Game/GameManager.cs b/Assets/Script/Game/GameManager.cs index 0507fbe..10bc6fc 100644 --- a/Assets/Script/Game/GameManager.cs +++ b/Assets/Script/Game/GameManager.cs @@ -156,6 +156,11 @@ public class GameManager : Singleton private void OnApplicationQuit() { Debug.Log("앱 종료 감지: 소켓 연결 정리 중..."); - _gameLogic?.Dispose(); + + if(_gameLogic.GameInProgress) + _gameLogic?.ForceQuit(); + else + _gameLogic?.Dispose(); + } } \ No newline at end of file diff --git a/Assets/Script/Game/GameUtility/GameRoutine.cs b/Assets/Script/Game/GameUtility/GameRoutine.cs index 18c131f..a6b26cb 100644 --- a/Assets/Script/Game/GameUtility/GameRoutine.cs +++ b/Assets/Script/Game/GameUtility/GameRoutine.cs @@ -1,4 +1,6 @@ -public partial class GameLogic +using UnityEngine; + +public partial class GameLogic { // 돌 카운터 증가 함수 public void CountStoneCounter() => _totalStoneCounter++; @@ -85,5 +87,7 @@ SetState(null); ReplayManager.Instance.SaveReplayDataResult(result); //TODO: 게임 종료 후 행동 구현 + ChangeGameInProgress(false); + Debug.Log("GameInProgress 변경 false"); } } \ No newline at end of file diff --git a/Assets/Script/Game/MultiplayManager.cs b/Assets/Script/Game/MultiplayManager.cs index 1c69ac6..1e8c232 100644 --- a/Assets/Script/Game/MultiplayManager.cs +++ b/Assets/Script/Game/MultiplayManager.cs @@ -218,6 +218,18 @@ public class MultiplayManager : IDisposable _roomId = null; // 방 나가면 roomId 초기화 } + public void ForceQuit(string roomId) + { + if (string.IsNullOrEmpty(_roomId)) + { + Debug.LogError("Disconnect 호출 실패: _roomId가 설정되지 않음"); + return; + } + + _socket.Emit("disconnect", new { roomId = _roomId }); + _roomId = null; // 방 나가면 roomId 초기화 + } + public void RequestSurrender() { if (string.IsNullOrEmpty(_roomId))