[Feat] 기보데이터 저장과 불러오기 구현
GameCopy 씬에서 플레이한 데이터를 저장했다가 데이터로 돌놓기 테스트 완료
This commit is contained in:
parent
1e7aaaef26
commit
4455ef085b
@ -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]);
|
||||
|
||||
|
||||
//게임 씬에서 확인하기 위한 임시 코드
|
||||
@ -88,7 +90,28 @@ public class GameManagerTestLIN : Singleton<GameManagerTestLIN>
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClickReplayUndoButton()
|
||||
{
|
||||
|
||||
}
|
||||
private void ChangeToGameScene(Enums.GameType gameType)
|
||||
{
|
||||
_gameType = gameType;
|
||||
|
@ -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 }
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,37 @@ public class Move
|
||||
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,7 +110,8 @@ public class ReplayManager : Singleton<ReplayManager>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
//폴더내 기보 파일을 전부 읽어옵니다.
|
||||
public List<ReplayRecord> LoadReplayDatas()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user