From cbf85de1566f1abd57e592479a9621aa7253850b Mon Sep 17 00:00:00 2001 From: HaeinLEE Date: Wed, 19 Mar 2025 21:21:57 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EA=B8=B0=EB=B3=B4=EC=94=AC=20?= =?UTF-8?q?=EC=B2=98=EC=9D=8C,=20=EC=9D=B4=EC=A0=84,=20=EB=8B=A4=EC=9D=8C,?= =?UTF-8?q?=20=EB=81=9D=20=EB=B2=84=ED=8A=BC=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/LIN/Scripts/GameManagerTestLIN.cs | 300 +++++++++++------------ Assets/Script/Common/Constants.cs | 1 + Assets/Script/Replay/ReplayController.cs | 6 +- Assets/Script/Replay/ReplayManager.cs | 93 ++++--- 4 files changed, 199 insertions(+), 201 deletions(-) diff --git a/Assets/LIN/Scripts/GameManagerTestLIN.cs b/Assets/LIN/Scripts/GameManagerTestLIN.cs index c9b7b5d..19673af 100644 --- a/Assets/LIN/Scripts/GameManagerTestLIN.cs +++ b/Assets/LIN/Scripts/GameManagerTestLIN.cs @@ -1,150 +1,150 @@ -using UnityEngine; -using UnityEngine.SceneManagement; -using System.Collections; -using System.Collections.Generic; - -public class GameManagerTestLIN : Singleton -{ - [SerializeField] private GameObject signinPanel; - [SerializeField] private GameObject signupPanel; - - [SerializeField] private Canvas canvas; - private UserManager _userManager; // UserManager 인스턴스 관리 - - private Enums.GameType _gameType; - private GameLogic _gameLogic; - private StoneController _stoneController; - private Canvas _canvas; - - public Sprite[] profileSprites; //패널에서 사용할 테스트 배열 - - private void Awake() - { - // UserManager가 없으면 생성 - if (UserManager.Instance == null) - { - GameObject userManagerObj = new GameObject("UserManager"); - _userManager = userManagerObj.AddComponent(); - - //TODO: 게임 내에서 기보 타입 적용하기 - _gameType = Enums.GameType.Replay; - } - } - - private void Start() - { - Debug.Log(UserManager.Instance.Nickname); - //TODO: 기보 타입으로 들어왔을 때 데이터 로드 테스트 수정할것 - ReplayManager.Instance.InitReplayBoard(ReplayManager.Instance.LoadReplayDatas()[9]); - - - //게임 씬에서 확인하기 위한 임시 코드 - } - - private void TryAutoSignin() - { - NetworkManager.Instance.GetInfo((userInfo) => - { - Debug.Log("자동 로그인 성공"); - - UpdateMainPanelUI(); - // ScoreData.SetScore(userInfo.score); - // OpenConfirmPanel(userInfo.nickname + "님 로그인 성공하였습니다.", () => { }); - }, () => - { - Debug.Log("자동 로그인 실패"); - // 로그인 화면 - OpenSigninPanel(); - }); - } - - private void UpdateMainPanelUI() - { - MainPanelController mainPanel = FindObjectOfType(); - if (mainPanel != null) - { - mainPanel.UpdateUserInfo(); - } - } - - public void OpenSigninPanel() - { - if (canvas != null) - { - var signinPanelObject = Instantiate(signinPanel, canvas.transform); - } - } - - public void OpenSignupPanel() - { - if (canvas != null) - { - var signupPanelObject = Instantiate(signupPanel, canvas.transform); - } - } - - public void OnClickConfirmButton() - { - _gameLogic.SetNewBoardValue(_gameLogic.currentTurn, _gameLogic.selectedRow,_gameLogic.selectedCol); - - } - - public void OnClickReplayNextButton() - { - Move nextMove = ReplayManager.Instance.GetNextMove(); - if (nextMove != null) - { - if (nextMove.stoneType.Equals(Enums.StoneType.Black.ToString())) - { - _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerA, nextMove.columnIndex, nextMove.rowIndex); - - } - else if (nextMove.stoneType.Equals(Enums.StoneType.White.ToString())) - { - _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerB, nextMove.columnIndex, nextMove.rowIndex); - } - ReplayManager.Instance.PushMove(nextMove); - } - } - - public void OnClickReplayUndoButton() - { - Move targetMove = ReplayManager.Instance.PopMove(); - if (targetMove != null) - { - if (targetMove.stoneType.Equals(Enums.StoneType.Black.ToString())) - { - _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerA, targetMove.columnIndex, targetMove.rowIndex); - - } - else if (targetMove.stoneType.Equals(Enums.StoneType.White.ToString())) - { - _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerB, targetMove.columnIndex, targetMove.rowIndex); - } - ReplayManager.Instance.PushUndoMove(targetMove); - //TODO: 화면상에서 돌 치우기 - } - } - private void ChangeToGameScene(Enums.GameType gameType) - { - _gameType = gameType; - SceneManager.LoadScene("Game"); - } - - protected override void OnSceneLoaded(Scene scene, LoadSceneMode mode) - { - if (scene.name == "Game") - { - _stoneController = GameObject.FindObjectOfType(); - _stoneController.InitStones(); - _gameLogic = new GameLogic(_stoneController, _gameType); - } - else if (scene.name == "Replay") - { - _stoneController = GameObject.FindObjectOfType(); - _stoneController.InitStones(); - _gameLogic = new GameLogic(_stoneController, Enums.GameType.Replay); - } - _canvas = GameObject.Find("Canvas").GetComponent(); - } -} \ No newline at end of file +// using UnityEngine; +// using UnityEngine.SceneManagement; +// using System.Collections; +// using System.Collections.Generic; +// +// public class GameManagerTestLIN : Singleton +// { +// [SerializeField] private GameObject signinPanel; +// [SerializeField] private GameObject signupPanel; +// +// [SerializeField] private Canvas canvas; +// private UserManager _userManager; // UserManager 인스턴스 관리 +// +// private Enums.GameType _gameType; +// private GameLogic _gameLogic; +// private StoneController _stoneController; +// private Canvas _canvas; +// +// public Sprite[] profileSprites; //패널에서 사용할 테스트 배열 +// +// private void Awake() +// { +// // UserManager가 없으면 생성 +// if (UserManager.Instance == null) +// { +// GameObject userManagerObj = new GameObject("UserManager"); +// _userManager = userManagerObj.AddComponent(); +// +// //TODO: 게임 내에서 기보 타입 적용하기 +// _gameType = Enums.GameType.Replay; +// } +// } +// +// private void Start() +// { +// Debug.Log(UserManager.Instance.Nickname); +// //TODO: 기보 타입으로 들어왔을 때 데이터 로드 테스트 수정할것 +// ReplayManager.Instance.InitReplayBoard(ReplayManager.Instance.LoadReplayDatas()[9]); +// +// +// //게임 씬에서 확인하기 위한 임시 코드 +// } +// +// private void TryAutoSignin() +// { +// NetworkManager.Instance.GetInfo((userInfo) => +// { +// Debug.Log("자동 로그인 성공"); +// +// UpdateMainPanelUI(); +// // ScoreData.SetScore(userInfo.score); +// // OpenConfirmPanel(userInfo.nickname + "님 로그인 성공하였습니다.", () => { }); +// }, () => +// { +// Debug.Log("자동 로그인 실패"); +// // 로그인 화면 +// OpenSigninPanel(); +// }); +// } +// +// private void UpdateMainPanelUI() +// { +// MainPanelController mainPanel = FindObjectOfType(); +// if (mainPanel != null) +// { +// mainPanel.UpdateUserInfo(); +// } +// } +// +// public void OpenSigninPanel() +// { +// if (canvas != null) +// { +// var signinPanelObject = Instantiate(signinPanel, canvas.transform); +// } +// } +// +// public void OpenSignupPanel() +// { +// if (canvas != null) +// { +// var signupPanelObject = Instantiate(signupPanel, canvas.transform); +// } +// } +// +// public void OnClickConfirmButton() +// { +// _gameLogic.SetNewBoardValue(_gameLogic.currentTurn, _gameLogic.selectedRow,_gameLogic.selectedCol); +// +// } +// +// public void OnClickReplayNextButton() +// { +// Move nextMove = ReplayManager.Instance.GetNextMove(); +// if (nextMove != null) +// { +// if (nextMove.stoneType.Equals(Enums.StoneType.Black.ToString())) +// { +// _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerA, nextMove.columnIndex, nextMove.rowIndex); +// +// } +// else if (nextMove.stoneType.Equals(Enums.StoneType.White.ToString())) +// { +// _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerB, nextMove.columnIndex, nextMove.rowIndex); +// } +// ReplayManager.Instance.PushMove(nextMove); +// } +// } +// +// public void OnClickReplayUndoButton() +// { +// Move targetMove = ReplayManager.Instance.PopMove(); +// if (targetMove != null) +// { +// if (targetMove.stoneType.Equals(Enums.StoneType.Black.ToString())) +// { +// _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerA, targetMove.columnIndex, targetMove.rowIndex); +// +// } +// else if (targetMove.stoneType.Equals(Enums.StoneType.White.ToString())) +// { +// _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerB, targetMove.columnIndex, targetMove.rowIndex); +// } +// ReplayManager.Instance.PushUndoMove(targetMove); +// //TODO: 화면상에서 돌 치우기 +// } +// } +// private void ChangeToGameScene(Enums.GameType gameType) +// { +// _gameType = gameType; +// SceneManager.LoadScene("Game"); +// } +// +// protected override void OnSceneLoaded(Scene scene, LoadSceneMode mode) +// { +// if (scene.name == "Game") +// { +// _stoneController = GameObject.FindObjectOfType(); +// _stoneController.InitStones(); +// _gameLogic = new GameLogic(_stoneController, _gameType); +// } +// else if (scene.name == "Replay") +// { +// _stoneController = GameObject.FindObjectOfType(); +// _stoneController.InitStones(); +// _gameLogic = new GameLogic(_stoneController, Enums.GameType.Replay); +// } +// _canvas = GameObject.Find("Canvas").GetComponent(); +// } +// } \ No newline at end of file diff --git a/Assets/Script/Common/Constants.cs b/Assets/Script/Common/Constants.cs index e09e345..9cd5c76 100644 --- a/Assets/Script/Common/Constants.cs +++ b/Assets/Script/Common/Constants.cs @@ -3,4 +3,5 @@ public const string ServerURL = "http://localhost:3000"; public const string GameServerURL = "ws://localhost:3000"; public const int BoardSize = 15; + public const int ReplayMaxRecordSize = 10; } \ No newline at end of file diff --git a/Assets/Script/Replay/ReplayController.cs b/Assets/Script/Replay/ReplayController.cs index dcc32b6..59a1c04 100644 --- a/Assets/Script/Replay/ReplayController.cs +++ b/Assets/Script/Replay/ReplayController.cs @@ -16,12 +16,12 @@ public class ReplayController : MonoBehaviour public void OnclickFirstButton() { - + ReplayManager.Instance.ReplayFirst(); } public void OnclickUndoButton() { - Move targetMove = ReplayManager.Instance.PopMove(); + Move targetMove = ReplayManager.Instance.PopPlacedMove(); if (targetMove != null) { ReplayManager.Instance.ReplayUndo(targetMove); @@ -39,7 +39,7 @@ public class ReplayController : MonoBehaviour public void OnClickFinishButton() { - + ReplayManager.Instance.ReplayFinish(); } diff --git a/Assets/Script/Replay/ReplayManager.cs b/Assets/Script/Replay/ReplayManager.cs index a2c412c..b07cd9f 100644 --- a/Assets/Script/Replay/ReplayManager.cs +++ b/Assets/Script/Replay/ReplayManager.cs @@ -72,7 +72,7 @@ public class ReplayManager : Singleton _placedStoneStack.Push(storedMove); } - public Move PopMove() + public Move PopPlacedMove() { if (_placedStoneStack.Count == 0) return null; @@ -80,7 +80,7 @@ public class ReplayManager : Singleton return move; } - public void PushUndoMove(Move storedMove) + private void PushUndoMove(Move storedMove) { _undoStack.Push(storedMove); } @@ -167,13 +167,14 @@ public class ReplayManager : Singleton return records; } + // 최대 저장 개수만큼 기보데이터가 저장, 유지되도록 하는 함수 private void RecordCountChecker() { try { string path = Application.persistentDataPath; var files = Directory.GetFiles(path, "*.json"); - if (files.Length <= 10) + if (files.Length <= Constants.ReplayMaxRecordSize) return; File.Delete(files[0]); RecordCountChecker(); @@ -184,11 +185,52 @@ public class ReplayManager : Singleton } } + // 기보 데이터 하나를 선택해서 매니저에 저장(씬 이동 후 데이터 활용을 위해) public void SetReplayData(ReplayRecord replayRecord) { _selectedReplayRecord = replayRecord; } + #region ReplayController에서 호출할 함수들 + public void ReplayNext(Move nextMove) + { + // 보드에 돌을 설정하기 위해 gameLogic의 SetNewBoardValue호출 + if (nextMove.stoneType.Equals(Enums.StoneType.Black.ToString())) + { + _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerA, nextMove.columnIndex, nextMove.rowIndex); + + } + else if (nextMove.stoneType.Equals(Enums.StoneType.White.ToString())) + { + _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerB, nextMove.columnIndex, nextMove.rowIndex); + } + // 돌이 놓인 내역을 ReplayManager에도 반영 + ReplayManager.Instance.PushMove(nextMove); + } + + public void ReplayUndo(Move targetMove) + { + ReplayManager.Instance.PushUndoMove(targetMove); + _gameLogic.RemoveStone(targetMove.columnIndex, targetMove.rowIndex); + } + + public void ReplayFirst() + { + while (_placedStoneStack.Count > 0) + { + ReplayUndo(_placedStoneStack.Pop()); + } + } + + public void ReplayFinish() + { + while(_placedStoneStack.Count < _selectedReplayRecord.moves.Count) + { + ReplayNext(GetNextMove()); + } + } + #endregion + protected override void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (scene.name == "Replay") @@ -207,49 +249,4 @@ public class ReplayManager : Singleton // Main으로 강제 전환 ? } } - - public void ReplayNext(Move nextMove ) - { - // 보드에 돌을 설정하기 위해 gameLogic의 SetNewBoardValue호출 - if (nextMove.stoneType.Equals(Enums.StoneType.Black.ToString())) - { - _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerA, nextMove.columnIndex, nextMove.rowIndex); - - } - else if (nextMove.stoneType.Equals(Enums.StoneType.White.ToString())) - { - _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerB, nextMove.columnIndex, nextMove.rowIndex); - } - // 돌이 놓인 내역을 ReplayManager에도 반영 - ReplayManager.Instance.PushMove(nextMove); - } - - public void ReplayUndo(Move targetMove) - { - if (targetMove.stoneType.Equals(Enums.StoneType.Black.ToString())) - { - _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerA, targetMove.columnIndex, targetMove.rowIndex); - - } - else if (targetMove.stoneType.Equals(Enums.StoneType.White.ToString())) - { - _gameLogic.SetNewBoardValue(Enums.PlayerType.PlayerB, targetMove.columnIndex, targetMove.rowIndex); - } - ReplayManager.Instance.PushUndoMove(targetMove); - _gameLogic.RemoveStone(targetMove.columnIndex, targetMove.rowIndex); - } - - #region for tests - - public void OnClickSaveButton(string winnerPlayerType = "PlayerA") - { - if(winnerPlayerType == Enums.PlayerType.PlayerA.ToString()) - SaveReplayData(Enums.PlayerType.PlayerA); - else - SaveReplayData(Enums.PlayerType.PlayerB); - - } - - - #endregion }