[Test] 리플레이매니저 게임로직 에러
This commit is contained in:
parent
4d43ec5706
commit
e0568fe3c9
File diff suppressed because it is too large
Load Diff
@ -46,12 +46,6 @@ public class GameManager : Singleton<GameManager>
|
||||
// 자동 로그인
|
||||
// TryAutoSignin();
|
||||
|
||||
//게임 씬에서 확인하기 위한 임시 코드
|
||||
_canvas = canvas.GetComponent<Canvas>();
|
||||
_stoneController = GameObject.FindObjectOfType<StoneController>();
|
||||
_stoneController.InitStones();
|
||||
var fioTimer = FindObjectOfType<FioTimer>();
|
||||
_gameLogic = new GameLogic(_stoneController, _gameType, fioTimer);
|
||||
}
|
||||
|
||||
private void TryAutoSignin()
|
||||
@ -142,15 +136,18 @@ public class GameManager : Singleton<GameManager>
|
||||
{
|
||||
if (scene.name == "Game")
|
||||
{
|
||||
if (_gameType == Enums.GameType.Replay)
|
||||
{
|
||||
//TODO: 리플레이를 위한 초기화
|
||||
}
|
||||
_stoneController = GameObject.FindObjectOfType<StoneController>();
|
||||
_stoneController.InitStones();
|
||||
var fioTimer = FindObjectOfType<FioTimer>();
|
||||
_gameLogic = new GameLogic(_stoneController, _gameType, fioTimer);
|
||||
}
|
||||
else if (scene.name == "Replay")
|
||||
{
|
||||
_stoneController = GameObject.FindObjectOfType<StoneController>();
|
||||
_stoneController.InitStones();
|
||||
_gameLogic = new GameLogic(_stoneController, Enums.GameType.Replay);
|
||||
}
|
||||
|
||||
_canvas = GameObject.Find("Canvas").GetComponent<Canvas>();
|
||||
}
|
||||
//임시 재시작 재대결
|
||||
@ -205,4 +202,64 @@ public class GameManager : Singleton<GameManager>
|
||||
settingsPanelObject.GetComponent<ReplayPanelController>().Show();
|
||||
}
|
||||
}
|
||||
|
||||
#region ReplayControll
|
||||
|
||||
public void ReplayNext(Move nextMove )
|
||||
{
|
||||
if (_gameLogic == null)
|
||||
{
|
||||
_gameLogic = new GameLogic(_stoneController, Enums.GameType.Replay);
|
||||
}
|
||||
|
||||
if (_stoneController == null)
|
||||
{
|
||||
_stoneController = GameObject.FindObjectOfType<StoneController>();
|
||||
_stoneController.InitStones();
|
||||
Debug.Log("스톤컨트롤러 재할당");
|
||||
}
|
||||
|
||||
// 보드에 돌을 설정하기 위해 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 (_gameLogic == null)
|
||||
{
|
||||
_gameLogic = new GameLogic(_stoneController, Enums.GameType.Replay);
|
||||
}
|
||||
|
||||
if (_stoneController == null)
|
||||
{
|
||||
_stoneController = GameObject.FindObjectOfType<StoneController>();
|
||||
_stoneController.InitStones();
|
||||
Debug.Log("스톤컨트롤러 재할당");
|
||||
}
|
||||
|
||||
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: 화면상에서 돌 치우기
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ReplayCell : MonoBehaviour
|
||||
@ -83,8 +84,10 @@ public class ReplayCell : MonoBehaviour
|
||||
//TODO: storedReplayRecord를 가지고 게임 씬으로 전환
|
||||
public void OnClickReplayButton()
|
||||
{
|
||||
Debug.Log($"Replay Start with {_opponentNickname}\nDate: {_storedReplayRecord.gameDate}\n" +
|
||||
$"Moves: {_storedReplayRecord.moves}");
|
||||
//TODO: 확인 패널 띄우고 밑의 내용 콜백 함수로 옮기기
|
||||
// GameManager.Instance.OpenConfirmPanel($"{_opponentNickname}님 과의 대결을 다시 보시겠습니까?", () => { });
|
||||
ReplayManager.Instance.SetReplayData(_storedReplayRecord);
|
||||
SceneManager.LoadScene("Replay");
|
||||
}
|
||||
|
||||
}
|
||||
|
46
Assets/Script/Replay/ReplayController.cs
Normal file
46
Assets/Script/Replay/ReplayController.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ReplayController : MonoBehaviour
|
||||
{
|
||||
void Awake()
|
||||
{
|
||||
//TODO: 리플레이매니저 데이터로 화면 초기화
|
||||
}
|
||||
|
||||
public void OnclickExitButton()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnclickFirstButton()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnclickUndoButton()
|
||||
{
|
||||
Move targetMove = ReplayManager.Instance.PopMove();
|
||||
if (targetMove != null)
|
||||
{
|
||||
GameManager.Instance.ReplayUndo(targetMove);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnclickNextButton()
|
||||
{
|
||||
Move nextMove = ReplayManager.Instance.GetNextMove();
|
||||
if (nextMove != null)
|
||||
{
|
||||
GameManager.Instance.ReplayNext(nextMove);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClickFinishButton()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
11
Assets/Script/Replay/ReplayController.cs.meta
Normal file
11
Assets/Script/Replay/ReplayController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bda9793c3fea2104199340f907378533
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -35,7 +35,7 @@ public class ReplayManager : Singleton<ReplayManager>
|
||||
|
||||
#region 기보 시작 후 데이터를 컨트롤하기
|
||||
|
||||
private ReplayRecord _replayRecord;
|
||||
private ReplayRecord _selectedReplayRecord;
|
||||
|
||||
//DO, Undo를 위한 스택
|
||||
private Stack<Move> _placedStoneStack;
|
||||
@ -45,7 +45,7 @@ public class ReplayManager : Singleton<ReplayManager>
|
||||
|
||||
public void InitReplayBoard(ReplayRecord replayRecord)
|
||||
{
|
||||
_replayRecord = replayRecord;
|
||||
_selectedReplayRecord = replayRecord;
|
||||
_moveIndex = 0;
|
||||
|
||||
_placedStoneStack = new Stack<Move>();
|
||||
@ -57,10 +57,10 @@ public class ReplayManager : Singleton<ReplayManager>
|
||||
if (_undoStack.Count > 0)
|
||||
return _undoStack.Pop();
|
||||
|
||||
if(_moveIndex >= _replayRecord.moves.Count)
|
||||
if(_moveIndex >= _selectedReplayRecord.moves.Count)
|
||||
return null;
|
||||
|
||||
Move move = _replayRecord.moves[_moveIndex];
|
||||
Move move = _selectedReplayRecord.moves[_moveIndex];
|
||||
_moveIndex++;
|
||||
return move;
|
||||
}
|
||||
@ -89,7 +89,7 @@ public class ReplayManager : Singleton<ReplayManager>
|
||||
///<summary>
|
||||
/// 게임 시작에 호출해서 기보 데이터 초기화
|
||||
/// </summary>
|
||||
public void InitReplayData(string playerANickname, string playerBNickname)
|
||||
public void InitReplayData(string playerANickname="", string playerBNickname="")
|
||||
{
|
||||
_recordingReplayData = new ReplayRecord();
|
||||
_recordingReplayData.playerA = playerANickname;
|
||||
@ -181,10 +181,24 @@ public class ReplayManager : Singleton<ReplayManager>
|
||||
Debug.LogError($"Replay Directory Error: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetReplayData(ReplayRecord replayRecord)
|
||||
{
|
||||
_selectedReplayRecord = replayRecord;
|
||||
}
|
||||
|
||||
protected override void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
if (scene.name == "Replay")
|
||||
{
|
||||
if (_selectedReplayRecord != null)
|
||||
{
|
||||
InitReplayBoard(_selectedReplayRecord);
|
||||
}
|
||||
|
||||
// TODO: 데이터 잘못 가져왔을 때 어떻게 처리할지 고민하기
|
||||
// Main으로 강제 전환 ?
|
||||
}
|
||||
}
|
||||
|
||||
#region for tests
|
||||
|
@ -11,4 +11,7 @@ EditorBuildSettings:
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/Game.unity
|
||||
guid: 90d8e06582d54504c8033aab27b15564
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/Replay.unity
|
||||
guid: 393dbf55b04641847ae9b882a54856af
|
||||
m_configObjects: {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user