[Feat] 기보데이터 저장과 불러오기 구현

GameCopy 씬에서 플레이한 데이터를 저장했다가 데이터로 돌놓기 테스트 완료
This commit is contained in:
HaeinLEE 2025-03-17 14:01:43 +09:00
parent 1e7aaaef26
commit 4455ef085b
4 changed files with 65 additions and 5 deletions

View File

@ -26,13 +26,15 @@ public class GameManagerTestLIN : Singleton<GameManagerTestLIN>
GameObject userManagerObj = new GameObject("UserManager");
_userManager = userManagerObj.AddComponent<UserManager>();
//게임 씬에서 확인하기 위한 임시 코드
_gameType = Enums.GameType.SinglePlay;
//TODO: 게임 내에서 기보 타입 적용하기
_gameType = Enums.GameType.Replay;
}
}
private void Start()
{
//TODO: 기보 타입으로 들어왔을 때 데이터 로드 테스트 수정할것
ReplayManager.Instance.InitReplayBoard(ReplayManager.Instance.LoadReplayDatas()[9]);
//게임 씬에서 확인하기 위한 임시 코드
@ -89,6 +91,27 @@ public class GameManagerTestLIN : Singleton<GameManagerTestLIN>
}
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);
}
}
}
public void OnClickReplayUndoButton()
{
}
private void ChangeToGameScene(Enums.GameType gameType)
{
_gameType = gameType;

View File

@ -8,5 +8,5 @@ public class Enums
public enum StoneState{ None, Selected, Blocked, LastPositioned }
public enum GameType{ None, SinglePlay, MultiPlay }
public enum GameType{ None, SinglePlay, MultiPlay, Replay }
}

View File

@ -27,6 +27,9 @@ public class GameLogic : MonoBehaviour
currentTurn = Enums.PlayerType.PlayerA;
SetState(currentTurn);
//TODO: 기보 매니저에게 플레이어 닉네임 넘겨주기
ReplayManager.Instance.InitReplayData("PlayerA","nicknameB");
}
private void SetState(Enums.PlayerType player)
@ -60,6 +63,8 @@ public class GameLogic : MonoBehaviour
LastNSelectedSetting(row, col);
SetState(Enums.PlayerType.PlayerB);
ReplayManager.Instance.RecordStonePlaced(Enums.StoneType.Black, row, col); //기보 데이터 저장
}
if (playerType == Enums.PlayerType.PlayerB)
{
@ -69,6 +74,8 @@ public class GameLogic : MonoBehaviour
LastNSelectedSetting(row, col);
SetState(Enums.PlayerType.PlayerA);
ReplayManager.Instance.RecordStonePlaced(Enums.StoneType.White, row, col);
}
}
}

View File

@ -33,7 +33,36 @@ public class ReplayManager : Singleton<ReplayManager>
{
private ReplayRecord _recordingReplayData;
#region
private ReplayRecord _replayRecord;
private Stack<Move> _plavedStoneStack;
private Stack<Move> _undoStack;
private int _moveIndex;
#endregion
public void InitReplayBoard(ReplayRecord replayRecord)
{
_replayRecord = replayRecord;
_moveIndex = 0;
}
public Move GetNextMove()
{
if (_undoStack.Count > 0)
return _undoStack.Pop();
if(_moveIndex >= _replayRecord.moves.Count)
return null;
Move move = _replayRecord.moves[_moveIndex];
_moveIndex++;
return move;
}
#region
///<summary>
/// 게임 시작에 호출해서 기보 데이터 초기화
/// </summary>
@ -81,6 +110,7 @@ public class ReplayManager : Singleton<ReplayManager>
}
}
#endregion
//폴더내 기보 파일을 전부 읽어옵니다.
public List<ReplayRecord> LoadReplayDatas()