[Feat] 기보데이터 Next와 Undo 구현

화면상에서 돌 치우는 기능 구현 필효
This commit is contained in:
HaeinLEE 2025-03-17 14:30:30 +09:00
parent 4455ef085b
commit 63a3e12907
2 changed files with 44 additions and 6 deletions

View File

@ -105,12 +105,27 @@ public class GameManagerTestLIN : Singleton<GameManagerTestLIN>
{
_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)
{

View File

@ -33,21 +33,24 @@ public class ReplayManager : Singleton<ReplayManager>
{
private ReplayRecord _recordingReplayData;
#region
#region
private ReplayRecord _replayRecord;
private Stack<Move> _plavedStoneStack;
//DO, Undo를 위한 스택
private Stack<Move> _placedStoneStack;
private Stack<Move> _undoStack;
private int _moveIndex;
#endregion
public void InitReplayBoard(ReplayRecord replayRecord)
{
_replayRecord = replayRecord;
_moveIndex = 0;
_placedStoneStack = new Stack<Move>();
_undoStack = new Stack<Move>();
}
public Move GetNextMove()
{
@ -61,6 +64,26 @@ public class ReplayManager : Singleton<ReplayManager>
_moveIndex++;
return move;
}
public void PushMove(Move storedMove)
{
_placedStoneStack.Push(storedMove);
}
public Move PopMove()
{
if (_placedStoneStack.Count == 0)
return null;
Move move = _placedStoneStack.Pop();
return move;
}
public void PushUndoMove(Move storedMove)
{
_undoStack.Push(storedMove);
}
#endregion
#region
///<summary>