Merge pull request #66 from Degulleo/DO-70-타임아웃-30초-멀티플레이-처리

DO-70 [Feat] 타임아웃 30초 멀티플레이 처리
This commit is contained in:
Jay 2025-03-27 14:11:22 +09:00 committed by GitHub
commit bafdbc0696
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 51 additions and 9 deletions

View File

@ -18,6 +18,7 @@
ExitRoom, // 자신이 방을 빠져 나왔을 때
EndGame, // 상대방이 접속을 끊거나 방을 나갔을 때
DoSurrender, // 상대방이 항복했을 때
SurrenderConfirmed // 항복 요청이 성공적으로 전송되었을 때
SurrenderConfirmed, // 항복 요청이 성공적으로 전송되었을 때
ReceiveTimeout // 상대방이 타임 아웃일 때
};
}

View File

@ -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);

View File

@ -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);
}
/// <summary>
/// 타임 아웃 요청
/// </summary>
public void SendTimeout()
{
if (string.IsNullOrEmpty(_roomId))
{
Debug.LogError("LeaveRoom 호출 실패: _roomId가 설정되지 않음");
return;
}
_socket.Emit("sendTimeout",new { roomId = _roomId });
}
/// <summary>
/// 타임 아웃 수신
/// </summary>
/// <param name="response"></param>
private void ReceiveTimeout(SocketIOResponse response)
{
var data = response.GetValue<MessageData>();
_onMultiplayStateChanged?.Invoke(Constants.MultiplayManagerState.ReceiveTimeout, data.message);
}
public void Dispose()
{
if (_socket != null)