[Feat] 기보씬 처음, 이전, 다음, 끝 버튼 기능 구현

This commit is contained in:
HaeinLEE 2025-03-19 21:21:57 +09:00
parent 580abf1d4a
commit cbf85de156
4 changed files with 199 additions and 201 deletions

View File

@ -1,150 +1,150 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
using System.Collections.Generic;
public class GameManagerTestLIN : Singleton<GameManagerTestLIN>
{
[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<UserManager>();
//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<MainPanelController>();
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>();
_stoneController.InitStones();
_gameLogic = new GameLogic(_stoneController, _gameType);
}
else if (scene.name == "Replay")
{
_stoneController = GameObject.FindObjectOfType<StoneController>();
_stoneController.InitStones();
_gameLogic = new GameLogic(_stoneController, Enums.GameType.Replay);
}
_canvas = GameObject.Find("Canvas").GetComponent<Canvas>();
}
}
// using UnityEngine;
// using UnityEngine.SceneManagement;
// using System.Collections;
// using System.Collections.Generic;
//
// public class GameManagerTestLIN : Singleton<GameManagerTestLIN>
// {
// [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<UserManager>();
//
// //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<MainPanelController>();
// 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>();
// _stoneController.InitStones();
// _gameLogic = new GameLogic(_stoneController, _gameType);
// }
// else if (scene.name == "Replay")
// {
// _stoneController = GameObject.FindObjectOfType<StoneController>();
// _stoneController.InitStones();
// _gameLogic = new GameLogic(_stoneController, Enums.GameType.Replay);
// }
// _canvas = GameObject.Find("Canvas").GetComponent<Canvas>();
// }
// }

View File

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

View File

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

View File

@ -72,7 +72,7 @@ public class ReplayManager : Singleton<ReplayManager>
_placedStoneStack.Push(storedMove);
}
public Move PopMove()
public Move PopPlacedMove()
{
if (_placedStoneStack.Count == 0)
return null;
@ -80,7 +80,7 @@ public class ReplayManager : Singleton<ReplayManager>
return move;
}
public void PushUndoMove(Move storedMove)
private void PushUndoMove(Move storedMove)
{
_undoStack.Push(storedMove);
}
@ -167,13 +167,14 @@ public class ReplayManager : Singleton<ReplayManager>
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<ReplayManager>
}
}
// 기보 데이터 하나를 선택해서 매니저에 저장(씬 이동 후 데이터 활용을 위해)
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<ReplayManager>
// 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
}