diff --git a/Assets/Script/Common/Constants.cs b/Assets/Script/Common/Constants.cs index 328ac54..a15f242 100644 --- a/Assets/Script/Common/Constants.cs +++ b/Assets/Script/Common/Constants.cs @@ -18,6 +18,7 @@ ExitRoom, // 자신이 방을 빠져 나왔을 때 EndGame, // 상대방이 접속을 끊거나 방을 나갔을 때 DoSurrender, // 상대방이 항복했을 때 - SurrenderConfirmed // 항복 요청이 성공적으로 전송되었을 때 + SurrenderConfirmed, // 항복 요청이 성공적으로 전송되었을 때 + ReceiveTimeout // 상대방이 타임 아웃일 때 }; } \ No newline at end of file diff --git a/Assets/Script/Game/GameLogic.cs b/Assets/Script/Game/GameLogic.cs index fb5afb7..61f7e79 100644 --- a/Assets/Script/Game/GameLogic.cs +++ b/Assets/Script/Game/GameLogic.cs @@ -177,7 +177,7 @@ public class MultiPlayerState: BasePlayerState gameLogic.UpdateForbiddenMoves(); #endregion - // gameLogic.currentTurn = _playerType; + gameLogic.currentTurn = _playerType; // gameLogic.stoneController.OnStoneClickedDelegate = (row, col) => // { // HandleMove(gameLogic, row, col); @@ -278,17 +278,24 @@ public class GameLogic : MonoBehaviour //timer 시간초과시 진행 함수 this.fioTimer.OnTimeout = () => { - if (currentTurn == Enums.PlayerType.PlayerA) + // 현재 턴의 플레이어가 로컬(유저)인지 확인 + bool isCurrentPlayerLocal = (currentTurn == Enums.PlayerType.PlayerA && firstPlayerState is PlayerState) || + (currentTurn == Enums.PlayerType.PlayerB && secondPlayerState is PlayerState); + + if (isCurrentPlayerLocal) // 내가 타임 오버일 때 { - GameManager.Instance.panelManager.OpenConfirmPanel($"Game Over: {Enums.PlayerType.PlayerB} Win", - () =>{}); + if (this.gameType == Enums.GameType.MultiPlay) // 멀티플레이인 경우 + { + _multiplayManager?.SendTimeout(); + } + GameManager.Instance.panelManager.OpenEffectPanel(Enums.GameResult.Lose); EndGame(Enums.GameResult.Lose); } - else if (currentTurn == Enums.PlayerType.PlayerB) + else // 로컬에서 자신의 타이머 기준으로 상대방이 타임 오버일 때 { - GameManager.Instance.panelManager.OpenConfirmPanel($"Game Over: {Enums.PlayerType.PlayerA} Win", - () =>{}); - EndGame(Enums.GameResult.Win); + // TODO: 컨펌 패널 OK 버튼 삭제? + GameManager.Instance.panelManager.OpenConfirmPanel("상대방의 응답을 기다리는 중입니다", + () => { } ); } }; } @@ -462,6 +469,14 @@ public class GameLogic : MonoBehaviour EndGame(Enums.GameResult.Lose); }); break; + case Constants.MultiplayManagerState.ReceiveTimeout: + Debug.Log("상대방이 타임 아웃 됨"); + UnityMainThreadDispatcher.Instance().Enqueue(() => + { + GameManager.Instance.panelManager.OpenEffectPanel(Enums.GameResult.Win); + EndGame(Enums.GameResult.Win); + }); + break; } ReplayManager.Instance.InitReplayData(UserManager.Instance.Nickname,"nicknameB"); @@ -492,6 +507,7 @@ public class GameLogic : MonoBehaviour // 기존 멀티플레이 상태 초기화 _multiplayManager = null; _roomId = null; + this.gameType = Enums.GameType.SinglePlay; // 싱글 플레이 상태로 변경 firstPlayerState = new PlayerState(true); diff --git a/Assets/Script/Game/MultiplayManager.cs b/Assets/Script/Game/MultiplayManager.cs index c5a8eab..445dfa5 100644 --- a/Assets/Script/Game/MultiplayManager.cs +++ b/Assets/Script/Game/MultiplayManager.cs @@ -90,6 +90,7 @@ public class MultiplayManager : IDisposable _socket.On("doOpponent", DoOpponent); _socket.On("doSurrender", DoSurrender); _socket.On("surrenderConfirmed", SurrenderConfirmed); + _socket.On("receiveTimeout", ReceiveTimeout); _socket.Connect(); } @@ -218,6 +219,30 @@ public class MultiplayManager : IDisposable _onMultiplayStateChanged?.Invoke(Constants.MultiplayManagerState.SurrenderConfirmed, data.message); } + /// + /// 타임 아웃 요청 + /// + public void SendTimeout() + { + if (string.IsNullOrEmpty(_roomId)) + { + Debug.LogError("LeaveRoom 호출 실패: _roomId가 설정되지 않음"); + return; + } + _socket.Emit("sendTimeout",new { roomId = _roomId }); + } + + /// + /// 타임 아웃 수신 + /// + /// + private void ReceiveTimeout(SocketIOResponse response) + { + var data = response.GetValue(); + + _onMultiplayStateChanged?.Invoke(Constants.MultiplayManagerState.ReceiveTimeout, data.message); + } + public void Dispose() { if (_socket != null)